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 book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
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)