double objects only respond to messages you tell it to. Since none have been defined, when save is sent to it, it doesn't know how to respond and it fails with that message. If you want to respond to all messages by default use .as_null_object which will always return nil. Otherwise provide stub return values for those messages you care about.
Just an FYI, but when rspec-rails 3.0 was released, the controller specs were changed to no longer try to use stubs by default. The reasoning for this is that default controllers are very tightly coupled to the ActiveRecord::Base implementations. While you are subclassing this, the majority of the API (which has a large surface area) is not controller by you. There is definitely some debate about stubbing code you own vs code you don't own. The core team decided to go the route of not stubbing controllers due to this very tight coupling. We'd encourage you to explore a more domain specific API which you control if you wish to stub controllers. On Thu, Jul 31, 2014 at 12:20 PM, Joy Ganguly <[email protected]> wrote: > Hi Aaron! > > Thanks a lot for your reply. > > I have change the code accordingly as you have said but now i am getting > this error > > Failure/Error: post :create, reader: params > Double Reader(id: integer, created_at: datetime, updated_at: datetime, > email: string) received unexpected message :save > with (no args) > > The code and error is updated at > https://gist.github.com/himadriganguly/e1547a512ff54084932d > > Thank you and take care. > > > On Monday, 28 July 2014 19:46:43 UTC+5:30, Joy Ganguly wrote: >> >> Running Rspec giving error >> >> undefined method `save' for #<RSpec::Mocks::AllowanceTarget:0x9bfadd4> >> >> and here is my code and error details >> https://gist.github.com/himadriganguly/e1547a512ff54084932d >> >> Thanks to all in advance. >> >> -- > You received this message because you are subscribed to the Google Groups > "rspec" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/e95c67c9-7582-4211-a154-d8f89e77b72f%40googlegroups.com > <https://groups.google.com/d/msgid/rspec/e95c67c9-7582-4211-a154-d8f89e77b72f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/CAKCESdgyK-fwwuzESi6TdGq5xJTzpWe%3DJ%2BjEaRiNLeqCf29iPA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
