RSpec / RSpec Mocks / Docs / Spies
This page comes from RSpec Mocks 2.99.4. It is not part of the 3.12.4 docs. See the latest RSpec Mocks docs.
Spy on an unstubbed method
Using have_received on an unstubbed method will never pass, so rspec-mocks issues a helpful error message.
Scenario: fail to verify a stubbed method
- Given a file named "
failed_spy_spec.rb" with:rubydescribe "have_received" do it "raises a helpful error for unstubbed methods" do object = Object.new object.object_id object.should have_received(:object_id) end end - When I run `rspec failed_spy_spec.rb`
- Then the output should contain "
that method has not been stubbed"
Source: features/spies/spy_unstubbed_method.feature at v2.99.4, RSpec Mocks (MIT license).