2011-01-21 14 views
1
Factory.define :person do |p| 
    p.first_name { User.generate_activation_code(6) } 
    p.last_name { User.generate_activation_code(6) } 
    p.username { "p#{first_name}_#{last_name}" } 
    p.email { "#{username}@mail.com" } 
    p.password { "password" } 
    p.password_confirmation { "password" } 
end 

を動作しません。このエラーを与える:参照が正しく

undefined local variable or method first_name' for main:Object (NameError) ./test/factories/user_factories.rb:4 ./features/step_definitions/generic_steps.rb:3 ./features/step_definitions/generic_steps.rb:2:in each' ./features/step_definitions/generic_steps.rb:2:in /^these (.+) records$/' features/transaction_import.feature:7:in Given these person records'

ここに私の設定(ルビー1.8.7)だ

Using cucumber (0.10.0) 
Using cucumber-rails (0.3.2) 
Using factory_girl (1.3.3) 
Using railties (3.0.3) 
Using factory_girl_rails (1.0.1) 
Using rails (3.0.3) 
Using rspec-core (2.4.0) 
Using rspec-expectations (2.4.0) 
Using rspec-mocks (2.4.0) 
Using rspec (2.4.0) 
Using rspec-rails (2.4.1) 
Using webrat (0.7.3) 

答えて

1

あなたはPersonクラスを持っていますか?依存属性の

Factory.define :person, :class => User do |p| 

ドキュメント::それは代わりにUserでなければなりませんように見える

あなたはあなたの行を変更する必要が
+0

私は人のクラスがあります。ドキュメントが助けになりました。ありがとうございました。それは今再び働いています。 –

1

p.username { "p#{first_name}_#{last_name}" } 

p.username {|x| "#{x.first_name}_#{x.last_name}" } 

それは私のために働いた。

関連する問題