Rspec email_spec 问题 [英] Rspec email_spec issue

查看:16
本文介绍了Rspec email_spec 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习此用户身份验证教程..

I am going through this User Authentication tutorial..

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

...使用 gem 'email_spec'.假设作者使用的是早期版本的 rails 和 rspec,我在让 gem 正常工作时遇到问题.

..which uses the gem 'email_spec'. Granted the author is using an earlier version of rails and rspec, I am having issues getting the gem to work properly.

添加时..

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 或测试套件就坏了.

I can still see the expected test failures so I continued, but once I got to the part where it had me add config.include(UserHelper) to the spec_helper, the gem or test suite broke.

rails 和 rspec 的这一侧有点超出我的想象.任何帮助都受到高度赞赏.

This side of rails and rspec is a little over my head. Any help is highly appreciated.

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

I am currently running Rails 4.1.6 and Rspec 3.1.7.

推荐答案

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

There are two problems to fix here.

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

Firstly, there is the notice from the email_spec gem. To get rid of this, simply require action_mailer before email_spec in your rails_helper.rb:

require "action_mailer"
require "email_spec"

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

Actually the email_spec gem will do this for you (hence the notice), but if you want to get rid of the pesky message, this is the solution.

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

Secondly, there is the issue of config.include(UserHelper). This is actually unrelated to the first issue, and happens because the support/user_helper.rb file is not included when you try to reference the UserHelper module.

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

The reason this happens is because the article you're following was written before RSpec 3, and thus before the Rails configurations moved to the rspec_helper.rb file. (More information on the upgrade here: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade)

解决问题:

  1. rails_helper.rb 中取消注释这一行:

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

这将从 spec/support 目录树中加载您的所有文件.

This will load all your files from the spec/support directory tree.

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

Move all your configurations from spec_helper.rb to rails_helper.rb.

这篇关于Rspec email_spec 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