spec/rubocop/cop/rspec/instance_spy_spec.rb in rubocop-rspec-1.32.0 vs spec/rubocop/cop/rspec/instance_spy_spec.rb in rubocop-rspec-1.33.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do subject(:cop) { described_class.new } context 'when used with `have_received`' do it 'adds an offense for an instance_double with single argument' do @@ -8,20 +10,34 @@ foo = instance_double(Foo).as_null_object ^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`. expect(foo).to have_received(:bar) end RUBY + + expect_correction(<<-RUBY) + it do + foo = instance_spy(Foo) + expect(foo).to have_received(:bar) + end + RUBY end it 'adds an offense for an instance_double with multiple arguments' do expect_offense(<<-RUBY) it do foo = instance_double(Foo, :name).as_null_object ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`. expect(foo).to have_received(:bar) end RUBY + + expect_correction(<<-RUBY) + it do + foo = instance_spy(Foo, :name) + expect(foo).to have_received(:bar) + end + RUBY end it 'ignores instance_double when it is not used with as_null_object' do expect_no_offenses(<<-RUBY) it do @@ -40,21 +56,6 @@ expect(bar).to have_received(:bar) end RUBY end end - - original = <<-RUBY - it do - foo = instance_double(Foo, :name).as_null_object - expect(foo).to have_received(:bar) - end - RUBY - corrected = <<-RUBY - it do - foo = instance_spy(Foo, :name) - expect(foo).to have_received(:bar) - end - RUBY - - include_examples 'autocorrect', original, corrected end