我的測試工作,當我單獨測試它們罰款,未定義的方法「password_confirmation」用戶:測試Authlogic黃瓜和工廠女孩
rake cucumber FEATURE = 'path/to/feature'
但是當我嘗試運行
rake cucumber
他們失敗,出現以下錯誤
undefined method `password_confirmation=' for #<User:0x1069545f0> (NoMethodError)
這出現了,當我嘗試創建一個用戶使用Factory.build (:用戶)。我有一個工廠文件,它定義了一個:user。
我真的不知道如何確認這一點,但它好像authlogic不存在,用戶模型還沒有添加方法。當我在Factory試圖構建一個新用戶時查看User方法(User.new.methods.include?(「password_confirmation =」))時,有一個由該名稱定義的方法。
我在這方面做了很多搜索,而且我沒有看到任何相關的東西,所以我假設這是我正在做的其他事情。
編輯:
多一點信息 - 我已經能夠重現這在一個簡單的例子:
------- .feature
Background:
Given user "Bad Admin" with email address "[email protected]" and password "password" exists with "admin" credentials
Given user "Good Admin" with email address "[email protected]" 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
- - factories.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
---- steps.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
嗨Voidy - 這是設置黃瓜和authlogic的非常有用的代碼。就我而言,我沒有註冊視圖,用戶是以其他方式創建的。這些用戶本質上是管理員,因此他們是通過控制檯或rake任務創建的。它們是由User.create創建的(:username =>'...',:password =>'...',::password_confirmation =>'...'。我可以想出一個UI來做到這一點,但我寧願不 - 我想弄清楚爲什麼這種方法在一個功能單獨運行時工作,而不是當它們按順序運行時運行。 – Swards 2010-09-30 14:48:23