I want to test that some instance is not receiving a specific method call. Trying to
RSpec.describe 'something' do
before { subject.stubs(foo: 'bar') }
it { is_expected.to_not receive(:foo) }
end
gives me
Failure/Error: it { is_expected.to_not receive(:foo) }
NoMethodError:
undefined method `receive' for #<RSpec::ExampleGroups::Something:0x0000000010391588>
and trying to
RSpec.describe 'something else' do
before { subject.stubs(foo: 42) }
it { subject.expects(:foo).never; subject.foo }
end
passes. What am I doing wrong?
I was directed to the current not-working solution by Rails rspec undefined method `receive_message' for #<RSpec::ExampleGroups:: and I am using
RSpec 3.7
- rspec-core 3.7.1
- rspec-expectations 3.7.0
- rspec-mocks 3.7.0
- rspec-support 3.7.1
Update 1: I am using webmock
instead of rspec-mocks
.
Update 2: I am using webmock
and mocha
.
Update 3: Thanks for all the explanations, @engineersmnky! Unfortunately, for my specific use case, I still need to stub the method. Why is this one still passing?
require 'rspec'
require 'mocha'
RSpec.configure do |config|
config.mock_with :mocha
end
RSpec.describe 'something' do
# passes
it 'can hide from foo' do
subject.stubs(:foo)
expects(:foo).never
subject.foo
end
end
The difference is that I tried to express that I expect the signal :foo
never to be sent.