After calling any_instance on a DataMapper validator in one example, the next example to contain a call to DataMapper::Model.valid? will cause a stack nested too deep error.
Not sure if the this is a RSpec or DataMapper issue.
I've included a reproducible case at https://gist.github.com/2496898.
Running rspec stack_error_spec.rb results in:
1) Post should still work after mocks have been removed
Failure/Error: Unable to find matching line from backtrace
stack level too deep
Finished in 0.03504 seconds
2 examples, 1 failure
rspec ./stack_error_spec.rb:32 # Post should still work after mocks have been removed
I have been able to reproduce the error on ruby-1.8.7, ruby-1.9.2 and jruby-1.6.7
I'm guessing this is related to #120 /cc @kaiwren
Probably. But it doesn't sound like the 'fork bomb' description given to #120. And the error only occurs after the stub should have been torn down.
@dchelimsky Noted, thanks /cc @deobald @srushti @preethiramdev
I have a similar issue with Sequel. Minimal case: https://gist.github.com/2869129
Experiencing this bug while trying to mock writing to a (plaintext) file.
Minimal example here: https://gist.github.com/3113509
Tested with current head (f36ad4d) and Ruby 1.9.3-p194.
Just to verify: When commenting out IO.any_instance, no error is thrown.
@torbjoernk I'm not sure why there's a stack overflow, but what you're trying to do won't work because nil is being yielded to File.open. You need to declare explicitly what should be returned by or yielded from File.open when you use should_receive. Try this instead of what's in your gist:
describe "message expectation on a file" do
it "works like this" do
filename = "test_file"
expected = "this should be written to test_file"
file = stub
file.should_receive( :puts ).with( expected )
File.should_receive( :open ).with( filename, "w" ).and_yield( file )
File.open( filename, "w" ) do |f|
@dchelimsky Thanks a lot. That worked. Though your code is a little "stuttering": file.should_receive.should_receive() ;) Now I'm going to educate myself about that and_yield ...
@torbjoernk fixed the stuttering - thanks!
I'm experiencing the same issue as @asdavey any spec that comes after the one where I have ObjectName.any_instance.stub is failing..
I feel like this is likely related to an instance being created in one spec that's sticking around in a different spec. That doesn't play nicely with any_instance.
Moving discussion to #167.