Rspec email_spec问题

我正在浏览此用户身份validation教程..

http://larsgebhardt.de/user-authentication-with-ruby-on-rails-rspec-and-capybara/

..which使用gem’mail_spec’。 当然,作者正在使用早期版本的rails和rspec,我遇到了让gem正常工作的问题。

添加时..

spec_helper.rb

RSpec.configure do |config| ... config.include(EmailSpec::Helpers) config.include(EmailSpec::Matchers) ... end 

我收到错误..

 Neither Pony nor ActionMailer appear to be loaded so email-spec is requiring ActionMailer. WARN: Unresolved specs during Gem::Specification.reset: minitest (~> 5.1) rack-test (~> 0.6.2) WARN: Clearing out unresolved specs. Please report a bug if this causes problems. 

我仍然可以看到预期的测试失败,所以我继续,但是一旦我到达它的部分,我将config.include(UserHelper)添加到spec_helper,gem或测试套件坏了。

铁路和rspec的这一侧有点超过我的头。 任何帮助都非常感谢。

我目前正在运行Rails 4.1.6和Rspec 3.1.7。

这里有两个问题需要解决。

首先,有来自email_spec gem的通知。 要摆脱这种情况,只需在email_spec中的rails_helper.rb之前要求rails_helper.rb

 require "action_mailer" require "email_spec" 

实际上, email_spec gem会为你做这个(因此通知),但如果你想摆脱讨厌的消息,这就是解决方案。

其次,存在config.include(UserHelper)的问题。 这实际上与第一个问题无关,并且因为当您尝试引用UserHelper模块时未包含support/user_helper.rb文件。

发生这种情况的原因是因为您所关注的文章是在RSpec 3之前编写的,因此在Rails配置移动到rspec_helper.rb文件之前。 (有关升级的更多信息,请访问: https : //www.relishapp.com/rspec/rspec-rails/docs/upgrade )

要解决此问题:

  1. rails_helper.rb取消注释此行:

    Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

    这将从spec/support目录树加载所有文件。

  2. 将所有配置从spec_helper.rb移动到rails_helper.rb