In rspec we can disable verify_partial_doubles for one test

My project has this value set in the rspec_helper.rb file

mocks.verify_partial_doubles = true 

I have a test that gets labeled

 TaskPublisher does not implement #publish 

The problem is that this method does not exist on the object until it is created. This is a module import based on the type of task to be published. (metaprogramming)

So I'm wondering if there is a way to disable verify_partial_doubles for a particular test, but not affect the other tests that matter.

Side question: Is this flag set to true for BDD? It seems to me that he flies in the face of Mocking, as he defined ( https://stackoverflow.com/a/3/9/ ).

+8
ruby-on-rails mocking rspec
source share
2 answers

[Is there] a way to disable [verify_partial_doubles] for a particular test.?

RSpec> = 3.6

Use without_partial_double_verification

 it 'example' do without_partial_double_verification do # ... end end 

http://rspec.info/blog/2017/05/rspec-3-6-has-been-released/

RSpec <3.6

Yes, with user-defined metadata and a global β€œaround the hook” :

 # In your spec .. describe "foo", verify_stubs: false do # ... end # In spec_helper.rb RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end config.around(:each, verify_stubs: false) do |ex| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = false ex.run mocks.verify_partial_doubles = true end end end 

I believe that for this technique credit refers to Nikolai Rutherford , from his post in rspec-rails issue # 1076 .

+7
source share

Recently, we encountered a similar problem, and as a result, the following turned out:

 config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true config.around(:example, :without_verify_partial_doubles) do |example| mocks.verify_partial_doubles = false example.call mocks.verify_partial_doubles = true end end 

Very similar to Jared Beck, but avoiding the second call to mock_with .

0
source share

All Articles