Rails 4.1.4和Rspec 3ActionMailer在测试邮件时失败
我正在用Rspec做一个非常基本的电子邮件测试。如果我从Rails控制台调用邮件程序,它可以很好地工作。如果我把它从邮件规范我得到:
wrong number of arguments (0 for 1..2)
的邮件是很基本的:
def create_team_invite(org, email)
@organization = org
mail(:to=>email, :subject=>'Test Subject')
end
测试是非常基本的太:
it 'can send out emails to invite others to create teams' do
UserMailer.create_team_invite(@org, '[email protected]').deliver
expect(ActionMailer::Base.deliveries.count).to eq 1
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq 'Test Subject'
expect(mail.from).to eq '[email protected]'
end
它在失败的“ mail(:to ...“)在我的环境中,似乎可能是它的一些配置问题,但我的测试设置与Dev完全一样,使用SMTP并将它发送到Mailcatcher端口。 looke d在Backtrace,但没有看到任何异常...
以前有人看过这个吗?
更新:提供请求的其他信息。
我test.rb,减去评论:
Rails.application.configure do
config.cache_classes = true
config.eager_load = false
config.serve_static_assets = true
config.static_cache_control = 'public, max-age=3600'
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.active_support.deprecation = :stderr
config.action_mailer.default_url_options = { :host => 'lvh.me:3000', :only_path=>false }
end
整个rspec的失败是:
UserMailer
团队加入电子邮件 可以发送电子邮件邀请他人创建团队(失败 - 1 )
失败:
1) UserMailer Team Joining Email can send out emails to invite others to create teams
Failure/Error: UserMailer.create_team_invite(@team, '[email protected]').deliver
ArgumentError:
wrong number of arguments (0 for 1..2)
# ./app/mailers/user_mailer.rb:11:in `create_team_invite'
# ./spec/mailers/user_mailer_spec.rb:36:in `block (3 levels) in <top (required)>'
Finished in 0.25858 seconds (files took 29 minutes 48 seconds to load)
1 example, 1 failure
我配置电子邮件的方式是通过一个初始化程序,从每个环境的配置中加载一个email.yml文件。测试和开发人员使用完全相同的过程,具有相同的设置。 (同样,我发送给Mailcatcher,而不是仅仅以mail_delivery:测试)
更新2
我已经把范围缩小到梅勒缺少“请求”对象。如果我挖通,其中错误发生(一个AbstractController rendering.rb,线109)它试图引用请求对象:
if defined?(request) && request && request.variant.present?
这被调用到机架test.rb线121:
def request(uri, env = {}, &block)
env = env_for(uri, env)
process_request(uri, env, &block)
end
因此,它像Rack Test.rb类被视为该抽象控制器中的请求方法...但我不知道如何,或为什么,或为什么会发生在这个特定的项目中...
请分享您的'environments/test.rb'。另外,我们可以看到整个测试失败... – Anthony 2014-10-10 14:54:25
我上面分享了他们 - 不要以为你有任何想法? – 2014-10-18 14:26:46
我删除了我的答案。我认为这是模板中的URI问题,但似乎没有。我只是隐藏了错误,所以我认为它工作。仍然得到相同的错误,并追踪它在宝石中没有显示任何有用的东西。美好时光。 – 2014-10-18 15:19:38