1
我正在构建一个简单的测试,以便为用户显示产品。我的规格如下所示:Rails 3.2使用FactoryGirl RSpec测试混淆
require 'spec_helper'
describe "Show Products" do
it "Displays a user's products" do
product = Factory(:product)
visit products_path
page.should have_content("ABC1")
end
end
和我厂的产品是这样的:
FactoryGirl.define do
factory :product do
sequence(:identifier, 1000) {|n| "ABC#{n}" }
end
end
我有一个简单的观点:
<table id="products">
<thead>
<th>Product ID</th>
</thead>
<tbody>
<% for product in @products %>
<tr>
<td><%= @product.identifier %></td>
</tr>
<% end %>
</tbody>
</table>
我得到的错误是,没有@products这样的东西。那么,是的。这是我的问题。由于我的工厂被定义为“产品”,并且它有一个序列,我如何将“产品”的值放入一个名为“产品”的变量中。
我基本上被FactoryGirl语法混淆了。如何在一条生产线上生成多个产品,但工厂名称必须与模型匹配?