私は周りを検索しましたが、これは十分に一般的な問題のようですが、何もうまくいきませんでした。どうぞ!
まず、Hartl RoR チュートリアルに取り組んでいます。セクション 9 (ビデオ 905)の終わりに近づいており、失敗したユーザー ログインをテストしようとしています。のコードは次のuser_spec.rb
とおりです。
describe "failure" do
it "should not log the user in" do
visit login_path
puts response.body
fill_in 'session_email', with: ""
fill_in 'session_password', with: ""
click_button
response.should have_selector('div.login_error', content: "Invalid")
response.should render_template('sessions/new')
end
end
自動テストエラーは次のとおりです。
1) User login failure should not log the user in
Failure/Error: visit login_path
NameError:
undefined local variable or method `login_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_5::Nested_1:0x00000102c79248>
# ./spec/models/user_spec.rb:176:in `block (4 levels) in <top (required)>'
visit login_path
として書いてみましvisit '/login'
たが、次のように変更されましたが、まだエラーが発生しました。
Failure/Error: visit '/login'
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_5::Nested_1:0x00000102c2d140>
「訪問」がwebrat(rspecではない)から来ていることをどこかで読んだので、これはおそらくwebratの問題だと思います。puts response.body
また、自動テストの失敗に表示されないため、最初の行を過ぎていないこともわかっています。さらに紛らわしいのは、アプリの別の部分に、実質的に同一の他のテスト コードがあり、正常に動作することです。
layout_links_spec.rb
:
before(:each) do
@user = Factory(:user)
visit login_path
# puts response.body
fill_in 'session_email', with: @user.email
fill_in 'session_password', with: @user.password
click_button
end
何か案は?