ええ、私は 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 を出力できますが、不思議なことに、テストが終了する前にレコードが表示されませんでした (データベースはロールバックします)。