Here is the rspec error message:
5) CustomersController GET customer page 'show' should be successful
Failure/Error: get 'show' , :id => customer.id
ActionView::Template::Error:
undefined method `name' for nil:NilClass
# ./app/views/customers/show.html.erb:43:in `_app_views_customers_show_html_erb___16283441_33497004'
# ./spec/controllers/customers_controller_spec.rb:41:in `block (3 levels) in <top (required)>'
name is one column in customer model.
Error above caused by the spec code for customers controller:
it "'show' should be successful" do
customer = Factory(:customer)
get 'show' , :id => customer.id
response.should be_success
end
The ‘show’ in customer controllers is :
def show
@customer = Customer.find(params[:id])
end
Any thoughts about the error? Thanks.
The error (
undefined method 'name' for nil:NilClass) is coming from your show view, line 43.and it’s because you’re calling
something.namewhensomethingisnil.