gpt4 book ai didi

ruby - 为什么规范失败?

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:42 24 4
gpt4 key购买 nike

我有两个规范。一个使用所有默认值编写(我认为 selenium 是默认值?),另一个使用 webkit。它们完全一样,但一个失败了另一个没有

规范

let(:admin) {create(:user, :admin)}
let(:programme) { create(:programme, :full_payment_scheme) }

before(:each) do
login_as(admin)
visit edit_programme_path(programme)
end

scenario 'adding a payment_scheme', js: true do
new_payment_scheme = create(:payment_scheme)
visit edit_programme_path(programme)
click_link 'Add Payment Scheme'
select new_payment_scheme.name, from: all('select[id*="programme_programme_payment_schemes_attributes"][id*="payment_scheme_id"]').last[:id]
fill_in all('input[id*="programme_programme_payment_schemes_attributes"][id*="markup"]').last[:id], with: 50
fill_in all('input[id*="programme_payment_scheme_allocations_attributes"][id*="interval_weeks"]').last[:id], with: 10
fill_in all('input[id*="programme_payment_scheme_allocations_attributes"][id*="allocation"]').last[:id], with: 100

expect {click_button "Save"}.to change{ProgrammePaymentScheme.count}.by(1)
end

上述规范中的 javascript 发生在 click_link 'Add Payment Scheme' 上。它将支付方案的控件添加到页面并填写这些控件。注意我知道 ID 看起来很奇怪,但是当您使用嵌套属性并将控件动态添加到页面时,ID 中有一个随机部分(通常计算日期)。所以我不能使用直接ID。我必须使用时髦的 CSS 选择器。

默认结果

Programme edit page
editing the payment_scheme
adding a payment_scheme

Finished in 8.57 seconds (files took 1.25 seconds to load)
1 example, 0 failures

Top 1 slowest examples (7.6 seconds, 88.7% of total time):
Programme edit page editing the payment_scheme adding a payment_scheme
7.6 seconds ./spec/features/programmes/programme_edit_spec.rb:48
ryanme@Ryan-Mes-MacBook-Pro ~/Sites/phoenix ±20487304354485⚡ » rspec spec/features/programmes/programme_edit_spec.rb

Webkit 的结果

Programme edit page
editing the payment_scheme
adding a payment_scheme (FAILED - 1)

Failures:

1) Programme edit page editing the payment_scheme adding a payment_scheme
Failure/Error: expect {click_button "Save"}.to change{ProgrammePaymentScheme.count}.by(1)
expected result to have changed by 1, but was changed by 0
# ./spec/features/programmes/programme_edit_spec.rb:57:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'

Finished in 3.8 seconds (files took 0.53482 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/programmes/programme_edit_spec.rb:48 # Programme edit page editing the payment_scheme adding a payment_scheme

Top 1 slowest examples (3.48 seconds, 91.5% of total time):
Programme edit page editing the payment_scheme adding a payment_scheme
3.48 seconds ./spec/features/programmes/programme_edit_spec.rb:48

当我使用 launchy 保存并打开页面时,我发现由于某种原因它没有填写付款方案字段。此功能使用 selenium 时效果很好。我曾尝试修改测试,但没有成功。

我认为这就是一切。任何输入将不胜感激。

最佳答案

可能是两件事

最明显的是,您可能会遇到异步问题,因为您使用的是 Capybara。 Capybara/测试线程告诉浏览器点击按钮然后继续。它不会等待其他任何事情发生,因此浏览器仍然可以处理 JS 并将请求发送回应用程序。您可以通过 sleep 或监听一些触发器来解决这个问题。

也可能是您用于单击按钮的 JS 或用于处理 JS 请求的代码没有按预期执行。

关于ruby - 为什么规范失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27164653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com