Ruby on rails 3 RubyonRails教程-Rails3.0第11章代码清单11.27后rspec失败

Ruby on rails 3 RubyonRails教程-Rails3.0第11章代码清单11.27后rspec失败,ruby-on-rails-3,Ruby On Rails 3,我把这本书看完了。我在每个步骤后运行“rspec spec/” 第11章无法启动11.27中的列表添加app/views/pages/home.html.erb 在清单11.30之后。将micropost实例变量添加到home操作。 app/controllers/pages\u controller.rb 一切都应该正常运转。事实并非如此。我只是第一次钻研铁轨。因为这是剪切粘贴代码,所以我没想到会出现错误 我将非常感谢任何帮助我调试这个。如果我剪切和粘贴错误,或者如果Michel的代码示例没有

我把这本书看完了。我在每个步骤后运行“rspec spec/”

第11章无法启动11.27中的列表添加app/views/pages/home.html.erb 在清单11.30之后。将micropost实例变量添加到home操作。 app/controllers/pages\u controller.rb

一切都应该正常运转。事实并非如此。我只是第一次钻研铁轨。因为这是剪切粘贴代码,所以我没想到会出现错误

我将非常感谢任何帮助我调试这个。如果我剪切和粘贴错误,或者如果Michel的代码示例没有经过充分测试,请检查

以下是rspec输出:

MPECHNER-MBP:示例应用程序michael.pechner$rspec规范/ ……FF…………FF

失败:

1) micropost控件“创建”失败不应创建micropost 失败/错误:post:create,:microspost=>@attr ActionView::模板::错误: 你有一个零的对象,当你没有想到它! 您可能希望有ActiveRecord::Base的实例。 计算nil.errors时出错 #./app/views/shared/\u error\u messages.html.erb:1:in
\u app\u views\u shared\u error\u messages\u html\u erb\u 2864847557408089106\u 217982440\u 3563936241835894680'
#./app/views/shared/_microspost_form.html.erb:2:in
block in_app_views_shared_microst_form_html_erb7327940821469484_21798444600_1418926388395345268' #./app/views/shared/_microspost_form.html.erb:1:in
_app_views_shared_microst_form_html_erb__7327940812169484_21798444600_1418926388395345268'
#/app/views/pages/home.html.erb:6:in
\u app\u views\u pages\u home\u html\u erb
\u 1781066003698849377\u 21798620\u 1594538359887050056' #./app/controllers/microsposts\u controller.rb:10:in
create'
#./spec/controllers/microsposts\u controller\u spec.rb:34:in
block(5级)in' #./spec/controllers/microsposts\u controller\u spec.rb:33:in'block(4级)in'

2) MicropostsController发布“创建”失败应呈现主页 失败/错误:post:create,:microspost=>@attr ActionView::模板::错误: 你有一个零的对象,当你没有想到它! 您可能希望有ActiveRecord::Base的实例。 计算nil.errors时出错 #./app/views/shared/\u error\u messages.html.erb:1:in
\u app\u views\u shared\u error\u messages\u html\u erb\u 2864847557408089106\u 217982440\u 3563936241835894680'
#./app/views/shared/_microspost_form.html.erb:2:in
block in_app_views_shared_microst_form_html_erb7327940821469484_21798444600_1418926388395345268' #./app/views/shared/_microspost_form.html.erb:1:in
_app_views_shared_microst_form_html_erb__7327940812169484_21798444600_1418926388395345268'
#/app/views/pages/home.html.erb:6:in
\u app\u views\u pages\u home\u html\u erb
\u 1781066003698849377\u 21798620\u 1594538359887050056' #./app/controllers/microsposts\u controller.rb:10:in
create'
#./spec/controllers/microposts\u controller\u spec.rb:39:in
块(4级)in'

3) 登录时,LayoutLinks应具有注销链接 失败/错误:访问根目录路径 ActionView::模板::错误: 你有一个零的对象,当你没有想到它! 您可能希望有ActiveRecord::Base的实例。 计算nil.errors时出错 #./app/views/shared/\u error\u messages.html.erb:1:in
\u app\u views\u shared\u error\u messages\u html\u erb\u 2864847557408089106\u 217982440\u 3563936241835894680'
#./app/views/shared/_microspost_form.html.erb:2:in
block in_app_views_shared_microst_form_html_erb7327940821469484_21798444600_1418926388395345268' #./app/views/shared/_microspost_form.html.erb:1:in
_app_views_shared_microst_form_html_erb__7327940812169484_21798444600_1418926388395345268'
#/app/views/pages/home.html.erb:6:in
\u app\u views\u pages\u home\u html\u erb
\u 1781066003698849377\u 21798620\u 1594538359887050056' #:10:in
同步'
#./spec/requests/layout_links_spec.rb:51:in
块(3层)in'

4) 登录时,LayoutLinks应具有配置文件链接 失败/错误:访问根目录路径 ActionView::模板::错误: 你有一个零的对象,当你没有想到它! 您可能希望有ActiveRecord::Base的实例。 计算nil.errors时出错 #./app/views/shared/\u error\u messages.html.erb:1:in
\u app\u views\u shared\u error\u messages\u html\u erb\u 2864847557408089106\u 217982440\u 3563936241835894680'
#./app/views/shared/_microspost_form.html.erb:2:in
block in_app_views_shared_microst_form_html_erb7327940821469484_21798444600_1418926388395345268' #./app/views/shared/_microspost_form.html.erb:1:in
_app_views_shared_microst_form_html_erb__7327940812169484_21798444600_1418926388395345268'
#/app/views/pages/home.html.erb:6:in
\u app\u views\u pages\u home\u html\u erb
\u 1781066003698849377\u 21798620\u 1594538359887050056' #:10:in
同步'
#./spec/requests/layout_links_spec.rb:57:in
块(3层)in'

以2.04秒完成 103个示例,4个故障
MPECHNER-MBP:sample_app michael.pechner$

我在git hub上搜索了其他已经完成此任务的人。 我是在邮寄时发现的 “app/views/shared/_error_messages.html.erb”似乎是错误的,我在第一行显示的代码是“if@users.errors.any?”,它需要是“if object.errors.any?”
第11章没有提到这一点需要改变。但是在这一改变之后,所有103次每秒的测试都通过了。

本教程已经有点过时了(考虑到gem版本发布的速度)。我发现如果你只是升级一下就很方便了
gem 'capybara'
gem 'capybara/rspec'
bundle install
click_link 'About'
page.should have_content("About")
# in place of
# enter code here`response.should have_selector('title', :content => "Contact")
get '/about'
response.should have_selector('title', :content => "About")