我正在运行以下功能:
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