当我单独测试它们时,我的测试工作正常,
rake cucumber FEATURE = 'path/to/feature'
但是当我尝试跑步时
rake cucumber
他们因以下错误而失败
undefined method `password_confirmation=' for #<User:0x1069545f0> (NoMethodError)
当我尝试使用 Factory.build(:user) 创建用户时会出现这种情况。我有一个定义 :user 的工厂文件。
我真的不知道如何确认这一点,但好像 authlogic 不存在并且 User 模型还没有添加的方法。当我在工厂尝试构建新用户时查看用户方法 (User.new.methods.include?("password_confirmation=")) 时,有一个由该名称定义的方法。
我对此进行了很多搜索,但没有看到任何相关内容,所以我假设这是我正在做的其他事情。
编辑:
更多信息 - 我已经能够在一个简单的案例中重现这一点:
- - - - 。特征
Background:
Given user "Bad Admin" with email address "badmin@gmail.com" and password "password" exists with "admin" credentials
Given user "Good Admin" with email address "goodadmin@gmail.com" and password "password" exists with "edit" credentials
Scenario: valid log in with authorization
When I go to the login page
Scenario: invalid login
When I go to the login page
---- 工厂.rb
Factory.define :user do |u|
u.first_name "Arthur"
u.last_name "Dent"
u.email { Factory.next(:user_email) }
u.password "default"
u.password_confirmation "default"
end
---- 步骤.rb
Given /^user "([^"]*)" with email "([^"]*)", password "([^"]*)" and credentials "([^"]*)" exists$/ do |name, email, password, role|
names = name.split(' ')
user = Factory(:user, :first_name => names.first, :last_name => names.last, :email => email, :password => password, :password_confirmation => password)
user.has_role! role.downcase.gsub(' ', '_')
end