puffing-billy 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +29 -16
- data/CHANGELOG.md +5 -0
- data/README.md +16 -4
- data/Rakefile +9 -0
- data/lib/billy/browsers/capybara.rb +41 -14
- data/lib/billy/browsers/watir.rb +1 -0
- data/lib/billy/config.rb +2 -1
- data/lib/billy/handlers/request_handler.rb +4 -0
- data/lib/billy/version.rb +1 -1
- data/puffing-billy.gemspec +3 -4
- data/spec/lib/billy/handlers/request_handler_spec.rb +22 -0
- data/spec/spec_helper.rb +10 -4
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6445deb6e30f295a1f15a5f4b1a094be474a587b375ecc6f23023baf0c74a9a0
|
4
|
+
data.tar.gz: b1da2a249c2d37d679f4134714ee1c33f6f6eb77fabefdb34637d1ebdf88b655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde48ead48a81d1f6b98e307aac098f3fd5357629a147fda05800120708e86f51a78433d15266e559ac856d22dd99f931e7a6c3a3ae10e158eb786b9d095381b
|
7
|
+
data.tar.gz: d4e2312af4c9a8e67c5d7316b0c9a0384d451974a78b3c9b3077d5392a492710460df32c08e4767a17f3e9e6f883e6ce98a9b81168e2e6dced1250ba6204104a
|
data/.travis.yml
CHANGED
@@ -1,23 +1,36 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
before_install:
|
4
|
-
- gem install bundler -v '< 2'
|
5
|
-
- export PHANTOMJS_VERSION='2.1.1'
|
6
|
-
- export PHANTOMJS_URL='https://github.com/Medium/phantomjs'
|
7
|
-
- export PHANTOMJS_URL+="/releases/download/v${PHANTOMJS_VERSION}"
|
8
|
-
- export PHANTOMJS_URL+="/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2"
|
9
|
-
- >
|
10
|
-
wget -q ${PHANTOMJS_URL} &&
|
11
|
-
tar xfv phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2 \
|
12
|
-
--wildcards */bin/phantomjs --strip-components=2
|
13
|
-
- export PATH="`pwd`:${PATH}"
|
14
|
-
before_script:
|
15
|
-
- phantomjs --version
|
16
|
-
- bundle --version
|
2
|
+
|
17
3
|
rvm:
|
18
4
|
- 2.3
|
19
5
|
- 2.4
|
20
6
|
- 2.5
|
21
7
|
- 2.6
|
22
|
-
|
8
|
+
|
9
|
+
cache:
|
10
|
+
bundler: true
|
11
|
+
directories:
|
12
|
+
- $HOME/.webdrivers
|
13
|
+
|
14
|
+
addons:
|
15
|
+
chrome: stable
|
16
|
+
apt:
|
17
|
+
update: true
|
18
|
+
|
19
|
+
sudo: false
|
20
|
+
dist: xenial
|
21
|
+
|
22
|
+
rvm:
|
23
|
+
- 2.3
|
24
|
+
- 2.4
|
25
|
+
- 2.5
|
26
|
+
- 2.6
|
27
|
+
|
28
|
+
matrix:
|
29
|
+
fast_finish: true
|
30
|
+
|
31
|
+
bundler_args: --jobs 3 --retry 3
|
32
|
+
|
33
|
+
before_install:
|
34
|
+
- gem update --system
|
35
|
+
- gem install bundler
|
23
36
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v2.2.0, 2019-10-26
|
2
|
+
-------------------
|
3
|
+
* Before handle request method [#273](https://github.com/oesmith/puffing-billy/pull/273)
|
4
|
+
* Add Selenium headless driver [#272](https://github.com/oesmith/puffing-billy/pull/272)
|
5
|
+
|
1
6
|
v2.1.1, 2019-06-15
|
2
7
|
-------------------
|
3
8
|
* Add driver registration for chrome headless [#267](https://github.com/oesmith/puffing-billy/pull/267)
|
data/README.md
CHANGED
@@ -55,7 +55,9 @@ require 'billy/capybara/rspec'
|
|
55
55
|
|
56
56
|
# select a driver for your chosen browser environment
|
57
57
|
Capybara.javascript_driver = :selenium_billy # Uses Firefox
|
58
|
+
# Capybara.javascript_driver = :selenium_headless_billy # Uses Firefox in headless mode
|
58
59
|
# Capybara.javascript_driver = :selenium_chrome_billy
|
60
|
+
# Capybara.javascript_driver = :selenium_chrome_headless_billy
|
59
61
|
# Capybara.javascript_driver = :apparition_billy
|
60
62
|
# Capybara.javascript_driver = :webkit_billy
|
61
63
|
# Capybara.javascript_driver = :poltergeist_billy
|
@@ -246,7 +248,8 @@ In your `rails_helper.rb`:
|
|
246
248
|
|
247
249
|
```ruby
|
248
250
|
Billy.configure do |c|
|
249
|
-
c.whitelist = ['test.host', 'localhost', '127.0.0.1']
|
251
|
+
c.whitelist = ['test.host', 'localhost', '127.0.0.1'] # To replace the default whitelist, OR
|
252
|
+
c.whitelist << 'mynewhost.local' # to append a host without overriding the defaults.
|
250
253
|
end
|
251
254
|
```
|
252
255
|
|
@@ -434,9 +437,6 @@ internally on this request, or your test ended before it could complete successf
|
|
434
437
|
|
435
438
|
`c.after_cache_handles_request` is used to configure a callback that can operate on the response after it has been retrieved from the cache but before it is returned. The callback receives the request and response as arguments, with a request object like: `{ method: method, url: url, headers: headers, body: body }`. An example usage would be manipulating the Access-Control-Allow-Origin header so that your test server doesn't always have to run on the same port in order to accept cached responses to CORS requests:
|
436
439
|
|
437
|
-
`c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
|
438
|
-
`false` to use `c.allow_params`
|
439
|
-
|
440
440
|
```
|
441
441
|
Billy.configure do |c|
|
442
442
|
...
|
@@ -454,6 +454,18 @@ Billy.configure do |c|
|
|
454
454
|
end
|
455
455
|
```
|
456
456
|
|
457
|
+
`c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
|
458
|
+
`false` to use `c.allow_params`
|
459
|
+
|
460
|
+
`c.before_handle_request` is used to modify `method`, `url`, `headers`, `body` before handle request by `stubs`, `cache` or `proxy`. Method accept 4 argumens and must return array of this arguments:
|
461
|
+
|
462
|
+
```
|
463
|
+
c.before_handle_request = proc { |method, url, headers, body|
|
464
|
+
filtered_body = JSON.dump(filter_secret_data(JSON.load(body)))
|
465
|
+
[method, url, headers, filtered_body]
|
466
|
+
}
|
467
|
+
```
|
468
|
+
|
457
469
|
`c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
|
458
470
|
|
459
471
|
`c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
|
data/Rakefile
CHANGED
@@ -47,12 +47,19 @@ module Billy
|
|
47
47
|
|
48
48
|
def self.register_selenium_driver
|
49
49
|
::Capybara.register_driver :selenium_billy do |app|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
options = build_selenium_options_for_firefox
|
51
|
+
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
52
|
+
|
53
|
+
::Capybara::Selenium::Driver.new(app, options: options, desired_capabilities: capabilities)
|
54
|
+
end
|
55
|
+
|
56
|
+
::Capybara.register_driver :selenium_headless_billy do |app|
|
57
|
+
options = build_selenium_options_for_firefox.tap do |opts|
|
58
|
+
opts.add_argument '-headless'
|
59
|
+
end
|
60
|
+
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
61
|
+
|
62
|
+
::Capybara::Selenium::Driver.new(app, options: options, desired_capabilities: capabilities)
|
56
63
|
end
|
57
64
|
|
58
65
|
::Capybara.register_driver :selenium_chrome_billy do |app|
|
@@ -60,19 +67,28 @@ module Billy
|
|
60
67
|
options.add_argument("--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}")
|
61
68
|
|
62
69
|
::Capybara::Selenium::Driver.new(
|
63
|
-
app,
|
64
|
-
|
70
|
+
app,
|
71
|
+
browser: :chrome,
|
72
|
+
options: options,
|
73
|
+
clear_local_storage: true,
|
74
|
+
clear_session_storage: true
|
65
75
|
)
|
66
76
|
end
|
67
|
-
|
77
|
+
|
68
78
|
::Capybara.register_driver :selenium_chrome_headless_billy do |app|
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
80
|
+
options.headless!
|
81
|
+
options.add_argument('--enable-features=NetworkService,NetworkServiceInProcess')
|
82
|
+
options.add_argument("--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}")
|
83
|
+
options.add_argument('--disable-gpu') if Gem.win_platform?
|
84
|
+
options.add_argument('--no-sandbox') if ENV['CI']
|
72
85
|
|
73
86
|
::Capybara::Selenium::Driver.new(
|
74
|
-
app,
|
75
|
-
|
87
|
+
app,
|
88
|
+
browser: :chrome,
|
89
|
+
options: options,
|
90
|
+
clear_local_storage: true,
|
91
|
+
clear_session_storage: true
|
76
92
|
)
|
77
93
|
end
|
78
94
|
end
|
@@ -84,6 +100,17 @@ module Billy
|
|
84
100
|
end
|
85
101
|
end
|
86
102
|
end
|
103
|
+
|
104
|
+
def self.build_selenium_options_for_firefox
|
105
|
+
profile = Selenium::WebDriver::Firefox::Profile.new.tap do |prof|
|
106
|
+
prof.assume_untrusted_certificate_issuer = false
|
107
|
+
prof.proxy = Selenium::WebDriver::Proxy.new(
|
108
|
+
http: "#{Billy.proxy.host}:#{Billy.proxy.port}",
|
109
|
+
ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}")
|
110
|
+
end
|
111
|
+
|
112
|
+
Selenium::WebDriver::Firefox::Options.new(profile: profile)
|
113
|
+
end
|
87
114
|
end
|
88
115
|
end
|
89
116
|
end
|
data/lib/billy/browsers/watir.rb
CHANGED
data/lib/billy/config.rb
CHANGED
@@ -11,7 +11,7 @@ module Billy
|
|
11
11
|
:non_whitelisted_requests_disabled, :cache_path, :certs_path, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
|
12
12
|
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :dynamic_jsonp_callback_name, :merge_cached_responses_whitelist,
|
13
13
|
:strip_query_params, :proxied_request_host, :proxied_request_port, :cache_request_body_methods, :after_cache_handles_request,
|
14
|
-
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params
|
14
|
+
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params, :before_handle_request
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
@@ -50,6 +50,7 @@ module Billy
|
|
50
50
|
@record_requests = false
|
51
51
|
@record_stub_requests = false
|
52
52
|
@use_ignore_params = true
|
53
|
+
@before_handle_request = nil
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -17,6 +17,10 @@ module Billy
|
|
17
17
|
def handle_request(method, url, headers, body)
|
18
18
|
request = request_log.record(method, url, headers, body)
|
19
19
|
|
20
|
+
if Billy.config.before_handle_request
|
21
|
+
method, url, headers, body = Billy.config.before_handle_request.call(method, url, headers, body)
|
22
|
+
end
|
23
|
+
|
20
24
|
# Process the handlers by order of importance
|
21
25
|
[:stubs, :cache, :proxy].each do |key|
|
22
26
|
if (response = handlers[key].handle_request(method, url, headers, body))
|
data/lib/billy/version.rb
CHANGED
data/puffing-billy.gemspec
CHANGED
@@ -18,18 +18,17 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency 'rspec'
|
19
19
|
gem.add_development_dependency 'thin'
|
20
20
|
gem.add_development_dependency 'faraday'
|
21
|
-
gem.add_development_dependency 'poltergeist'
|
22
21
|
gem.add_development_dependency 'apparition'
|
23
|
-
# selenium-webdriver 3.8 drops support for PhantomJS
|
24
|
-
gem.add_development_dependency 'selenium-webdriver', '<= 3.7.0'
|
25
22
|
gem.add_development_dependency 'capybara'
|
26
|
-
gem.add_development_dependency '
|
23
|
+
gem.add_development_dependency 'selenium-webdriver'
|
27
24
|
gem.add_development_dependency 'rack'
|
25
|
+
gem.add_development_dependency 'rake'
|
28
26
|
gem.add_development_dependency 'guard'
|
29
27
|
gem.add_development_dependency 'rb-inotify'
|
30
28
|
gem.add_development_dependency 'pry'
|
31
29
|
gem.add_development_dependency 'cucumber'
|
32
30
|
gem.add_development_dependency 'watir', '~> 6.10.0'
|
31
|
+
gem.add_development_dependency 'webdrivers'
|
33
32
|
gem.add_runtime_dependency 'addressable', '~> 2.5'
|
34
33
|
gem.add_runtime_dependency 'eventmachine', '~> 1.2'
|
35
34
|
gem.add_runtime_dependency 'em-synchrony'
|
@@ -128,6 +128,28 @@ describe Billy::RequestHandler do
|
|
128
128
|
allow(stub_handler).to receive(:handle_request).and_raise("Any Stub Error")
|
129
129
|
expect(subject.handle_request(*args)).to eql(error: "Any Stub Error")
|
130
130
|
end
|
131
|
+
|
132
|
+
context 'before_handle_request activated' do
|
133
|
+
before do
|
134
|
+
handle_request = proc { |method, url, headers, body|
|
135
|
+
[method, url, headers, "#{body}_modified"]
|
136
|
+
}
|
137
|
+
allow(Billy::config).to receive(:before_handle_request).and_return(handle_request)
|
138
|
+
end
|
139
|
+
|
140
|
+
after do
|
141
|
+
allow(Billy::config).to receive(:before_handle_request).and_call_original
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'modify request before handling' do
|
145
|
+
new_args = %w(get url headers body_modified)
|
146
|
+
expect(stub_handler).to receive(:handle_request).with(*new_args)
|
147
|
+
expect(cache_handler).to receive(:handle_request).with(*new_args).and_return('bar')
|
148
|
+
expect(proxy_handler).to_not receive(:handle_request)
|
149
|
+
expect(subject.handle_request(*args)).to eql 'bar'
|
150
|
+
expect(subject.requests).to eql([{status: :complete, handler: :cache, method: 'get', url: 'url', headers: 'headers', body: 'body'}])
|
151
|
+
end
|
152
|
+
end
|
131
153
|
end
|
132
154
|
|
133
155
|
describe '#stubs' do
|
data/spec/spec_helper.rb
CHANGED
@@ -6,11 +6,17 @@ require 'billy/watir/rspec'
|
|
6
6
|
require 'rack'
|
7
7
|
require 'logger'
|
8
8
|
require 'fileutils'
|
9
|
+
require 'webdrivers'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
$stdout.puts `#{::Selenium::WebDriver::Chrome::Service.driver_path.call} --version` if ENV['CI']
|
12
|
+
|
13
|
+
browser = Billy::Browsers::Watir.new :chrome
|
14
|
+
|
15
|
+
Capybara.configure do |config|
|
16
|
+
config.app = Rack::Directory.new(File.expand_path('../../examples', __FILE__))
|
17
|
+
config.server = :webrick
|
18
|
+
config.javascript_driver = :selenium_chrome_headless_billy
|
19
|
+
end
|
14
20
|
|
15
21
|
Billy.configure do |config|
|
16
22
|
config.logger = Logger.new(File.expand_path('../../log/test.log', __FILE__))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puffing-billy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olly Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: apparition
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: capybara
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -82,20 +82,6 @@ dependencies:
|
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: selenium-webdriver
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "<="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 3.7.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "<="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 3.7.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: capybara
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -109,21 +95,21 @@ dependencies:
|
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: rack
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - "
|
108
|
+
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
110
|
+
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: rake
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - ">="
|
@@ -206,6 +192,20 @@ dependencies:
|
|
206
192
|
- - "~>"
|
207
193
|
- !ruby/object:Gem::Version
|
208
194
|
version: 6.10.0
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: webdrivers
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: addressable
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|