[rspec-users] Weird behavior with should_not_receive

David Hofer david.hofer at gmail.com
Tue Nov 1 13:59:14 EDT 2011


I recently saw a test passing when it should have failed, because the
person who wrote it used should_not_receive instead of
should_receive.  Here is a simple example illustrating the behavior:

class MyTest
  def foo
    puts "hey"
  end

  def bar
    foo
  end
end

describe MyTest do
  it "passes but should fail" do
    subject.should_not_receive(:foo).once
    subject.bar
  end
end

If I remove the ".once" the test fails, as I would expect.

Is this intended behavior?  It seems really weird to me.

I am seeing this with rspec 1.3.2 and rspec-rails 1.3.4.

Thanks,
David


More information about the rspec-users mailing list