[rspec-users] mock_model not working in rspec2?

Kristian Mandrup kmandrup at gmail.com
Thu Jun 10 00:08:01 EDT 2010


undefined method `model_name' for Message:Class
---

# spec/views/messages/new.html.erb_spec.rb

class Message; end

  describe "messages/new.html.erb" do
    it "renders a form to create a message" do
      assign(:message, mock_model(Message).as_new_record)
      render


# app/views/messages/new.html.erb
  <%= form_for @message do |f| %>
    <%= f.submit "Save" %>
  <% end %>
---

1) messages/new.html.erb renders a form to create a message
    Failure/Error: Unable to find matching line from backtrace
    undefined method `model_name' for Message:Class
    # On line #1 of /users/kristianconsult/development/languages/ruby/
apps/web-apps/rails/rails-3/experimental/views_example/app/views/
messages/new.html.erb

    1: <%= form_for @message do |f| %>
    2:   <%= f.submit "Save" %>
    3: <% end %>


More information about the rspec-users mailing list