Ruby on Rails Wednesday, June 29, 2011

On Jun 29, 1:46 pm, David Zhang <dzhan...@gmail.com> wrote:
> ...That's odd.  I just read The RSpec Book, and it explains how double isn't
> sufficient when you're testing something related to form_for.  The book, in
> its example, says to use mock_model("Message").as_new_record...
> and anyway in my case neither method is working.  If I use mock_model, I
> get
>
> Failure/Error: assign(:user_session,
> mock_model("UserSession").as_new_record)
>      ArgumentError:
>        The mock_model method can only accept as its first argument:
>          * A String representing a Class that does not exist
>          * A String representing a Class that extends ActiveModel::Naming
>          * A Class that extends ActiveModel::Naming
>
>        It received UserSession
>
> ...and if I use double, I get the error the book says I'd get: "undefined
> method `model_name' for RSpec::Mocks::Mock:Class"
>
> :/ so I wonder what the best way to test form_for is now with rspec... btw
> I'm using Capybara.

Didn't realize you needed it for form_for. You'll need to either use
the real object, or stub out all the necessary methods yourself (or
submit a patch to Authlogic to get it to conform to ActiveModel's
API).

Cheers,
David

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment