rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

Cop idea: IdenticalSiblingSetup

Open pirj opened this issue 5 years ago • 1 comments

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.

pirj avatar Aug 10 '20 19:08 pirj

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

Darhazer avatar Nov 19 '20 13:11 Darhazer