rspec/rspec-mocks — Issue #96: stack level too deep if mocking joins_values attribute accessor (ActiveRecord::Relation)
Author: brueckenschlaeger23
Created: 2012-01-19 11:06:02+00:00
State: open

Too test scopes, I wanted to stub ActiveRecord::Relation joins_values attribute accessor (I was not sure whether it's just an instance variable, so I preferred stubbing):

ActiveRecord::Relation.any_instance.stub(:joins_values).and_return([])

Doing so, leads to a "stack level too deep" exception as soon as I call a scope using joins. Presumably caused by a loop in:

ruby-1.9.2-p290/gems/rspec-mocks-2.8.0/lib/rspec/mocks/any_instance/recorder.rb
where
self.class.__recorder.playback!(self, :#{method_name})
ends up calling
observe!
again.

The error was dificult too localize (- and still not totally sure about it) because first I stubbed "where_values" as well and the error occured in OTHER test cases than the test case where I defined the stub. - Presumably the error came during cleanup?

It seems like an bug to me. If not, this behavior (don't stub attr_accessors) should be specified.