我想为已经实施的邮件制作一个规范,我有这个:
应用/邮寄者/ application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: 'aaa@gmail.com'
layout 'mailer'
end
应用/邮寄者/ user_mailer.rb
class UserMailer < ApplicationMailer
def welcome(user)
@user = user
mail(to: @user.email, subject: 'Welcome!')
end
end
配置/环境/ test.rb
Rails.application.configure do
#[...]
config.action_mailer.delivery_method = :test
#[...]
end
规格/邮寄者/ usermailer_spec.rb
require 'spec_helper'
RSpec.describe UserMailer, :type => :mailer do
#[...]
end
当我跑步时
rspec spec / mailers / usermailer_spec.rb
我在终端上收到此错误消息:
[...] spec / mailers / usermailer_spec.rb:4:在`&#39;: 未初始化的常量UserMailer(NameError) [...]
答案 0 :(得分:0)
您需要在规范文件中要求require 'rails_helper'
而不是spec_helper
。