水豚在失败时会通过

时间:2019-02-05 15:35:52

标签: ruby-on-rails testing rspec capybara

我有一个用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?时,出现在测试中的所有内容都会出现。为什么包含所有不在页面上的文本?

1 个答案:

答案 0 :(得分:0)

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

相关问题