【发布时间】:2011-06-18 09:31:13
【问题描述】:
我已经浏览了这本书。我在每一步之后运行“rspec spec/”。
第 11 章未能在 11.27 中添加 app/views/pages/home.html.erb 清单 11.30 之后。将 micropost 实例变量添加到 home 操作。 app/controllers/pages_controller.rb
一切都应该正常工作。它不是。我只是第一次深入研究轨道。由于这是剪切和粘贴代码,我没想到会出错。
我将不胜感激在调试此问题方面的任何帮助。如果我剪切和粘贴错误,或者 Michel 的代码示例没有经过全面测试,请务必解决。
这是 rspec 输出:
MPECHNER-MBP:sample_app michael.pechner$ rspec spec/ ..FF.................................................. .................................. FF... .
失败:
1) MicropostsController POST 'create' 失败不应创建微博
失败/错误:post :create, :micropost => @attr
动作视图::模板::错误:
当你没想到时,你有一个 nil 对象!
您可能期望 ActiveRecord::Base 的实例。
评估 nil.errors 时发生错误
# ./app/views/shared/_error_messages.html.erb:1:in _app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680'
# ./app/views/shared/_micropost_form.html.erb:2:inblock in _app_views_shared__micropost_form_html_erb_732794408121469484_2179844600__1418926388395345268'
# ./app/views/shared/_micropost_form.html.erb:1:in _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268'
# ./app/views/pages/home.html.erb:6:in_app_views_pages_home_html_erb_1781066003698849377_2179862020__1594538359887050056'
# ./app/controllers/microposts_controller.rb:10:in create'
# ./spec/controllers/microposts_controller_spec.rb:34:inblock (5 个级别) in '
# ./spec/controllers/microposts_controller_spec.rb:33:in `block (4 levels) in '
2) MicropostsController POST 'create' 失败应该呈现主页
失败/错误:post :create, :micropost => @attr
动作视图::模板::错误:
当你没想到时,你有一个 nil 对象!
您可能期望 ActiveRecord::Base 的实例。
评估 nil.errors 时发生错误
# ./app/views/shared/_error_messages.html.erb:1:in _app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680'
# ./app/views/shared/_micropost_form.html.erb:2:inblock in _app_views_shared__micropost_form_html_erb_732794408121469484_2179844600__1418926388395345268'
# ./app/views/shared/_micropost_form.html.erb:1:in _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268'
# ./app/views/pages/home.html.erb:6:in_app_views_pages_home_html_erb_1781066003698849377_2179862020__1594538359887050056'
# ./app/controllers/microposts_controller.rb:10:in create'
# ./spec/controllers/microposts_controller_spec.rb:39:inblock (4 个级别) in '
3) 登录时的 LayoutLinks 应该有一个退出链接
失败/错误:访问 root_path
动作视图::模板::错误:
当你没想到时,你有一个 nil 对象!
您可能期望 ActiveRecord::Base 的实例。
评估 nil.errors 时发生错误
# ./app/views/shared/_error_messages.html.erb:1:in _app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680'
# ./app/views/shared/_micropost_form.html.erb:2:inblock in _app_views_shared__micropost_form_html_erb_732794408121469484_2179844600__1418926388395345268'
# ./app/views/shared/_micropost_form.html.erb:1:in _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268'
# ./app/views/pages/home.html.erb:6:in_app_views_pages_home_html_erb_1781066003698849377_2179862020__1594538359887050056'
# :10:in synchronize'
# ./spec/requests/layout_links_spec.rb:51:inblock (3 个级别) in '
4) 登录后的 LayoutLinks 应该有个人资料链接
失败/错误:访问 root_path
动作视图::模板::错误:
当你没想到时,你有一个 nil 对象!
您可能期望 ActiveRecord::Base 的实例。
评估 nil.errors 时发生错误
# ./app/views/shared/_error_messages.html.erb:1:in _app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680'
# ./app/views/shared/_micropost_form.html.erb:2:inblock in _app_views_shared__micropost_form_html_erb_732794408121469484_2179844600__1418926388395345268'
# ./app/views/shared/_micropost_form.html.erb:1:in _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268'
# ./app/views/pages/home.html.erb:6:in_app_views_pages_home_html_erb_1781066003698849377_2179862020__1594538359887050056'
# :10:in synchronize'
# ./spec/requests/layout_links_spec.rb:57:inblock (3 个级别) in '
在 2.04 秒内完成 103 个例子,4 次失败 MPECHNER-MBP:sample_app michael.pechner$
【问题讨论】:
标签: ruby-on-rails-3