0

我正在运行以下功能:

  Scenario: viewing existing images
    Given I am on the images page
    And 4 images already exist
    Then I should see a table containg those 4 images
    And have the option to show images
    And have the option to delete images

定义了这些步骤:

Given /^I am on the images page$/ do
  visit(images_path)
end

Given /^(\d+) images already exist$/ do |count|
  count.to_i.times {
    FactoryGirl.build(:image).save!
  }
end

Then /^I should see a table containg those (\d+) images$/ do |count|
  page.all('table#imagesTable tr').count.should == count
end

最后一步,计算表中的行数,失败得很惨。它只能找到一行,我假设是标题行。这些是索引页面的测试,我已经手动确认它有效。为什么我的 FactoryGirl 创建的对象没有拾取我的控制器?

控制器的索引方法:

  def index
    @images = Image.all
  end
4

1 回答 1

3

交换“我在图片页面”和“4 张图片已经存在”的顺序。

索引操作被称为视图在创建图像之前呈现,因此它们不会被拾取。

另外,我不知道你是否已经知道这一点,而不是

FactoryGirl.build(:image).save!

你可以做

FactoryGirl.create(:image)
于 2012-06-16T10:57:50.773 回答