[mocha-developer] Stubbing objects and calling to_json on them errors (circular reference)
jamesmead44 at gmail.com
Sun Oct 26 15:09:54 EDT 2008
2008/10/20 Bill Kocik <bkocik at gmail.com>
> My apologies if there's a user list I should be posting this to. I didn't
> find one.
No worries. This list serves as both user & developer list.
> Suppose you have a controller action like this:
> def do_something
> @something = Something.find(:first)
> render :json => @something.to_json
> A test might be this:
> context "when do_something is called" do
> setup do
> @something = Something.new()
> get :do_something
> should_respond_with :success
> Because I stubbed a method on my @something object (and this also happens
> with expects()), I get this:
> 1) Error:
> test: when do_something is called should respond with success.
> ActiveSupport::JSON::CircularReferenceError: object references itself
> If I print out the object @something, I see that it contains an @mocha
> attribute that references the containing object, which is the cause of
> to_json's heartburn and the error. But that @mocha attribute is not present
> if I never call stubs() or expects() on the object that's going to be
> converted to JSON, and I do not get the error in that case. Can anyone show
> me what I'm doing wrong, or is this actually a known issue?
> Bill Kocik
This sounds like a bug. I'm going to add a bug report to track this .
Thanks for letting us know about it.
More information about the mocha-developer