-
-
Notifications
You must be signed in to change notification settings - Fork 358
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 |
I'm not sure I correctly understand how the 'stashing' is intended to operate - is this the code that should be doing that? If so, at this point, Updating this line to
Passes the spec, and appears to perhaps reflect the intent - the lines were introduced here, and it doesn't look like it intended anything tricky. Here's my stab, though I think that the spec might not be in the right place: #1575 |
|
Fix released in 3.13.1 |
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: