Read more

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

Henning Koch
October 26, 2015Software engineer at makandra GmbH

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.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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 .

Posted by Henning Koch to makandra dev (2015-10-26 13:43)