rubocop-rspec
rubocop-rspec copied to clipboard
Cop idea: IdenticalSiblingSetup
RSpec.describe 'Foo' do
context 'when bar' do
let(:qux) { 111 }
let(:unique) { 'no one like me' }
before { setup(qux, unique) }
it { is_expected.to eq 222 }
end
context 'when bar' do
let(:qux) { 111 }
let(:unique) { 'I am different!!!' }
before { setup(qux, unique) }
it { is_expected.to eq 333 }
end
end
In the case above let(:qux) and before can be pulled up to the outer example group.
Perhaps this should have some minimum number of common setup?
What if the default value of :qux is already set at the top-level to 112, but in those two cases we want to have 111
I like the idea of the cop, but it should be scoped better. I suggest:
- Flag only if all siblings have the same value
- Or if there is more then MinDuplicatedElements between two siblings
- In any case, be mindful if a value is already present on an outer scope