railsチュートリアル7章についてrails test時のエラーが解決できません。どなたかご教授、ご意見頂けますと幸いです。
問題点が未把握な状態ですので、問題点及びその解決法を知りたいです。宜しくお願い致します。
ubuntu:~/environment/sample_app (main) $ rails test Running via Spring preloader in process 5210 Run options: --seed 63281 # Running: .....E Error: UsersSignupTest#test_invalid_signup_information: NameError: undefined local variable or method `user_params' for #<UsersController:0x00560ed52c4400> Did you mean? user_path app/controllers/users_controller.rb:12:in `create' test/integration/users_signup_test.rb:8:in `block (2 levels) in <class:UsersSignupTest>' test/integration/users_signup_test.rb:7:in `block in <class:UsersSignupTest>' rails test test/integration/users_signup_test.rb:5 E Error: UsersSignupTest#test_valid_signup_information: NameError: undefined local variable or method `user_params' for #<UsersController:0x00560ed53fd448> Did you mean? user_path app/controllers/users_controller.rb:12:in `create' test/integration/users_signup_test.rb:23:in `block (2 levels) in <class:UsersSignupTest>' test/integration/users_signup_test.rb:22:in `block in <class:UsersSignupTest>' rails test test/integration/users_signup_test.rb:20
上記エラーに対し、該当ファイルを載せますので併せてご確認下さい。
統合テストファイル名:users_signup_test.rb
require 'test_helper' class UsersSignupTest < ActionDispatch::IntegrationTest test "invalid signup information" do get signup_path assert_no_difference 'User.count' do post users_path, params: { user: { name: "", email: "user@invalid", password: "foo", password_confirmation: "bar" } } end assert_template 'users/new' assert_select 'div#<CSS id for error explanation>' assert_select 'div.<CSS class for field with error>' end test "valid signup information" do get signup_path assert_difference 'User.count', 1 do post users_path, params: { user: { name: "Example User", email: "user@example.com", password: "password", password_confirmation: "password" } } end follow_redirect! assert_template 'users/show' assert_not flash.FILL_IN end end
コントローラーファイル名:users_controller.rb
class UsersController < ApplicationController def show @user = User.find(params[:id]) debugger end def new @user = User.new end def create @user = User.new(user_params) if @user.save redirect_to @user else render 'new' end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end end end
def createのend位置を修正後さらに下記のエラーが発生致しました。
ubuntu:~/environment/sample_app (main) $ rails test Running via Spring preloader in process 5733 Run options: --seed 14035 # Running: .E Error: UsersSignupTest#test_invalid_signup_information: Nokogiri::CSS::SyntaxError: unexpected '#' after '[#<Nokogiri::CSS::Node:0x0000556852973a50 @type=:ELEMENT_NAME, @value=["div"]>]' (eval):3:in `_racc_do_parse_c' (eval):3:in `do_parse' test/integration/users_signup_test.rb:14:in `block in <class:UsersSignupTest>' rails test test/integration/users_signup_test.rb:5 E Error: UsersSignupTest#test_valid_signup_information: ActionView::Template::Error: undefined local variable or method `options' for #<ActionView::Base:0x007ff1f85073b8> Did you mean? url_options app/helpers/users_helper.rb:3:in `gravatar_for' app/views/users/show.html.erb:6 test/integration/users_signup_test.rb:28:in `block in <class:UsersSignupTest>' rails test test/integration/users_signup_test.rb:20 .......... Finished in 1.221876s, 10.6394 runs/s, 22.0972 assertions/s. 13 runs, 27 assertions, 0 failures, 2 errors, 0 skips
こちらに関しまして、問題点を分かりやすくご教示頂けますと幸いです。また解決策もございましたら宜しくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/30 04:37
2021/03/30 07:41