Devise 的 Cucumber 步骤失败,连接被拒绝?
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的environments/test.rb文件中是否有这个:
这告诉rails“不要将电子邮件发送到现实世界”。
Do you have this in your environments/test.rb file:
This tells rails "not to deliver emails to the real world".