Search code examples
rspecrspec-rails

Is any_instance broken in Rspec 3.2 with expect syntax?


did anyone run into this?

Works:

MyClass.any_instance.should_receive(:my_method)

Does not work:

expect(MyClass.any_instance).to receive(:my_method)

Am I screwing up syntax here or is it just not possible to do this in expect syntax? I'd really dig sticking with expect here, but didn't work it out yet.

Thanks!


Solution

  • RSpec introduced expect_any_instance_of as described in https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/working-with-legacy-code/any-instance in order to support this with "expect like" syntax. What you've shown is indeed not supported.