我運行以下特點:我的FactoryGirl創建的對象不會持久?
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個圖像已經存在'給予。我認爲索引操作在創建圖像之前被調用,因此新圖像實際上並沒有被拾取 – SuperMaximo93
@ SuperMaximo93乾杯,你釘了它。提交一個答案,如果你想信用:) – willcodejavaforfood
酷:)提交回答 – SuperMaximo93