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.
It looks like line 27 should be double(Reader) instead of allow(Reader).
allow returns a mock expectation, not the object to mock. Additionally, line 37 will overwrite the stub you created on line 36; meaning that it will return nil. Add the .and_return(reader) to line 37 and delete line 36.
Hope that helps.
--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3b2a5bb2-0ef5-4843-9589-0f6d995958d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Failure/Error: post :create, reader: paramsDouble Reader(id: integer, created_at: datetime, updated_at: datetime, email: string) received unexpected message :savewith (no args)
The code and error is updated at https://gist.github.com/himadriganguly/e1547a512ff54084932d
Thank you and take care.
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.
--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/e95c67c9-7582-4211-a154-d8f89e77b72f%40googlegroups.com.