【问题标题】:Automatic js: true on rspec system specs?自动 js:在 rspec 系统规范上是真的吗?
【发布时间】:2021-12-29 07:08:05
【问题描述】:

我所有的系统测试/规范都有js: true,有没有办法自动将该标签/元数据添加到我的系统测试/规范中?

require "rails_helper"

RSpec.describe "redirect_to", js: true do
  ...
end

编辑:嗯,我依赖 js: true 作为 database_cleaner,但用 type: :system 替换它,现在我不需要这个 hack

【问题讨论】:

    标签: ruby-on-rails rspec capybara


    【解决方案1】:
    config.before(:each, type: :system) { |example| example.metadata[:js] = true }
    

    【讨论】:

      【解决方案2】:

      您应该能够将默认驱动程序设置为 selenium、selenium_chrome 或任何其他自定义驱动程序:https://github.com/teamcapybara/capybara#selecting-the-driver

      类似:

      # spec/rails_helper.rb
      
      Capybara.default_driver = :selenium_chrome_headless
      

      【讨论】:

      • 我已经这样做了:driven_by :selenium_chrome_headless
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 2020-04-06
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      相关资源
      最近更新 更多