RSpecのテストでエラーになってしまい、原因と解決方法が分からない為、質問させていただきます。
開発環境は、以下のようになります。
Rails 6.0.4.1
Ruby 2.5.1
コードは、以下のようになります。
[spec/system/users_spec.rb] require 'rails_helper' RSpec.describe "UsersSpec.rbs", type: :system do let(:user) { create(:user) } describe 'ログイン後' do before { login_as(user) } describe 'パスワードの変更機能の検証' do fit 'パスワードが変更できる' do visit profile_path click_on 'パスワードのリセット' fill_in 'email', with: user.email click_button '送信' expect(page).to have_content 'パスワードリセットのメールを送信しました' visit edit_password_reset_url(user.reload.reset_password_token) expect(page).to have_content user.email fill_in 'パスワード', with: 'update_password' fill_in 'パスワード確認', with: 'update_password' click_button '更新する' expect(page).to have_content('パスワードを変更しました') expect(current_path).to eq(login_path) end end
エラーは、以下のようになります。
higmonta@higuchimiyukiyuunoMacBook-Pro fishing_cooking % bundle exec rspec DEPRECATION WARNING: Initialization autoloaded the constants ActionText::ContentHelper and ActionText::TagHelper. Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. Reloading does not reboot the application, and therefore code executed during initialization does not run again. So, if you reload ActionText::ContentHelper, for example, the expected changes won't be reflected in that stale Module object. These autoloaded constants have been unloaded. Please, check the "Autoloading and Reloading Constants" guide for solutions. (called from <top (required)> at /Users/higmonta/workspace/fishing_cooking/config/environment.rb:5) Run options: include {:focus=>true} UsersSpec.rbs ログイン後 パスワードの変更機能の検証 パスワードが変更できる (FAILED - 1) Failures: 1) UsersSpec.rbs ログイン後 パスワードの変更機能の検証 パスワードが変更できる Failure/Error: visit edit_password_reset_url(user.reload.reset_password_token) Net::ReadTimeout: Net::ReadTimeout [Screenshot]: /Users/higmonta/workspace/fishing_cooking/tmp/screenshots/failures_r_spec_example_groups_users_spec_rbs_nested_2_nested_3_パスワードが変更できる_512.png # ./spec/system/users_spec.rb:251:in `block (4 levels) in <top (required)>' Finished in 1 minute 19.1 seconds (files took 3.9 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/system/users_spec.rb:245 # UsersSpec.rbs ログイン後 パスワードの変更機能の検証 パスワードが変更できる
自分で試したことと考えたこと
タイムアウトとなっており、テスト実行時に時間がかかりすぎてしまいエラーになってしまうと考えました。
development環境では、ブラウザでは問題なくパスワードが変更できます。
テストコードをデバッグしたところ、以下のようになりました。
higmonta@higuchimiyukiyuunoMacBook-Pro fishing_cooking % bundle exec rspec DEPRECATION WARNING: Initialization autoloaded the constants ActionText::ContentHelper and ActionText::TagHelper. Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. Reloading does not reboot the application, and therefore code executed during initialization does not run again. So, if you reload ActionText::ContentHelper, for example, the expected changes won't be reflected in that stale Module object. These autoloaded constants have been unloaded. Please, check the "Autoloading and Reloading Constants" guide for solutions. (called from <top (required)> at /Users/higmonta/workspace/fishing_cooking/config/environment.rb:5) Run options: include {:focus=>true} UsersSpec.rbs ログイン後 パスワードの変更機能の検証 ^A^BFrom:^A^B /Users/higmonta/workspace/fishing_cooking/spec/system/users_spec.rb:246 : 241: end 242: end 243: 244: describe 'パスワードの変更機能の検証' do 245: fit 'パスワードが変更できる' do => 246: binding.pry 247: visit profile_path 248: click_on 'パスワードのリセット' 249: fill_in 'email', with: user.email 250: click_button '送信' 251: expect(page).to have_content 'パスワードリセットのメールを送信しました' [1] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> visit profile_path => nil [2] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> click_on 'パスワードのリセット' => Obsolete #<Capybara::Node::Element> [3] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> fill_in 'email', with: user.email => #<Capybara::Node::Element tag="input" path="/HTML/BODY[1]/DIV[1]/DIV[1]/DIV[2]/DIV[1]/FORM[1]/DIV[1]/INPUT[1]"> [4] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> click_button '送信' => Obsolete #<Capybara::Node::Element> [5] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> expect(page).to have_content 'パスワードリセットのメールを送信しました' => true [6] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> user.reload.reset_password_token => "ckQnUfstgya-Rpk4pCfe" [7] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)> visit edit_password_reset_url(user.reload.reset_password_token)Net::ReadTimeout: Net::ReadTimeout from /Users/higmonta/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:181:in `rbuf_fill' [8] pry(#<RSpec::ExampleGroups::UsersSpecRbs::Nested_2::Nested_3>)>
visit edit_password_reset_url(user.reload.reset_password_token)の部分でタイムアウトになっており、アクセスができていない状態です。
プレフィックスも以下のようになっており、正しい状態です。
edit_password_reset GET /password_resets/:id/edit(.:format) password_resets#edit
考えられるのがdevelopment環境の時に以下のようなURLだとポート番号が記載されてなく、アクセスできず、
http://localhost/password_resets/uqpk5GV1pjYCRv43fA4z/edit
以下のようにポート番号を記載することでアクセスできました。
http://localhost:3000/password_resets/uqpk5GV1pjYCRv43fA4z/edit
テスト環境で'visit edit_password_reset_url(user.reload.reset_password_token)'でアクセスする際にポート番号が記載されていないURLにアクセスしようとしているのではないかなと思いました。
以下の記載はしています。
[config/environments/test.rb] config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
テスト実行時にタイムアウトになる理由と解消方法のご教示をお願いします。

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。