パスワード再設定用のメイラーメソッドのテストをかいていたところ、以下のようなエラーメッセージが出てしまいました。しかしfixtureにはmichealというユーザーがあります。なぜ、エラーが起こるのか分かりません。
エラーメッセージ
test_password_reset#UserMailerTest (1.61s) StandardError: StandardError: No fixture named 'michael' found for fixture set 'users' test/mailers/user_mailer_test.rb:17:in `block in <class:UserMailerTest>'
test/mailers/user_mailer_test.rb
ruby
1require 'test_helper' 2 3class UserMailerTest < ActionMailer::TestCase 4 test "account_activation" do 5 user = users(:micheal) 6 user.activation_token = User.new_token 7 mail = UserMailer.account_activation(user) 8 assert_equal "Account activation", mail.subject 9 assert_equal [user.email], mail.to 10 assert_equal ["noreply@example.com"], mail.from 11 assert_match user.name, mail.body.encoded 12 assert_match user.activation_token, mail.body.encoded 13 assert_match CGI.escape(user.email), mail.body.encoded 14 end 15 16 test "password_reset" do 17 user = users(:michael) 18 user.reset_token = User.new_token 19 mail = UserMailer.password_reset(user) 20 assert_equal "Password reset", mail.subject 21 assert_equal [user.email], mail.to 22 assert_equal ["noreply@example.com"], mail.from 23 assert_match user.reset_token, mail.body.encoded 24 assert_match CGI.escape(user.email), mail.body.encoded 25 end 26 27end 28
test/fixtures/users.yml
micheal: name: Micheal Example email: micheal@example.com password_digest: <%= User.digest('password') %> admin: true activated: true activated_at: <%= Time.zone.now %> archer: name: Sterling Archer email: duchess@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> lana: name: Lana Kane email: hands@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> malory: name: Malory Archer email: boss@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> <% 30.times do |n| %> user_<%= n %>: name: user_<%= n %> email: user_<%= n %>@example.com password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> <% end %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。