Factory_girl 工厂内的引用无法正常工作
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
给出这个错误:
未定义的局部变量或方法
first_name' 代表 main:Object (名称错误) ./test/factories/user_factories.rb:4 ./features/step_definitions/generic_steps.rb:3 ./features/step_definitions/generic_steps.rb:2:in
每个' ./features/step_definitions/generic_steps.rb:2:in/^这些 (.+) 记录$/' 特征/transaction_import.feature:7:in
鉴于这些人的记录'
这是我的配置(Ruby 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)
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
Gives this error:
undefined local variable or method
first_name' for main:Object
each'
(NameError)
./test/factories/user_factories.rb:4
./features/step_definitions/generic_steps.rb:3
./features/step_definitions/generic_steps.rb:2:in
./features/step_definitions/generic_steps.rb:2:in/^these (.+) records$/'
Given these person records'
features/transaction_import.feature:7:in
Here's my configuration (Ruby 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有
Person
类吗?看起来应该是User
:依赖属性的文档:
Do you have a
Person
class? Looks like it should beUser
instead:Documentation for dependent attributes:
你需要改变你的路线:
对
我有用。
You need to change your line:
to
That worked for me.