RSpec & Capybaraを使用してBDDを適用するRailsアプリケーションを作成しています。私のテストの1つは失敗し続けます。テストの目的は、インデックスページに表示された各マシンレコードが編集リンクをクリックすると、詳細編集ページを視覚化するかどうかをチェックすることです。アプリケーションを実行すると、この機能が動作します。だから、私のRSpecのシナリオには何か間違いがあると思います。ここでコンテンツがpage.htmlにある間にRSpec/Capybara "expect(page).to have_content"テストが失敗する
は失敗し、テストだ:
Failures:
1) existing machines have a link to an edit form
Failure/Error: expect(page).to have_content(@existing_machine.model)
expected to find text "RX22" in "Toggle navigation uXbridge Catalogue Settings Brands Machine Types Machine Groups Repair States Titles User Signed in as [email protected] Sign out Machine details Brand TORO Model Machine type ZITMAAIER Description Engine Purchase Price Unit Price VAT Minimal Stock Current Stock Warehouse Location"
# ./spec/features/machine_spec.rb:50:in `block (2 levels) in <top (required)>'
ここでは、テストのコードです:シナリオをデバッグする場合
RSpec.feature 'existing machines' do
before do
@john = User.create!(email: '[email protected].com', password: 'password')
login_as @john
brand = Brand.create!(name: 'TORO')
machinegroup = Machinegroup.create!(name: 'GAZON')
machinetype = Machinetype.create!(name: 'ZITMAAIER', machinegroup_id: machinegroup.id)
@existing_machine = Machine.create!(brand_id: brand.id, model: 'RX22', machinetype_id: machinetype.id, description: 'fantastic machine', engine: '100PK')
end
scenario 'have a link to an edit form' do
visit '/machines'
find("a[href='/machines/#{@existing_machine.id}/edit']").click
expect(page).to have_content('Machine details')
expect(page).to have_content(@existing_machine.model)
end
end
、@existing_machineオブジェクトが正しく.createを通じて人口ようだ()メソッドは!前のブロックで。
screenshot of debug window in IDE
デバッガでpage.htmlを検査するときに、私が登場する "RX22" の文字列を参照しています。
screenshot of page.html inspection
期待(ページ).TO have_content(@ existing_machine.model)を実行するときに、なぜRSpecの/カピバラは、同じコンテンツを見ていないのですか?
おかげで多くのことを動作するはずです!できます!学ぶ楽しみ。 – lbaeyens