【问题标题】:Capybara have_text Passes When It Should FailCapybara have_text 在它应该失败时通过
【发布时间】:2019-02-05 15:35:52
【问题描述】:

我有一个用 RSpec 和 Capybara 编写的测试不应该通过,但是它是:

it 'should have the given text' do
  visit root_path
  expect(page).to have_text("This is not here")
end

然后我将其包含在测试中以查找问题:

puts page.text

它返回的文本比页面上的多得多,其中包括:

Extracted source (around line #12):
10 11 12 13
})
visit root_path
expect(page).to have_text("This is not here")

看起来我在测试中输入的任何内容都会在调用has_text? 时出现。为什么它包含所有不在页面上的文本?

【问题讨论】:

    标签: ruby-on-rails testing rspec capybara


    【解决方案1】:

    这是因为您的应用程序/代码中有错误,并且 gem 将错误和周围的代码呈现到在测试模式下启用的返回页面。您想在测试模式下禁用所有这些类型的 gem(better_errors 等)(因此它更接近生产模式)。您可以通过将它们移动到 Gemfile 中的仅开发组来做到这一点。您也可以查看test.log 以查看引发了什么错误。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-07
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      相关资源
      最近更新 更多