New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutex cannot be mocked since 3.9.0 (Stack level too deep) #1574
Comments
A wild guess. What if you remove this line? |
The result is the same with or without the expectation. I believe this condition arises from the setup in the |
This is different to the original bug and weirder. That was about the ability to stub mutex at all.
The spec runs [or at least the version I set up in |
@JonRowe Thanks, yes, that actually removes the issue, but the thing is that would also keep me from testing what I want. The code I added was the minimum required to trigger the issue, however I'm interested in also testing what happens inside the It is not even possible to test that Even if I remove the
# frozen_string_literal: true
require_relative '../writer'
RSpec.describe Writer do
subject(:writer) { described_class.new }
let(:mocked_mutex) do
instance_double(
Mutex
)
end
before do
allow(Mutex).to receive(:new).and_return(mocked_mutex)
end
describe '#initialize' do
it 'creates a new Mutex' do
expect(Mutex).to receive(:new)
writer
end
end
describe '#write' do
it 'uses the Mutex to synchronize the writing' do
expect(mocked_mutex).to receive(:synchronize)
writer.write("hello world!")
end
end
end Now the test for And note that, just setting the expectation triggers the error, even if I remove the call to the actual method: |
Apologies, I did not mean to imply you should remove the line, my intent was to highlight that it was the |
We seem to be using |
I don't think thats the issue, we stash |
Mutex cannot be mocked since
Since
rspec 3.9.0
mocks of theMutex
class result in aSystemStackError
: stack level too deep. Error. I unearthed these two issues:And I thought this had already been fixed and it was something related to my setup or the combination of gems in my project but actually the issue is still there. Reproducible with Ruby 2.x and 3.x
Your environment
3.2.2
and2.7.7
3.9.0
all the way up to3.13.0
the issue is visible in all of them.Steps to reproduce
I created this simple project to show the issue:
writer.rb
:spec/writer_spec.rb
:Expected behavior
I would expect my test to pass (like it does with RSpec
3.8.0
)Actual behavior
I'm getting the mentioned
SystemStackError: stack level too deep
with such a backtrace:The text was updated successfully, but these errors were encountered: