【问题标题】:How to setup puffing-billy to Rails System Test如何设置 puffing-billy 到 Rails 系统测试
【发布时间】:2019-07-02 14:12:30
【问题描述】:

我正在尝试设置 puffing-billy 以使用 Rails 系统测试。因为它使用 Capybara,所以我在这里尝试了所有记录在案的 Capybara 解决方案,但似乎没有正确设置。

系统测试为配置内容生成application_system_test_case.rb。下面是它的样子:

require "test_helper"
require 'billy'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]

  Capybara.javascript_driver = :selenium_chrome_billy
  Capybara.current_driver = Capybara.javascript_driver

  WebMock.allow_net_connect!
end

实际的测试文件是这样的:

require "application_system_test_case"

class PromotionsTest < ApplicationSystemTestCase
  include ApplicationHelper

  make_my_diffs_pretty!
  Capybara.default_max_wait_time = 3
  Capybara.configure do |config|
    config.app_host = "http://dev.myapp.com"
  end

  test 'Stub test' do
    proxy.stub('http://www.google.com/').and_return(:text => "I'm not Google!")

    visit 'http://www.google.com/'
  end
end

但是当我运行测试时: NameError: undefined local variable or method 'proxy' for #&lt;PromotionsTest:0x00007fd357450c90&gt;.

我在这里做错了什么?

【问题讨论】:

    标签: ruby-on-rails mocking system-testing


    【解决方案1】:

    IIRC puffing-billy 不会为系统测试安装帮助程序,因此您需要通过 Billy 命名空间访问代理

    Billy.proxy.stub(...)
    

    此外,系统测试会覆盖javascript_driver',current_driver, etc so you need to specify the driver you want to use viadriven_by`

    driven_by :selenium, using: :selenium_chrome_billy
    

    注意:我不在我的主计算机旁,所以这一切都在我的脑海中,可能不是 100% 正确,但应该会让你走上正确的道路。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      相关资源
      最近更新 更多