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語法混淆了。如何在一條生產線上生成多個產品,但工廠名稱必須與模型匹配?