这是rspec错误消息:
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是客户模型中的一列。
客户控制器的规范代码导致上述错误:
it "'show' should be successful" do
customer = Factory(:customer)
get 'show' , :id => customer.id
response.should be_success
end
客户控制器中的“show”是:
def show
@customer = Customer.find(params[:id])
end
有关错误的任何想法?感谢。
答案 0 :(得分:0)
错误(undefined method 'name' for nil:NilClass
)来自您的节目视图第43行。
# ./app/views/customers/show.html.erb:43:in
这是因为当something.name
为something
时,您正在呼叫nil
。