可选择将 capybara-webkit 与 RSpec 结合使用

发布于 2024-12-21 00:31:36 字数 639 浏览 3 评论 0原文

我更喜欢使用 capybara-webkit 作为与 capybara 一起使用的驱动程序,但不要指望我团队中的其他开发人员会跳过安装 QT 的障碍来执行相同的操作。我想从 gemfile 中删除 capybara-webkit 并仅在需要时将其用作测试驱动程序。我尝试在我的spec_helper.rb 文件中使用以下代码来执行此操作:

begin
  require 'capybara-webkit'
  driver = :webkit
  puts "capybara-webkit has been detected."
rescue LoadError
  driver = :selenium
  puts "capybara-webkit unavailable. Falling back to Selenium"
  puts "For faster, headless integration tests, install capybara-webkit"
end

Capybara.javascript_driver = driver

问题是,即使安装了 capybara-webkit,要求也会失败。我只能假设这是因为它不在我的应用程序包中。我该如何解决这个问题?有没有一种方法可以解决这个问题,不需要将 capybara-webkit 添加到 Gemfile 中?

I prefer to use capybara-webkit as the driver used with capybara, but don't expect other developers on my team to jump through the hoop of having QT installed in order to do the same. I'd like to remove capybara-webkit from the gemfile and only use it as the test driver when it can be required. I tried to do this with the following code in my spec_helper.rb file:

begin
  require 'capybara-webkit'
  driver = :webkit
  puts "capybara-webkit has been detected."
rescue LoadError
  driver = :selenium
  puts "capybara-webkit unavailable. Falling back to Selenium"
  puts "For faster, headless integration tests, install capybara-webkit"
end

Capybara.javascript_driver = driver

The problem is that even with capybara-webkit installed, the require fails. I can only assume this is because it's not in my application's bundle. How can I get around this? Is there a way to get around this that doesn't require capybara-webkit to be added to the Gemfile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞取 2024-12-28 00:31:36

与其执行 require 检查,不如检查应该存在的另一个组件怎么样?超出 Ruby 范围的东西。您需要执行此操作,因为该 gem 在捆绑包中不可用。

Rather than performing a require check, how about checking for another component that should be there instead? Something outside the scope of Ruby. You'd need to do this because of the gem being unavailable in the bundle.

背叛残局 2024-12-28 00:31:36

我认为您只想向 Gemfile 添加一个自定义组并将 capybara-webkit 放在那里。然后其他开发人员可以安装该捆绑包,但排除该组。

I think you'd just want to add a custom group to the Gemfile and put capybara-webkit there. Other developers can then install the bundle, but exclude that group.

我乃一代侩神 2024-12-28 00:31:36

我也喜欢使用两者,一般来说,webkit 更快,但有时我喜欢看到浏览器做一些事情(比如当我不知道发生了什么,或者向客户展示时)我的解决方案是安装两者通过gemfile,并在你的spec_helper.rb中设置它,

Capybara.javascript_driver = :webkit unless ENV['SHOWJS']

这将我的默认设置为无头驱动程序,当我想在selenium中看到它时,我可以运行这个命令:

SHOWJS=1 rspec spec/features/user/new_spec.rb

如果你使用guard或其他东西,你可能必须导出环境变量,因为我不认为你可以直接传递进去。

I like to use both as well, in general, webkit is faster, but sometimes I like to see the browser doing stuff(like when I have no idea what is happening, or to show to a client) my resolution is to have both installed via the gemfile, and set this in your spec_helper.rb

Capybara.javascript_driver = :webkit unless ENV['SHOWJS']

This leaves my default to the headless driver, and when I want to see it in selenium I can run this command:

SHOWJS=1 rspec spec/features/user/new_spec.rb

If you use guard or something, you might have to export the environment variable because I don't think you can just pass it in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文