如何加载用户\工厂的集合?
我正在使用 Ruby on Rails 3.1.0、rspec-rails 2
和 Factory
gem。为了测试控制器 index
操作,我想加载用户\工厂的集合。
示例(以下代码不起作用):
describe "GET index" do
let(:users) { 3.times(Factory(:user)) }
it "should ..." do
users.should ...
end
end
使用上面的代码我收到以下错误:
Failure/Error: let(:users) { 3.times(Factory(:user)) }
ArgumentError:
wrong number of arguments(1 for 0)
如何将工厂加载到 users
变量中?
更新 ...如果在上面的代码中我有 Factory(:user, :account => Factory.build(:account))
而不是工厂(:用户)
如何加载工厂?
I am using Ruby on Rails 3.1.0, rspec-rails 2
and Factory
gems. In order to test a controller index
action I would like to load a collection of users\factories.
Example (the following code doesn't work):
describe "GET index" do
let(:users) { 3.times(Factory(:user)) }
it "should ..." do
users.should ...
end
end
Using the above code I get the following error:
Failure/Error: let(:users) { 3.times(Factory(:user)) }
ArgumentError:
wrong number of arguments(1 for 0)
What can I do to load factories in to users
variable?
UPDATE ... and if in the above code I have Factory(:user, :account => Factory.build(:account))
instead of Factory(:user)
how can I load factories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
let(:users) { FactoryGirl.create_list(:user, 3) }
Try
let(:users) { FactoryGirl.create_list(:user, 3) }