Mike Hartlの「Learn Rails by Example」チュートリアルで奇妙なrspecエラーが発生しました。 10.30リストページ419でrspecエラー:例でレールを学ぶ:期待していないときにオブジェクトがありません。
、:
it "should have an element for each user" do
get :index
@users[0..2].each do |user|
response.should have_selector("li", :content => user.name)
end
end
そして、私はRSpecの実行時に、私はこのエラーメッセージ:
障害受け取る::次のようにコードがある
1) UsersController GET 'index' for signed-in-users should have an element for each user
Failure/Error: @users[0..2].each do |user|
NoMethodError:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
# ./spec/controllers/users_controller_spec.rb:40
Finished in 2.58 seconds 75 examples, 1 failure
Failed examples:
rspec ./spec/controllers/users_controller_spec.rb:38 # UsersController GET 'index' for >signed-in-users should have an element for each user
を私はいくつかの研究を行い、このスレッドで同様の問題を発見しましたが、まだテストをパスすることができませんでした。
アイデア?
参考リンク:
Why are my RSpec tests failing, but my app is working?
Cookies do not persist in Rspec on rails 3.1
Rails Tutorial chapter 10.3.3 - 4 RSpec Errors (app working)
また、最初のリンクでは、sessions_helper.rbファイルにcurrent_userと@current_userが追加されています。私はこれを試しましたが、何も修正していないようです。 – Dmat00
もう1つのコメント、アプリは正常に動作します。ちょうどこの1つのテストは失敗します。それは非常にイライラしています! – Dmat00