capybara-webmock 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: db388c98471efbe6d26acf80ee96b4804e310b59
4
- data.tar.gz: 4bdc44c1f858fd1ae57784db6fa92966420269a4
2
+ SHA256:
3
+ metadata.gz: 28f4ebed6063f94e18d058d63223bd1c9fd437241e622cee85f38597122aca2b
4
+ data.tar.gz: debbbb2e0c9d47f31930781dc38e19b0dbd4bea58424b3325a25dd8d119c3e48
5
5
  SHA512:
6
- metadata.gz: fc39f134851122d660ba26701d6c46a4bf958951dbbfde066119755ce6be750113d539883b917e5e00bde876ed952bb4604daa026b0e2371e0de67b5a35399be
7
- data.tar.gz: 8cdaf05aa300e8b91a13ba7b6033a1a09ad087a90adf22d23364bed93870e9aea4c751b4488e2032cb78ba01d59af374a4db90e7f97c175e1353a56b1e933b93
6
+ metadata.gz: 6f2a033ab751fd97ff1b8798ab87264625191a361619f6b70d9ef6e7323dd739cc0ca95401de958d821cd1511b7aa996060d7713ad7e7eb0f01d60b6e25f4dbb
7
+ data.tar.gz: f6e373337fee16aef5c716c9648103651905ca1e3996e67051f183b8f1c686de903be936b8dc5f627490ff935162bbd7efac0601b7df156ad1de4c01acc2d2e3
@@ -0,0 +1,25 @@
1
+ name: Run tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest, macos-latest]
11
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
12
+ ruby: [2.5, 2.6, 2.7, '3.0', head]
13
+ runs-on: ${{ matrix.os }}
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: nanasess/setup-chromedriver@master
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
21
+ - run: |
22
+ export DISPLAY=":99"
23
+ chromedriver --url-base=/wd/hub &
24
+ sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
25
+ bundle exec rake
data/README.md CHANGED
@@ -81,6 +81,8 @@ or:
81
81
  ```ruby
82
82
  # Use Chrome Driver
83
83
  Capybara.javascript_driver = :capybara_webmock_chrome
84
+ # or Chrome Driver in headless mode
85
+ Capybara.javascript_driver = :capybara_webmock_chrome_headless
84
86
  ```
85
87
 
86
88
  ```ruby
@@ -88,7 +90,7 @@ Capybara.javascript_driver = :capybara_webmock_chrome
88
90
  Capybara.javascript_driver = :capybara_webmock_poltergeist
89
91
  ```
90
92
 
91
- *NOTE: These are just two default driver wrappers this gem provides. If you are
93
+ *NOTE: These are just some default driver wrappers this gem provides. If you are
92
94
  already using a custom driver profile you can still use `capybara-webmock`, you
93
95
  just need to configure proxy settings to `127.0.0.1:9292`*
94
96
 
@@ -108,6 +110,13 @@ it 'makes a request to /somewhere when the user visits the page' do
108
110
  end
