0
我正在寫一個Rails應用程序應用BDD使用RSpec &水豚。我的一個測試仍然失敗。測試的目標是檢查索引頁面上顯示的每臺機器記錄是否單擊編輯鏈接,導致可視化詳細信息編輯頁面。當我運行我的應用程序時,此功能起作用。所以我想,我的RSpec方案出了問題。RSpec /水豚「expect(page).to have_content」測試失敗,而內容是在page.html
下面是失敗的測試:
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]', 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
那麼,爲什麼RSpec的/水豚不執行預期(頁)當看到同樣的內容。要have_content(@ existing_machine.model)?
非常感謝!有用!有趣的學習。 – lbaeyens