[rspec-devel] Fix for should == mock_model with ActiveRecord

David Chelimsky dchelimsky at gmail.com
Sat Sep 15 17:44:25 EDT 2007


This was actually the solution to a known bug int the tracker
(http://rubyforge.org/tracker/index.php?func=detail&aid=13370&group_id=797&atid=3149).
I went ahead and applied it and credited you (Mike) w/ the patch, but
please do put patches in the tracker rather than hear - as Aslak said,
reduces the likelihood of stuff getting lost.

Thanks,
David

On 9/15/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> Thanks for the patch,
>
> Please put this in the tracker on Rubyforge so it stays on our radar.
> It's guaranteed to be forgotten here on the list.
>
> Aslak
>
> On 9/15/07, Mike Mangino <mmangino at elevatedrails.com> wrote:
> > I've attached a fix for the problems using specs like
> >
> > it "should belong to a user" do
> >    @comment.user.should == @user
> > end
> >
> > where @user is a mock_model.
> >
> >
> > To summarize the issue,
> >
> > rspec mocks use a proxy (__mock_proxy) to delegate methods to. When
> > on the LHS, == is delegated to the proxy. On the RHS, however, we are
> > comparing the mock itself to the proxy. There are a couple of
> > potential fixes.
> >
> > We could actually check to see if the RHS is a mock, and if so,
> > compare our proxy to its proxy. Alternatively, we could take the
> > naive solution and just reverse the comparison.
> >
> > I've attached the patch. I'm open to other suggestions, but I would
> > really like to see this fixed in some form.
> >
> > Mike
> >
> >
> >
> > --
> > Mike Mangino
> > http://www.elevatedrails.com
> >
> >
> >
> >
> > _______________________________________________
> > rspec-devel mailing list
> > rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
> >
> >
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list