对于Devise黄瓜步失败,连接被拒绝了吗?

时间:2011-05-11 20:36:59

标签: cucumber devise

我正在尝试使用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

这对我的用户工厂来说:

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 "a_new_user@example.com/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 "a_new_user@example.com/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

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

1 个答案:

答案 0 :(得分:0)

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

config.action_mailer.delivery_method = :test

这告诉我们“不要向现实世界发送电子邮件”。