0
我目前在Rails教程(測試版)的section 10.3.2中,並遇到了RSpec的一些問題。Rails教程 - 奇怪的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:這裏給whole project on GitHub的鏈接。
更新2:我現在發現,當我重新啓動rails server
我得到的錯誤,也當我打的頁面的第一次。但是當我第二次加載頁面(重新加載)時,它完美地工作。
您可以請[gist](https://gist.github.com/)您的spec_helper,受影響的規範,控制器和視圖。偉大的將推動你的完整應用程序在github上;) – Mailo 2012-04-09 12:00:23
這裏是:https://github.com/znq/sample_app/tree/396d503d52b437790859917ce710c1aa59d3a426 – znq 2012-04-09 13:00:45
你可以嘗試更改'<%= render'shared/micropost_form'%>在home.html.erb中添加'<%= render:partial =>「shared/micropost_form」,:locals => {:micropost => @micropost}%>'然後在_micropost_form.html中使用'form_for(micropost)' .erb? – DanS 2012-04-09 13:38:29