我目前在Rails Tutorial (beta) 的第 10.3.2 节中,遇到了 RSpec 的一些问题。
rspec spec/ runs
完美,但是如果我rspec spec/requests/micropost_pages_spec.rb
按照教程中的描述进行操作,我会收到以下错误:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: before { visit root_path }
ActionView::Template::Error:
undefined method `model_name' for NilClass:Class
# ./app/views/shared/_micropost_form.html.erb:1:in `_app_views_shared__micropost_form_html_erb__567210303736562711_70234980477780'
# ./app/views/static_pages/home.html.erb:8:in `_app_views_static_pages_home_html_erb___61006871036382679_70234970424160'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
在 Web 浏览器中手动执行测试似乎也能完美运行。
不确定我是否做错了什么,或者教程中是否存在“错误”。谁能给个提示?
更新 1:这是GitHub 上整个项目的链接。
更新2:我现在发现,当我重新启动rails server
时,我第一次点击页面时也会收到错误。但是当我第二次加载页面(重新加载)时,它可以完美运行。