ruby on rails教程 - rails 3.0第11章rspec在代码列表11.27后失败

mpe*_*ner 2 ruby-on-rails-3

我完成了这本书.我在每一步后运行"rspec spec /".

第11章未能在列表11.27中添加app/views/pages/home.html.erb在列表11.30之后失败.将微博实例变量添加到主动作.应用程序/控制器/ pages_controller.rb

一切都应该是有效的.事实并非如此.我刚刚第一次进入轨道.既然这是剪切和粘贴代码,我没想到错误.

我将非常感谢任何帮助调试这个.如果我剪切和粘贴错误,或者如果Michel的代码示例没有经过全面测试,请将其删除.

这是rspec输出:

MPECHNER-MBP:sample_app michael.pechner $ rspec spec/..FF ................................... .................................................. ........ FF ....

失败:

1)MicropostsController POST'创建'失败不应该创建微博失败/错误:post:create,:micropost => @attr ActionView :: Template ::错误:当你没想到它时你有一个零对象!您可能期望ActiveRecord :: Base的实例._app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680' # ./app/views/shared/_micropost_form.html.erb:2:in在_app_views_shared__micropost_form_html_erb_ 732794408121469484_2179844600__1418926388395345268'#./ app/ _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268' # ./app/views/pages/home.html.erb:6:inviews/shared/ _micropost_form.html.erb:1: in_app_views_pages_home_html_erb中评估nil.errors#./ app/views/shared/_error_messages.html.erb:1: in 块时发生错误_1781066003698849377_2179862020__1594538359887050056'#./ app/console/microposts_controller.rb create' # ./spec/controllers/microposts_controller_spec.rb:34:in:10:在'./spec/controllers/microposts_controller_spec.rb:33:in`block(4个级别)中的块(5个级别)中

2)MicropostsController POST'创建'失败应该渲染主页失败/错误:post:create,:micropost => @attr ActionView :: Template ::错误:当你没想到它时你有一个nil对象!您可能期望ActiveRecord :: Base的实例._app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680' # ./app/views/shared/_micropost_form.html.erb:2:in在_app_views_shared__micropost_form_html_erb_ 732794408121469484_2179844600__1418926388395345268'#./ app/ _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268' # ./app/views/pages/home.html.erb:6:inviews/shared/ _micropost_form.html.erb:1: in_app_views_pages_home_html_erb中评估nil.errors#./ app/views/shared/_error_messages.html.erb:1: in 块时发生错误_1781066003698849377_2179862020__1594538359887050056'#./ app/controllers/microposts_controller.rb:10:in create' # ./spec/controllers/microposts_controller_spec.rb:39:inblock(4 levels)in'

3)登录时的LayoutLinks应该有一个注销链接失败/错误:访问root_path ActionView :: Template ::错误:当你没想到它时你有一个nil对象!您可能期望ActiveRecord :: Base的实例._app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680' # ./app/views/shared/_micropost_form.html.erb:2:in在_app_views_shared__micropost_form_html_erb_ 732794408121469484_2179844600__1418926388395345268'#./ app/ _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268' # ./app/views/pages/home.html.erb:6:inviews/shared/ _micropost_form.html.erb:1: in_app_views_pages_home_html_erb中评估nil.errors#./ app/views/shared/_error_messages.html.erb:1: in 块时发生错误_1781066003698849377_2179862020__1594538359887050056'#:10:在synchronize' # ./spec/requests/layout_links_spec.rb:51:in块(3级)中'

4)登录时的LayoutLinks应该有一个配置文件链接失败/错误:访问root_path ActionView :: Template ::错误:当你没想到它时你有一个零对象!您可能期望ActiveRecord :: Base的实例._app_views_shared__error_messages_html_erb___2864847557408089106_2179824440__3563936241835894680' # ./app/views/shared/_micropost_form.html.erb:2:in在_app_views_shared__micropost_form_html_erb_ 732794408121469484_2179844600__1418926388395345268'#./ app/ _app_views_shared__micropost_form_html_erb___732794408121469484_2179844600__1418926388395345268' # ./app/views/pages/home.html.erb:6:inviews/shared/ _micropost_form.html.erb:1: in_app_views_pages_home_html_erb中评估nil.errors#./ app/views/shared/_error_messages.html.erb:1: in 块时发生错误_1781066003698849377_2179862020__1594538359887050056'#:10:在synchronize' # ./spec/requests/layout_links_spec.rb:57:in块(3级)中'

完成2.04秒103例,4次失败MPECHNER-MBP:sample_app michael.pechner $

mpe*_*ner 8

我搜索了git hub以寻找其他已经完成此任务的人.我发现它在https://github.com/mfmcgran的帖子中 "app/views/shared/_error_messages.html.erb"似乎是错的,我把第一行的代码显示为"if @ users.errors.任何?" 广告它需要"如果object.errors.any?" 第11章没有提到这需要改变.但是在这次改变之后,所有103次rpsec测试都通过了.