-2

ええ、私は BDD テストと特にテストが初めてです。rspec、factory_girl_rails、セレン、カピバラの宝石を使用しています。データの編集をテストして、次のように保存したい:

  it "edit consultant" do
    # c = FactoryGirl.create(:consultant)
    c = Consultant.create(
      orgorcom: "xyz",
      year_id: 8,
      bidang: "IT & Networking",
      project: "E-Sw",
      professional_fee: "1000000",
      role: "Database Architect",
      user_id: 19,
      nopkj: "075899 "
      )
    visit "/consultants?year=#{Time.now.year}"
    string = "#consultant#{c.id}"
    page.find(string).click_link('Edit')
    fill_in "Organization / Company" , :with => c.orgorcom + "aaa"
    fill_in "Field", :with => c.bidang + "aaa"
    fill_in "Project" , :with => c.project + "aaa"
    fill_in "Role", :with => c.role + "aaa"
    fill_in "Professional fee", :with => c.professional_fee + 111
    click_button "Save"
    expect(page).to have_content "Data updated."
    sleep 10
    # c.destroy
    # find('a[href="/consultants/6144/edit?year=2013"]').click
  end

しかし、作成したデータが表示されず、このメッセージが表示されます

  1) the consultation edit consultant
     Failure/Error: page.find(string).click_link('Edit')
     Capybara::ElementNotFound:
       Unable to find css "#consultant6157"

以下のように既存のデータをクリックしようとすると、通りました。

page.find("#consultant6144").click_link('Edit')

コンサルタント ID を出力できますが、不思議なことに、テストが終了する前にレコードが表示されませんでした (データベースはロールバックします)。

4

2 に答える 2

3

これは、ブラウザーのテストに Selenium を使用し、トランザクション フィクスチャが で構成されている場合の既知の問題ですspec_helper。Selenium は別のスレッドで実行され、Rspec がトランザクション内でデータベース オブジェクトを作成するために使用するものとは別のデータベース接続を使用するため、Selenium スレッドはそれらを参照できません。

この種のスペックでは、トランザクション フィクスチャを使用せず、database_cleanerのようなものを使用して、スペックの開始時にオブジェクトを作成し、後でそれらを切り捨て/削除する必要があります。

于 2013-08-25T06:46:29.520 に答える