Why is this view spec failing?

I can’t figure out why I am getting a failure. It renders out fine in
the browser.

New member

<%= error_messages_for :member %>

<% form_for(:member, :url => members_path) do |f| %>

Member Info

First Name: <%= f.text_field :first_name %>

Last Name: <%= f.text_field :last_name %>

<%= submit_tag "Create" %>

<% end %> <%= link_to 'Back', members_path %>

ActionView::TemplateError in ‘/members/new.rhtml should render new form’
Mock ‘Member_1002’ received unexpected message :first_name with (no
args)
On line #9 of app/views/members/new.rhtml

6:
7:   <fieldset>
8:     <legend>Member Info</legend>
9:     <p><label for="member[first_name]">First Name:</label>    <%=

f.text_field :first_name %>


10:

Last Name: <%=
f.text_field :last_name %>


11:
12:
#{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:52:in

__raise' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:16:inraise_unexpected_message_error’
#{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/proxy.rb:83:in
raise_unexpected_message_error' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/mock.rb:20:inmethod_missing’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:in
send' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:invalue_before_type_cast’


This is using the auto-created test

it “should render new form” do
render “/members/new.rhtml”

response.should have_tag("form[action=?][method=post]",

members_path) do
end
end

Thanks for the help

On Nov 6, 2007 12:56 PM, Chris O. [email protected] wrote:

<legend>Member Info</legend>

<%= link_to ‘Back’, members_path %>


ActionView::TemplateError in ‘/members/new.rhtml should render new form’
Mock ‘Member_1002’ received unexpected message :first_name with (no
args)

This error is telling you exactly why it’s failing. The mock name
“Member_1002” that I’m assuming gets created in the spec (please post
before(:each) in the future for clarity) is being sent :first_name by
the code invoked by t.text_field. Assuming (again) that it is called
@member:

@member.stub!(:first_name).and_return(“Chris”)

should solve the problem.

Cheers,
David

Thanks for the help David.