Rails 3, RSpec 2.5: Using should_receive or stub_chain with named scopes
问题 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