Skip to content
This repository

Mocking not initialized in around(:each) blocks. #364

tylerhunt opened this Issue · 1 comment

2 participants

Tyler Hunt David Chelimsky
Tyler Hunt

The mocking framework appears to not be initialized properly before the example is run in an around block.

RSpec.configure do |config|
  config.mock_with :rspec

describe 'around mocking' do
  let!(:now) { }

  around(:each) do |example|

  specify { == now }

This results in the following failure:

Run filtered 


  1) around mocking 
     Failure/Error: Time.stub(:now).and_return(now)
       undefined method `stub' for Time:Class
     # ./bug.rb:9

Finished in 0.00039 seconds
1 example, 1 failure

Changing the around to a before works as expected, and after is called, the mocking methods are available inside the around block. It appears the source of the the bug is that RSpec::Core::Example#run_before_each is where the mocking framework is set up (@example_group_instance.setup_mocks_for_rspec), but around begins executing before this code is called.

David Chelimsky

Mocking is unsupported in around hooks. I'll leave that open until this fact gets documented.

The mocking framework is verified/reset after each example, so doing this in a before is just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.