gpt4 book ai didi

ruby-on-rails - 无 rspec 期望的 capybara have_field 在升级到 2.2 时失败

转载 作者:行者123 更新时间:2023-12-04 06:18:30 25 4
gpt4 key购买 nike

在我将 Capybara 从 2.1.0 升级到 2.2.1 并将 Poltergeist 从 1.4.1 升级到 1.5.0 之后,以下 rspec 期望在我的 Rails 应用程序测试中开始失败:

it{ expect(page).to have_field("foo_field_id", with: nil) }

rspec 错误如下所示:
 Failure/Error: it{ expect(page).to have_field("foo_field_id", with: nil) }
Capybara::ExpectationNotMet:
expected to find field "foo_field_id" but there were no matches. Also found "", which matched the selector but not all filters.

如果我抛出一个断点进行检查,则该值确实为零:
»  page.find_field('foo_field_id').value
=> nil

如果我将“with”更改为“text”,则断言通过:
it{ expect(page).to have_field("foo_field_id", text: nil) }

HTML 表单字段如下所示:
<input class="string optional" id="foo_field_id" name="foo[field_id]" type="text">

为什么会这样?

最佳答案

根据 https://github.com/jnicklas/capybara/pull/1169 ,这是因为最近的变化:

It's not possible to match against nil anymore because to_s gets called on what you pass to with.



解决方法是执行以下操作:
expect(find_field("foo_field_id").text).to be_blank

关于ruby-on-rails - 无 rspec 期望的 capybara have_field 在升级到 2.2 时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23892056/

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