109
111
  ```
110
112
 
113
+ You can provide extra hosts to be permitted past the proxy, but should be used carefully.
114
+ This setting does not remove the default localhosts, but adds to them.
115
+
116
+ ```ruby
117
+ Capybara::Webmock.allowed_hosts = ["example.com", "sub.example.com"]
118
+ ```
119
+
111
120
  ### Development
112
121
 
113
122
  After pulling down the repo, install dependencies:
@@ -26,8 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "rack", ">= 1.4"
27
27
  spec.add_dependency "rack-proxy", ">= 0.6.0"
28
28
  spec.add_dependency "selenium-webdriver", "~> 3.0"
29
+ spec.add_dependency "rexml", ">= 3.2"
30
+ spec.add_dependency "webrick", ">= 1.7"
29
31
 
30
- spec.add_development_dependency "bundler", "~> 1.13"
32
+ spec.add_development_dependency "bundler", ">= 1.13"
31
33
  spec.add_development_dependency "pry", "~> 0.10.4"
32
34
  spec.add_development_dependency "rake", "~> 10.0"
33
35
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -9,15 +9,21 @@ require 'capybara/webmock/proxied_request'
9
9
 
10
10
  module Capybara
11
11
  module Webmock
12
+ SEPARATOR = "|"
13
+
12
14
  class << self
13
- attr_accessor :port_number, :pid_file, :kill_timeout, :start_timeout
15
+ attr_accessor :port_number, :pid_file, :kill_timeout, :start_timeout, :allowed_hosts
14
16
 
15
17
  def start
16
18
  if @pid.nil?
17
19
  kill_old_process
18
20
  gem_path = File.dirname(__FILE__)
19
21
  proxy_file = File.join(gem_path, 'webmock', 'config.ru')
20
- stdin, stdout, wait_thr = Open3.popen2e({ "PROXY_PORT_NUMBER" => port_number.to_s }, "rackup", proxy_file)
22
+ env_config = {
23
+ "CAPYBARA_WEBMOCK_PROXY_PORT_NUMBER" => port_number.to_s,
24
+ "CAPYBARA_WEBMOCK_ADDED_HOSTS" => allowed_hosts.to_a.join(SEPARATOR)
25
+ }
26
+ stdin, stdout, wait_thr = Open3.popen2e(env_config, "rackup", proxy_file)
21
27
  stdin.close
22
28
  @stdout = stdout
23
29
  @pid = wait_thr[:pid]
@@ -68,7 +74,13 @@ module Capybara
68
74
  end
69
75
 
70
76
  def chrome_options
71
- {args: [ "--proxy-server=127.0.0.1:#{port_number}" ]}
77
+ ::Selenium::WebDriver::Chrome::Options.new.tap do |options|
78
+ options.add_argument "--proxy-server=127.0.0.1:#{port_number}"
79
+ end
80
+ end
81
+
82
+ def chrome_headless_options
83
+ chrome_options.tap { |options| options.headless! }
72
84
  end
73
85
 
74
86
  def phantomjs_options
@@ -162,9 +174,11 @@ Capybara.register_driver :capybara_webmock do |app|
162
174
  end
163
175
 
164
176
  Capybara.register_driver :capybara_webmock_chrome do |app|
165
- Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: {
166
- chromeOptions: Capybara::Webmock.chrome_options
167
- })
177
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: Capybara::Webmock.chrome_options)
178
+ end
179
+
180
+ Capybara.register_driver :capybara_webmock_chrome_headless do |app|
181
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: Capybara::Webmock.chrome_headless_options)
168
182
  end
169
183
 
170
184
  Capybara.register_driver :capybara_webmock_poltergeist do |app|
@@ -2,4 +2,4 @@ require 'rack'
2
2
  require 'capybara/webmock/proxy'
3
3
 
4
4
  app = Capybara::Webmock::Proxy.new(Process.pid)
5
- Rack::Handler::WEBrick.run(app, Port: ENV.fetch('PROXY_PORT_NUMBER', 9292))
5
+ Rack::Handler::WEBrick.run(app, Port: ENV.fetch('CAPYBARA_WEBMOCK_PROXY_PORT_NUMBER', 9292))
@@ -1,25 +1,19 @@
1
+ require 'forwardable'
1
2
  require 'uri'
2
3
 
3
4
  module Capybara
4
5
  module Webmock
5
6
  class ProxiedRequest
7
+ extend Forwardable
8
+
6
9
  attr_reader :referrer, :uri
7
10
 
11
+ def_delegators :uri, :fragment, :host, :hostname, :password, :path, :port, :query, :scheme, :user, :userinfo
12
+
8
13
  def initialize(raw_referrer, raw_uri)
9
14
  @referrer = raw_referrer == "-" ? nil : URI.parse(raw_referrer)
10
15
  @uri = URI.parse(raw_uri)
11
16
  end
12
-
13
- def fragment; @uri.fragment; end
14
- def host; @uri.host; end
15
- def hostname; @uri.hostname; end
16
- def password; @uri.password; end
17
- def path; @uri.path; end
18
- def port; @uri.port; end
19
- def query; @uri.query; end
20
- def scheme; @uri.scheme; end
21
- def user; @uri.user; end
22
- def userinfo; @uri.userinfo; end
23
17
  end
24
18
  end
25
19
  end
@@ -2,7 +2,7 @@ require 'rack/proxy'
2
2
  require 'capybara/webmock'
3
3
 
4
4
  class Capybara::Webmock::Proxy < Rack::Proxy
5
- ALLOWED_HOSTS = allowed_hosts = ['127.0.0.1', 'localhost', /(.*\.|\A)lvh.me/]
5
+ DEFAULT_ALLOWED_HOSTS = ['127.0.0.1', 'localhost', /(.*\.|\A)lvh.me/]
6
6
 
7
7
  def call(env)
8
8
  @streaming = true
@@ -27,8 +27,12 @@ class Capybara::Webmock::Proxy < Rack::Proxy
27
27
 
28
28
  private
29
29
 
30
+ def allowed_hosts
31
+ DEFAULT_ALLOWED_HOSTS + ENV.fetch('CAPYBARA_WEBMOCK_ADDED_HOSTS', "").split(Capybara::Webmock::SEPARATOR)
32
+ end
33
+
30
34
  def allowed_host?(host)
31
- ALLOWED_HOSTS.any? do |allowed_host|
35
+ allowed_hosts.any? do |allowed_host|
32
36
  case allowed_host
33
37
  when Regexp
34
38
  allowed_host =~ host
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Webmock
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Worth
8
8
  - Dillon Hafer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-12 00:00:00.000000000 Z
12
+ date: 2021-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -73,18 +73,46 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: rexml
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ - !ruby/object:Gem::Dependency
91
+ name: webrick
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '1.7'
76
104
  - !ruby/object:Gem::Dependency
77
105
  name: bundler
78
106
  requirement: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - "~>"
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '1.13'
83
111
  type: :development
84
112
  prerelease: false
85
113
  version_requirements: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
117
  version: '1.13'
90
118
  - !ruby/object:Gem::Dependency
@@ -178,7 +206,7 @@ executables: []
178
206
  extensions: []
179
207
  extra_rdoc_files: []
180
208
  files:
181
- - ".circleci/config.yml"
209
+ - ".github/workflows/run-tests.yml"
182
210
  - ".gitignore"
183
211
  - ".rspec"
184
212
  - CODE_OF_CONDUCT.md
@@ -198,7 +226,7 @@ homepage: https://github.com/hashrocket/capybara-webmock
198
226
  licenses:
199
227
  - MIT
200
228
  metadata: {}
201
- post_install_message:
229
+ post_install_message:
202
230
  rdoc_options: []
203
231
  require_paths:
204
232
  - lib
@@ -213,9 +241,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
241
  - !ruby/object:Gem::Version
214
242
  version: '0'
215
243
  requirements: []
216
- rubyforge_project:
217
- rubygems_version: 2.6.12
218
- signing_key:
244
+ rubygems_version: 3.2.3
245
+ signing_key:
219
246
  specification_version: 4
220
247
  summary: Mock external requests
221
248
  test_files: []
data/.circleci/config.yml DELETED
@@ -1,9 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.5.1
6
- steps:
7
- - checkout
8
- - run: bundle install
9
- - run: rake