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

テーブルの行を数える最後のステップは、惨めに失敗します。ヘッダー行であると私が推測する1つの行しか見つけることができません。これらはインデックスページのテストであり、手動で動作することを確認しています。FactoryGirlで作成されたオブジェクトがコントローラーを取得しないのはなぜですか?

コントローラのインデックス方式:

  def index
    @images = Image.all
  end
4

1 に答える 1

3

「I am on the images page」と「4 つの images already exist」の順序を入れ替えます。

インデックス アクションが呼び出され、ビューは画像の作成前にレンダリングされるため、画像は取得されません。

また、これをすでに知っているかどうかはわかりませんが、代わりに

FactoryGirl.build(:image).save!

できるよ

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