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