0
我的工作軌道上的教程紅寶石的第10章,並獲得了後續錯誤:UserMailerTest引發ArgumentError:錯誤的參數數目(0 1)
UserMailerTest#test_account_activation:
ArgumentError: wrong number of arguments (0 for 1)
app/mailers/user_mailer.rb:3:in `account_activation'
test/mailers/user_mailer_test.rb:6:in `block in <class:UserMailerTest>'
我不知道是什麼原因造成由於代碼與教程中的代碼相同,所以錯誤。有任何想法嗎?
user_mailer.rb
class UserMailer < ApplicationMailer
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
def password_reset
@greeting = "Hi"
mail to: "[email protected]"
end
end
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout 'mailer'
end
的routes.rb
Rails.application.routes.draw do
get 'sessions/new'
root 'welcome#index'
get 'contact' => 'welcome#contact'
get 'about' => 'welcome#about'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
resources :account_activations, only: [:edit]
match ':controller(/:action(/:id))', :via => :get
end
user_mailer_test.rb
require 'test_helper'
class UserMailerTest < ActionMailer::TestCase
test "account_activation" do
mail = UserMailer.account_activation
assert_equal "Account activation", mail.subject
assert_equal ["[email protected]"], mail.to
assert_equal ["[email protected]"], mail.from
assert_match "Hi", mail.body.encoded
end
test "password_reset" do
mail = UserMailer.password_reset
assert_equal "Password reset", mail.subject
assert_equal ["[email protected]"], mail.to
assert_equal ["[email protected]"], mail.from
assert_match "Hi", mail.body.encoded
end
end
謝謝!
我看到了,修正了它。謝謝! –