问题
I'm trying to setup puffing-billy to work with Rails System Test. Since it uses Capybara for that, I tried all the documented Capybara solutions here, but didn't seem to get it correctly setup.
System Test generates an application_system_test_case.rb
for config stuff. Here's how it looks like:
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
And the actual test file looks like this:
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
But then when I run the tests:
NameError: undefined local variable or method 'proxy' for #<PromotionsTest:0x00007fd357450c90>
.
What am I doing wrong here?
回答1:
IIRC puffing-billy doesn't install helpers for system tests so you'll need to access the proxy via the Billy namespace
Billy.proxy.stub(...)
Also, system tests override javascript_driver',
current_driver, etc so you need to specify the driver you want to use via
driven_by`
driven_by :selenium, using: :selenium_chrome_billy
Note: I'm away from my main computer so this is all off the top of my head and may not be 100% correct but should put you on the right path.
来源:https://stackoverflow.com/questions/56854435/how-to-setup-puffing-billy-to-rails-system-test