Commit 23da356d authored by Vitali Tatarintev's avatar Vitali Tatarintev

Refactor BeSuccessMatcher specs

parent e1b8b932
...@@ -10,10 +10,16 @@ require_relative '../../../../rubocop/cop/rspec/be_success_matcher' ...@@ -10,10 +10,16 @@ require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
describe RuboCop::Cop::RSpec::BeSuccessMatcher do describe RuboCop::Cop::RSpec::BeSuccessMatcher do
include CopHelper include CopHelper
OFFENSE_CALL_EXPECT_TO_BE_SUCCESS = %(expect(response).to be_success).freeze CODE_EXAMPLES = [
OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS = %(is_expected.to be_success).freeze {
CALL_EXPECT_TO_BE_SUCCESSFUL = %(expect(response).to be_successful).freeze bad: %(expect(response).to be_success).freeze,
CALL_IS_EXPECTED_TO_BE_SUCCESSFUL = %(is_expected.to be_successful).freeze good: %(expect(response).to be_successful).freeze
},
{
bad: %(is_expected.to be_success).freeze,
good: %(is_expected.to be_successful).freeze
}
]
let(:source_file) { 'spec/foo_spec.rb' } let(:source_file) { 'spec/foo_spec.rb' }
...@@ -42,47 +48,30 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do ...@@ -42,47 +48,30 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
allow(cop).to receive(:in_controller_spec?).and_return(true) allow(cop).to receive(:in_controller_spec?).and_return(true)
end end
context 'using expect(response).to be_success call' do CODE_EXAMPLES.each do |code_example|
it_behaves_like 'an offensive be_success call', OFFENSE_CALL_EXPECT_TO_BE_SUCCESS context "using #{code_example[:bad]} call" do
it_behaves_like 'an autocorrected be_success call', OFFENSE_CALL_EXPECT_TO_BE_SUCCESS, CALL_EXPECT_TO_BE_SUCCESSFUL it_behaves_like 'an offensive be_success call', code_example[:bad]
end it_behaves_like 'an autocorrected be_success call', code_example[:bad], code_example[:good]
context 'using is_expected.to be_success call' do
it_behaves_like 'an offensive be_success call', OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS
it_behaves_like 'an autocorrected be_success call', OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS, CALL_IS_EXPECTED_TO_BE_SUCCESSFUL
end
context 'using expect(response).to be_successful' do
it "does not register an offense" do
inspect_source(CALL_EXPECT_TO_BE_SUCCESSFUL)
expect(cop.offenses.size).to eq(0)
end end
end
context 'using is_expected.to be_successful' do context "using #{code_example[:good]} call" do
it 'does not register an offense' do it "does not register an offense" do
inspect_source(CALL_IS_EXPECTED_TO_BE_SUCCESSFUL) inspect_source(code_example[:good])
expect(cop.offenses.size).to eq(0) expect(cop.offenses.size).to eq(0)
end
end end
end end
end end
context 'outside of a controller spec file' do context 'outside of a controller spec file' do
context 'using expect(response).to be_success call' do CODE_EXAMPLES.each do |code_example|
it 'does not register an offense' do context "using #{code_example[:bad]} call" do
inspect_source(OFFENSE_CALL_EXPECT_TO_BE_SUCCESS) it 'does not register an offense' do
inspect_source(code_example[:bad])
expect(cop.offenses.size).to eq(0)
end
end
context 'using is_expected.to be_success call' do
it 'does not register an offense' do
inspect_source(OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS)
expect(cop.offenses.size).to eq(0) expect(cop.offenses.size).to eq(0)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment