Configure RSpec to raise an error when stubbing a non-existing method

Updated . Posted . Visible to the public.

You can configure RSpec 3.3+ to raise an error when attempting to stub or mock a non-existing method. We strongly recommend to do this as non-verified stubs are a footgun.

You can enable this behavior by adding the following to your spec_helper.rb:

RSpec.configure do |config|
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end

This will also replace stub_existing from our rspec_candy Show archive.org snapshot .

Henning Koch
Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2015-10-26 12:43)