Last active
March 4, 2021 15:19
-
-
Save senid231/1feaef76a7c4f88d02c0916796e8bc80 to your computer and use it in GitHub Desktop.
rails bug report with system test with miniproxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# gem 'rails', github: 'rails/rails', branch: 'main' | |
gem 'rails', '~> 6.0.0' | |
gem 'capybara' | |
gem 'selenium-webdriver', require: false | |
gem 'cuprite' | |
gem 'miniproxy' | |
end | |
require 'action_controller/railtie' | |
class TestApp < Rails::Application | |
config.root = __dir__ | |
config.hosts << '127.0.0.1' | |
secrets.secret_key_base = 'secret_key_base' | |
config.logger = Logger.new($stdout) | |
Rails.logger = config.logger | |
routes.draw do | |
get '/' => 'test#index' | |
end | |
end | |
class TestController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
def index | |
render plain: 'Home' | |
end | |
end | |
require 'minitest/autorun' | |
require 'rack/test' | |
require 'capybara/rails' | |
require 'capybara/minitest' | |
require 'capybara/cuprite' | |
require 'miniproxy' | |
Capybara.server = :webrick | |
Capybara.javascript_driver = :cuprite | |
Capybara.register_driver(:cuprite) do |app| | |
driver = Capybara::Cuprite::Driver.new( | |
app, | |
window_size: [1200, 800], | |
js_errors: true, | |
browser_options: { | |
'ignore-certificate-errors' => nil | |
} | |
) | |
driver.set_proxy(MiniProxy.host, MiniProxy.port) | |
driver | |
end | |
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase | |
driven_by Capybara.javascript_driver | |
end | |
class BugTest < ApplicationSystemTestCase | |
test 'visits page' do | |
MiniProxy.reset | |
MiniProxy.stub_request(method: "GET", url: /google.com.ua/, response: { | |
headers: { "Foo" => "bar" }, | |
code: 200, | |
body: "test google azaza" | |
}) | |
page.driver.browser.goto 'http://google.com.ua' | |
assert_text 'test google azaza' | |
MiniProxy.ignore_all_requests | |
MiniProxy.stop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment