Devise 的 Cucumber 步骤失败,连接被拒绝?

发布于 11-06 19:01 字数 2516 浏览 2 评论 0原文

我正在尝试使用 Devise 进行一些 Cucumber 测试,并且我有以下步骤定义:

Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)\/(.*)"$/ do |email, password|
  Factory(:user, :email => email, :password => password, :password_confirmation => password)
end

这对于我的 User 工厂:

Factory.define :user do |u|
  u.sequence(:email) { |n| "testing@example#{n}.com" }
  u.password "test_pass"
  u.password_confirmation "test_pass"
  u.sequence(:display_name) { |n| "user#{n}" }
  u.people { |i| [i.association(:person), i.association(:person)] }
end

并且我已加载这些 Devise 模块(在 app/models/user.rb >):

# Include Devise modules
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :confirmable, :lockable, :timeoutable

我使用上述步骤运行 Cucumber 场景,但失败并显示:

Given I am signed in as "[email protected]/test_password" # features/step_definitions/devise_steps.rb:7
  Connection refused - connect(2) (Errno::ECONNREFUSED)
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `initialize'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `open'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `block in do_start'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `do_start'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
  ./features/step_definitions/devise_steps.rb:4:in `/^(?:I am|I have|I) signed up (?:as|with) "(.*)\/(.*)"$/'
  features/users/friends.feature:7:in `Given I am signed in as "[email protected]/test_password"'

...我认为这与创建新用户时发送确认电子邮件有关,我已在其中进行了配置config/environments/cucumber.rb

App::Application.configure do

  # sets our mailer to localhost for the mailer (Devise)
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

end

如何解决这个问题/修复这个问题/避免这个问题?如果您需要更多信息来帮助我解决此问题,请告诉我...

I'm trying to get some Cucumber tests working with Devise, and I have the following step definition:

Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)\/(.*)"$/ do |email, password|
  Factory(:user, :email => email, :password => password, :password_confirmation => password)
end

And this for my User factory:

Factory.define :user do |u|
  u.sequence(:email) { |n| "testing@example#{n}.com" }
  u.password "test_pass"
  u.password_confirmation "test_pass"
  u.sequence(:display_name) { |n| "user#{n}" }
  u.people { |i| [i.association(:person), i.association(:person)] }
end

And I have these Devise modules loaded (in app/models/user.rb):

# Include Devise modules
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :confirmable, :lockable, :timeoutable

I run a Cucumber scenario with the above step, and it fails with:

Given I am signed in as "[email protected]/test_password" # features/step_definitions/devise_steps.rb:7
  Connection refused - connect(2) (Errno::ECONNREFUSED)
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `initialize'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `open'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `block in do_start'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:551:in `do_start'
  /Users/macbook/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
  ./features/step_definitions/devise_steps.rb:4:in `/^(?:I am|I have|I) signed up (?:as|with) "(.*)\/(.*)"$/'
  features/users/friends.feature:7:in `Given I am signed in as "[email protected]/test_password"'

... which I assume is related to the sending of the confirmation email when a new user is created, which I have configured in config/environments/cucumber.rb:

App::Application.configure do

  # sets our mailer to localhost for the mailer (Devise)
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

end

How do I get around this/fix this/avoid this? Let me know if you need anymore info to help me solve this issue...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满地尘埃落定2024-11-13 19:01:41

你的environments/test.rb文件中是否有这个:

config.action_mailer.delivery_method = :test

这告诉rails“不要将电子邮件发送到现实世界”。

Do you have this in your environments/test.rb file:

config.action_mailer.delivery_method = :test

This tells rails "not to deliver emails to the real world".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文