統合テストがエラーになってしまいました。
今まで全部通っていたのですが、何かしら変えたことによって
統合テストがエラーになってしまいました。原因がわからず困っています。
実際、$r s
で動かすとDBもしっかり動いているように見えます。
フォームエラーによって同じフォームが表示されていたりします。
テスト
の★のつく箇所がエラー箇所です。本当かな...。
文法上の問題等、教えていただけると幸いです...。
要約(更新中)
・ but rendering with <[]>
になってしまうのがおかしい。 → 表示されてるのに。
・ "User.count" didn't change by 1.
になってしまうのがおかしい。 → 増えてるのに。
エラー内容
FAIL["test_ユーザ登録失敗時テスト", UsersSignupTest, 4.637436497000181] test_ユーザ登録失敗時テスト#UsersSignupTest (4.64s) expecting <"user/users/new"> but rendering with <[]> test/integration/users_signup_test.rb:13:in `block in <class:UsersSignupTest>' FAIL["test_ユーザ登録失敗時メッセージテスト", UsersSignupTest, 4.914939696000147] test_ユーザ登録失敗時メッセージテスト#UsersSignupTest (4.91s) expecting <"user/users/new"> but rendering with <[]> test/integration/users_signup_test.rb:21:in `block in <class:UsersSignupTest>' FAIL["test_ユーザ登録成功時テスト", UsersSignupTest, 5.075468785999874] test_ユーザ登録成功時テスト#UsersSignupTest (5.08s) "User.count" didn't change by 1. Expected: 35 Actual: 34 test/integration/users_signup_test.rb:26:in `block in <class:UsersSignupTest>' FAIL["test_ユーザ登録成功時フラッシュテスト", UsersSignupTest, 5.2429648319998705] test_ユーザ登録成功時フラッシュテスト#UsersSignupTest (5.24s) "User.count" didn't change by 1. Expected: 35 Actual: 34 test/integration/users_signup_test.rb:57:in `block in <class:UsersSignupTest>'
controller
class User::UsersController < User::Base before_action :logged_in_user,only:[:index] def new @user = User.new end def create @user = User.new(user_params) if @user.save @user.send_activation_email flash[:info] = "ユーザ本登録メールを送信しました。ご確認ください。" redirect_to [:user,:root] else render 'new' end end private def user_params params.require(:user).permit( :name,:email,:gender,:birth_year, :password,:password_confirmation) end end
テスト
require 'test_helper' class UsersSignupTest < ActionDispatch::IntegrationTest def setup ActionMailer::Base.deliveries.clear end test "ユーザ登録失敗時テスト" do get user_signup_path assert_no_difference 'User.count' do post user_signup_path,params:{user:{name:"",email:'invalid@email',password:'foo',password_confirmation:'bar',gender:1,birth_year:'1992'}} end ★ assert_template 'user/users/new' end test "ユーザ登録失敗時メッセージテスト" do get user_signup_path assert_no_difference 'User.count' do post user_signup_path,params:{user:{name:'invalid',email:'invalid@',password:'foo',password_confirmation:'bar',gender:1,birth_year:1992}} end ★ assert_template 'user/users/new' assert_select 'div#error_explanation' end test "ユーザ登録成功時テスト" do get user_signup_path ★ assert_difference 'User.count',1 do post user_signup_path,params:{user:{name:"ExampleUser",email:'example@example.com',gender:1,birth_year:1992,password:'password',password_confirmation:'password'}} end assert_equal 1, ActionMailer::Base.deliveries.size user = assigns(:user) assert_not user.activated? # 本登録していない状態でログイン log_in_as(user) assert_not is_logged_in? # 有効化トークン不正時 get edit_user_account_activation_path("invalid token", email: user.email) assert_not is_logged_in? # 有効化トークンは正しいがアドレスが無効時 get edit_user_account_activation_path(user.activation_token, email: 'wrong') assert_not is_logged_in? # 有効化トークンが正しい場合 get edit_user_account_activation_path(user.activation_token, email: user.email) assert user.reload.activated? follow_redirect! assert_template 'user/static_pages/index' assert is_logged_in? end test "ユーザ登録成功時フラッシュテスト" do get user_signup_path ★ assert_difference 'User.count',1 do post user_signup_path,params:{user:{name:"ExampleUser",email:'example@example.com',gender:1,birth_year:1992,password:'password',password_confirmation:'password'}} end follow_redirect! # POSTリク送信後、指定に移動するメソ assert_template 'user/static_pages/index' assert_not flash.empty? end end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。