通过标签将 VCR 与 Cucumber 一起使用

发布于 2024-12-15 16:31:10 字数 863 浏览 1 评论 0原文

我有一些 Cucumber 功能需要与 Google Maps Routing API 交互。我正在尝试使用 VCR 来消除这些交互。

我已经在我的功能中添加了一个 VCR 标签,如下所示:

@google_routing_api @javascript
Scenario: Creating a bus
  Given I am on the buses page
  When I follow "Get Started Now"

然后在 features/support/vcr.rb 中添加了我的 VCR 配置

require 'vcr'

VCR.config do |c|
  # INFO: This is relative to the Rails.root
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
end

# INFO: https://github.com/myronmarston/vcr/wiki/Usage-with-Cucumber
VCR.cucumber_tags do |t|
  t.tag '@google_routing_api'
end

但是当我运行我的 cukes 时,我被告知..

Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:54181/__identify__

I have some Cucumber features which need to interact with the Google Maps Routing API. I'm trying to stub out these interactions using VCR.

I have added a VCR tag to my features like so:

@google_routing_api @javascript
Scenario: Creating a bus
  Given I am on the buses page
  When I follow "Get Started Now"

And then added my VCR configuration in features/support/vcr.rb

require 'vcr'

VCR.config do |c|
  # INFO: This is relative to the Rails.root
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
end

# INFO: https://github.com/myronmarston/vcr/wiki/Usage-with-Cucumber
VCR.cucumber_tags do |t|
  t.tag '@google_routing_api'
end

But when I run my cukes, I am told..

Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:54181/__identify__

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

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

发布评论

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

评论(1

丑丑阿 2024-12-22 16:31:10

您必须将 VCR 设置为忽略本地主机请求。否则,当水豚尝试从您的网站请求任何页面时,VCR 将阻止它。

c.ignore_localhost = true 添加到您的 VCR 配置块中。

VCR.config do |c|
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
  c.ignore_localhost = true
end

You have to set VCR to ignore localhost requests. Otherwise, when capybara tries to request any page from your website, VCR will block it.

Add c.ignore_localhost = true to your VCR config block.

VCR.config do |c|
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
  c.ignore_localhost = true
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文