have_content 和 have_selector 不适用于 Capybara 和 Minitest

have_content and have_selector don't work with Capybara and Minitest

我最近从 RSpec 切换到 Minitest。我的模型测试都 运行 很棒。但是,我的集成测试不再有效。

None 我对 have_contenthave_selector 的调用正在工作。

我在我的 test_helper.rb 文件中包含了 Capybara::DSL 如下:

class ActionDispatch::IntegrationTest
  include Rails.application.routes.url_helpers # for x_path and x_url helpers
  include Capybara::DSL
  include PossibleJSDriver # switching Capybara driver for javascript tests

  def setup
  end

end

这是测试中有问题的行:

page.should have_selector('ul.ui-autocomplete li.ui-menu-item a')

和错误:

NoMethodError: undefined method `have_selector' for #<AppIntegrationTest:0x007f95f103afc8> 

我不明白为什么这些不再起作用了。我正在使用 minitest-rails-capybara gem.

Minitest 中的语法不同。改用这个:

page.must_have_selector('ul.ui-autocomplete li.ui-menu-item a')