Commit 0fee9447 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Inline shared examples for BeSuccessMatcher

Former shared examples were used only once.
Inlining them makes tests more clear.
parent 17385f4d
...@@ -14,62 +14,53 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do ...@@ -14,62 +14,53 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
shared_examples 'an offensive be_success call' do |content| shared_examples 'cop' do |good:, bad:|
it "registers an offense for `#{content}`" do context "using #{bad} call" do
inspect_source(content, source_file) it "registers an offense for `#{bad}`" do
inspect_source(bad, source_file)
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq([content])
end
end
shared_examples 'an autocorrected be_success call' do |content, autocorrected_content| expect(cop.offenses.size).to eq(1)
it "registers an offense for `#{content}` and autocorrects it to `#{autocorrected_content}`" do expect(cop.offenses.map(&:line)).to eq([1])
autocorrected = autocorrect_source(content, source_file) expect(cop.highlights).to eq([bad])
end
expect(autocorrected).to eql(autocorrected_content) it "registers an offense for `#{bad}` and autocorrects it to `#{good}`" do
end autocorrected = autocorrect_source(bad, source_file)
end
shared_examples 'cop' do |good:, bad:| expect(autocorrected).to eql(good)
context "using #{bad} call" do end
it_behaves_like 'an offensive be_success call', bad
it_behaves_like 'an autocorrected be_success call', bad, good
end end
context "using #{good} call" do context "using #{good} call" do
it 'does not register an offense' do it 'does not register an offense' do
inspect_source(good) inspect_source(good)
expect(cop.offenses.size).to eq(0) expect(cop.offenses).to be_empty
end end
end end
end end
describe 'using different code examples' do it_behaves_like 'cop',
it_behaves_like 'cop', bad: 'expect(response).to be_success',
bad: 'expect(response).to be_success', good: 'expect(response).to be_successful'
good: 'expect(response).to be_successful'
it_behaves_like 'cop', it_behaves_like 'cop',
bad: 'expect(response).to_not be_success', bad: 'expect(response).to_not be_success',
good: 'expect(response).to_not be_successful' good: 'expect(response).to_not be_successful'
it_behaves_like 'cop', it_behaves_like 'cop',
bad: 'expect(response).not_to be_success', bad: 'expect(response).not_to be_success',
good: 'expect(response).not_to be_successful' good: 'expect(response).not_to be_successful'
it_behaves_like 'cop', it_behaves_like 'cop',
bad: 'is_expected.to be_success', bad: 'is_expected.to be_success',
good: 'is_expected.to be_successful' good: 'is_expected.to be_successful'
it_behaves_like 'cop', it_behaves_like 'cop',
bad: 'is_expected.to_not be_success', bad: 'is_expected.to_not be_success',
good: 'is_expected.to_not be_successful' good: 'is_expected.to_not be_successful'
it_behaves_like 'cop', it_behaves_like 'cop',
bad: 'is_expected.not_to be_success', bad: 'is_expected.not_to be_success',
good: 'is_expected.not_to be_successful' good: 'is_expected.not_to be_successful'
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