[rspec-users] Should receive field_for failing

Steve vertebrate at gmail.com
Wed Nov 14 12:23:23 EST 2007

I have a spec that's not behaving as I'm thinking it should. Here's the


it's failing with:

ActionView::TemplateError in 'customers/new should receive fields_for'
Mock 'ActionView::Base' expected :form_for with ("address", #<Address id:
nil, address1: "123 Main St.", address2: "PO Box 9403", city: "Anytown",
state: "FL", zip_code: "12345">) but received it with (:customer,
#<Customer:0x..fdb9ec5fe @name="Customer_1000">, {:url=>"/customers"})

Since the specs don't seem to follow subsequent render calls, is there a
way to verify that addresses/_form.html.haml is being called properly? 

I recall a similar discussion some weeks back, and the desire was to spec
for the end output of the view, and not the individual parts. My
problem comes from the fact that fields_for will happily create fields
even if the passed in object doesn't have attrs for them.

I had 'fields_for :address', and it output the whole form, and even though
@address was nil my specs passed, because I just checked for the presence
of the various form fields. However, since the form was rendered as a
partial, the fields weren't populating with values on the postback,
because what I needed to have was 'fields_for "address", address'. 

Is there a way to check for this through the primary view, or should I
just spec the partial individually?


More information about the rspec-users mailing list