spec/rubocop/cop/rspec/message_spies_spec.rb in rubocop-rspec-1.9.1 vs spec/rubocop/cop/rspec/message_spies_spec.rb in rubocop-rspec-1.10.0

- old
+ new

@@ -6,17 +6,53 @@ context 'when EnforcedStyle is have_received' do let(:cop_config) do { 'EnforcedStyle' => 'have_received' } end - it 'flags expect(...).to receive' do + it 'flags expect(send).to receive' do expect_violation(<<-RUBY) expect(foo).to receive(:bar) ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`. RUBY end + it 'flags expect(lvar).to receive' do + expect_violation(<<-RUBY) + foo = baz + expect(foo).to receive(:bar) + ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`. + RUBY + end + + it 'flags expect(ivar).to receive' do + expect_violation(<<-RUBY) + expect(@foo).to receive(:bar) + ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `@foo` as a spy using `allow` or `instance_spy`. + RUBY + end + + it 'flags expect(const).to receive' do + expect_violation(<<-RUBY) + expect(Foo).to receive(:bar) + ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `Foo` as a spy using `allow` or `instance_spy`. + RUBY + end + + it 'flags expect(...).not_to receive' do + expect_violation(<<-RUBY) + expect(foo).not_to receive(:bar) + ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`. + RUBY + end + + it 'flags expect(...).to_not receive' do + expect_violation(<<-RUBY) + expect(foo).to_not receive(:bar) + ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`. + RUBY + end + it 'flags expect(...).to receive with' do expect_violation(<<-RUBY) expect(foo).to receive(:bar).with(:baz) ^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`. RUBY @@ -50,13 +86,49 @@ context 'when EnforcedStyle is receive' do let(:cop_config) do { 'EnforcedStyle' => 'receive' } end - it 'flags expect(...).to have_received' do + it 'flags expect(send).to have_received' do expect_violation(<<-RUBY) expect(foo).to have_received(:bar) ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. + RUBY + end + + it 'flags expect(lvar).to have_received' do + expect_violation(<<-RUBY) + foo = baz + expect(foo).to have_received(:bar) + ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. + RUBY + end + + it 'flags expect(ivar).to have_received' do + expect_violation(<<-RUBY) + expect(@foo).to have_received(:bar) + ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. + RUBY + end + + it 'flags expect(const).to have_received' do + expect_violation(<<-RUBY) + expect(Foo).to have_received(:bar) + ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. + RUBY + end + + it 'flags expect(...).not_to have_received' do + expect_violation(<<-RUBY) + expect(foo).not_to have_received(:bar) + ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. + RUBY + end + + it 'flags expect(...).to_not have_received' do + expect_violation(<<-RUBY) + expect(foo).to_not have_received(:bar) + ^^^^^^^^^^^^^ Prefer `receive` for setting message expectations. RUBY end it 'flags expect(...).to have_received with' do expect_violation(<<-RUBY)