使用多个类对象实例时遇到问题?
我在Rails 3.0.9和Rspect 2上使用Ruby。我试图以以下方式重构一些SPEC文件(为了使用较少的代码测试相似的代码 user class obsoct object属性值):
let(:user1) { Factory(:user, :users_attribute_a => 'invalid_value') }
let(:user2) { Factory(:user, :users_attribute_b => 'invalid_value') }
let(:user3) { Factory(:user, :users_attribute_c => 'invalid_value') }
[ user1, user2, user3 ].each do |user|
...
end
但是,如果我运行上述测试,我会收到以下错误:
undefined local variable or method `user1' for #<Class:0x00000103ddb158> (NameError)
有什么问题?我该如何解决?
I am using Ruby on Rails 3.0.9 and RSpect 2. I am trying to refactoring some spec file in the following way (in order to test with less code similar User
class object attribute values):
let(:user1) { Factory(:user, :users_attribute_a => 'invalid_value') }
let(:user2) { Factory(:user, :users_attribute_b => 'invalid_value') }
let(:user3) { Factory(:user, :users_attribute_c => 'invalid_value') }
[ user1, user2, user3 ].each do |user|
...
end
However, if I run the above test I get the following error:
undefined local variable or method `user1' for #<Class:0x00000103ddb158> (NameError)
What is the problem? How can I solve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将示例代码放在“it”块内
You need your example code inside of a "it" block