I use Rails 3.0.4 and RSpec 2.5. In my controllers I use named scopes heavily, for example
@collection = GuestbookEntry.nonreplies.bydate.inclusive.paginate( :page => params[:page], :conditions => { ... })
In my tests, I want to be able to mock the result of such a query, not the wording. I do not think it makes sense to do something like
GuestbookEntry.stub_chain(:nonreplies, :bydate, ...).and_return(...)
because this test will fail the moment I decide to reorder the named scopes.
With Rails 2.3 and RSpec 1.x, this worked fine: I could write
GuestbookEntry.should_receive(:find).with(:all, :conditions => { ... })
and the above call would be caught and correctly handled. However, with Rails 3, for some reason this does not work any more.
Why? How do I set expectations or stubs on the result of nested scopes? Since everything in Rails 3's ActiveModel is a named scope (thanks to ARel), this must be possible somehow, or tests would indeed be very brittle.
Thanks!
Update: See also issue report on GitHub.