puffing-billy 3.0.1 → 3.0.4

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
2
  SHA256:
3
- metadata.gz: ec02ea3b7f01e33d68df684db911886bacb0b9c92f1fbe3d9931df42218dd78f
4
- data.tar.gz: 9ea280821375f4ba83429c33aa2d17035a3269e580fbb52c6a26e5db968eed25
3
+ metadata.gz: 16bed8180bba7ace31cc3516c9b30bddbce8531cfe5f4a1effd93572219f2952
4
+ data.tar.gz: d47667758e923263a1e98e2bb60c6ab1bf3962fa38722259addc4e59b4af129e
5
5
  SHA512:
6
- metadata.gz: 9b1680023f9b58ee65995bc91471d11f4d1a9fd96dbee00a9635edb23775bbe2824b3234414c5d87aa33709a10b8c71729079bb0bd885db7023958aa4da77859
7
- data.tar.gz: f42c4227325d9dcab48a50eed2f5470db36c90e5fc8aff2618cfd37531fe15e23345b7bff92080053a130b0e9755a8f43c46cdf958d45ece795e8cd4ac7e7c51
6
+ metadata.gz: e7a47d5b299bb1b5ba9b6979317e383b498116cabfb6cf8bc924c75b0a2fd97684beafac596ee728b7c393b74f92229090b13fba5a06140846992c7234a50f4f
7
+ data.tar.gz: b7bb0f1fb51747f935c26fc3c4c455900c5a0971676ce4bba1ee8ddfe87740f7e5771ed529b22735687f15ad423da436dc8f7fd940e7179fb4d62e609641d669
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ v3.0.4, 2022-08-07
2
+ ------------------
3
+ * Adds a configurable Cuprite driver [#327](https://github.com/oesmith/puffing-billy/pull/327)
4
+
5
+ v3.0.3, 2022-05-31
6
+ -------------------
7
+ * Only calculate cache scope and key if request is cacheable [#324](https://github.com/oesmith/puffing-billy/pull/324)
8
+
9
+ v3.0.2, 2022-02-16
10
+ -------------------
11
+ * Add rake tasks inside files DSL in gemspec [#321](https://github.com/oesmith/puffing-billy/pull/321)
12
+
1
13
  v3.0.1, 2022-02-15
2
14
  -------------------
3
15
  * Adapt to newer versions selenium webdriver [#314](https://github.com/oesmith/puffing-billy/pull/314)
data/README.md CHANGED
@@ -65,6 +65,7 @@ Capybara.javascript_driver = :selenium_billy # Uses Firefox
65
65
  # Capybara.javascript_driver = :apparition_billy
66
66
  # Capybara.javascript_driver = :webkit_billy
67
67
  # Capybara.javascript_driver = :poltergeist_billy
68
+ # Capybara.javascript_driver = :cuprite_billy
68
69
  ```
69
70
 
70
71
  > __Note__: `:poltergeist_billy` doesn't support proxying any localhosts, so you must use
@@ -154,6 +155,20 @@ And /^a stub for google$/ do
154
155
  end
155
156
  ```
156
157
 
158
+ ### Setup remote Chrome
159
+
160
+ In the case you are using a Chrome instance, running on another machine, or in
161
+ another Docker container, you need to :
162
+ * Fix the Billy proxy host and port
163
+ * Passes the `--proxy-server=<billy host>:<billy port>`
164
+
165
+ #### WebSockets
166
+
167
+ Puffing billy doesn't support websockets, so if you are using them,
168
+ or ActionCable for the Ruby On Rails developers, you can tell Chrome to bypass
169
+ the proxy for websockets by adding the flag `--proxy-bypass-list=ws://*` to
170
+ your remote chrome intance or Docker container.
171
+
157
172
  ## Minitest Usage
158
173
 
159
174
  Please see [this link](https://gist.github.com/sauy7/1b081266dd453a1b737b) for
@@ -8,7 +8,8 @@ module Billy
8
8
  poltergeist: 'capybara/poltergeist',
9
9
  webkit: 'capybara/webkit',
10
10
  selenium: 'selenium/webdriver',
11
- apparition: 'capybara/apparition'
11
+ apparition: 'capybara/apparition',
12
+ cuprite: 'capybara/cuprite'
12
13
  }
13
14
 
14
15
  def self.register_drivers
@@ -108,6 +109,20 @@ module Billy
108
109
  end
109
110
  end
110
111
 
112
+ def self.register_cuprite_driver
113
+ driver_otions = {
114
+ browser_options: {
115
+ 'ignore-certificate-errors' => nil
116
+ }
117
+ }.deep_merge(Billy.config.cuprite_options)
118
+
119
+ ::Capybara.register_driver :cuprite_billy do |app|
120
+ ::Capybara::Cuprite::Driver.new(app, **driver_otions).tap do |driver|
121
+ driver.set_proxy(Billy.proxy.host, Billy.proxy.port)
122
+ end
123
+ end
124
+ end
125
+
111
126
  def self.build_selenium_options_for_firefox
112
127
  profile = Selenium::WebDriver::Firefox::Profile.new.tap do |prof|
113
128
  prof.proxy = Selenium::WebDriver::Proxy.new(
data/lib/billy/cache.rb CHANGED
@@ -15,6 +15,8 @@ module Billy
15
15
  end
16
16
 
17
17
  def cached?(method, url, body)
18
+ return false unless Billy.config.cache
19
+
18
20
  # Only log the key the first time it's looked up (in this method)
19
21
  key = key(method, url, body, true)
20
22
  !@cache[key].nil? || persisted?(key)
data/lib/billy/config.rb CHANGED
@@ -11,7 +11,8 @@ module Billy
11
11
  :non_whitelisted_requests_disabled, :cache_path, :certs_path, :verify_peer, :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, :before_handle_request
14
+ :cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_requests, :record_stub_requests, :use_ignore_params,
15
+ :before_handle_request, :cuprite_options
15
16
 
16
17
  def initialize
17
18
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -53,6 +54,7 @@ module Billy
53
54
  @record_stub_requests = false
54
55
  @use_ignore_params = true
55
56
  @before_handle_request = nil
57
+ @cuprite_options = {}
56
58
  end
57
59
  end
58
60
 
@@ -25,9 +25,6 @@ module Billy
25
25
  port: Billy.config.proxied_request_port }} )
26
26
  end
27
27
 
28
- cache_scope = Billy::Cache.instance.scope
29
- cache_key = Billy::Cache.instance.key(method.downcase, url, body)
30
-
31
28
  req = EventMachine::HttpRequest.new(url, opts)
32
29
  req = req.send(method.downcase, build_request_options(url, headers, body))
33
30
 
@@ -47,6 +44,9 @@ module Billy
47
44
  end
48
45
 
49
46
  if cacheable?(url, response[:headers], response[:status])
47
+ cache_scope = Billy::Cache.instance.scope
48
+ cache_key = Billy::Cache.instance.key(method.downcase, url, body)
49
+
50
50
  Billy::Cache.instance.store(
51
51
  cache_key,
52
52
  cache_scope,
data/lib/billy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Billy
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.4'
3
3
  end
@@ -0,0 +1,87 @@
1
+ require 'addressable/uri'
2
+
3
+ namespace :cache do
4
+ desc 'Print out all cache file information'
5
+ task :print_all do
6
+ cache_array = load_cache
7
+
8
+ sort_cache(cache_array).each do |cache|
9
+ print_cache_details(cache)
10
+ end
11
+ end
12
+
13
+ desc 'Print out specific cache file information'
14
+ task :print_details, :sha do |_t, args|
15
+ fail "Missing sha; usage: rake cache:print_details['<sha>']" unless args[:sha]
16
+ cache_array = load_cache(Billy.config.cache_path, '*' + args[:sha] + '*.yml')
17
+
18
+ sort_cache(cache_array).each do |cache|
19
+ print_cache_details(cache)
20
+ end
21
+ end
22
+
23
+ desc 'Find specific cache files by URL'
24
+ task :find_by_url, :api_path do |_t, args|
25
+ fail "Missing api path; usage: rake cache:find_by_url['<api_path>']" unless args[:api_path]
26
+ cache_array = load_cache
27
+ filtered_cache_array = cache_array.select { |f| f[:url_path].include?(args[:api_path]) }
28
+
29
+ sort_cache(filtered_cache_array).each do |cache|
30
+ print_cache_details(cache)
31
+ end
32
+ end
33
+
34
+ desc 'Find specific cache files by scope'
35
+ task :find_by_scope, :scope do |_t, args|
36
+ fail "Missing scope; usage: rake cache:find_by_scope['<scope>']" unless args[:scope]
37
+ cache_array = load_cache
38
+ filtered_cache_array = cache_array.select { |f| f[:scope] && f[:scope].include?(args[:scope]) }
39
+
40
+ sort_cache(filtered_cache_array).each do |cache|
41
+ print_cache_details(cache)
42
+ end
43
+ end
44
+
45
+ desc 'Find cache files with non-successful status codes'
46
+ task :find_non_successful do
47
+ cache_array = load_cache
48
+ filtered_cache_array = cache_array.select { |f| !(200..299).include?(f[:status]) }
49
+
50
+ sort_cache(filtered_cache_array).each do |cache|
51
+ print_cache_details(cache)
52
+ end
53
+ end
54
+
55
+ def load_cache(cache_directory = Billy.config.cache_path, file_pattern = '*.yml')
56
+ cache_path = Rails.root.join(cache_directory)
57
+ cache_array = []
58
+
59
+ Dir.glob(cache_path + file_pattern) do |filename|
60
+ data = load_cache_file(filename)
61
+ url = Addressable::URI.parse(data[:url])
62
+ data[:url_path] = "#{url.path}#{url.query ? '?' + url.query : ''}#{url.fragment ? '#' + url.fragment : ''}"
63
+ data[:filename] = filename.gsub(Rails.root.to_s + '/', '')
64
+ cache_array << data
65
+ end
66
+ cache_array
67
+ end
68
+
69
+ def load_cache_file(filename)
70
+ YAML.load_file(filename)
71
+ rescue ArgumentError => e
72
+ puts "Could not parse YAML: #{e.message}"
73
+ end
74
+
75
+ def print_cache_details(cache)
76
+ puts " Scope: #{cache[:scope]}" if cache[:scope]
77
+ puts " URL: #{cache[:url]}"
78
+ puts " Body: #{cache[:body]}" if Billy.config.cache_request_body_methods.include?(cache[:method])
79
+ puts " Details: Request method '#{cache[:method]}' returned response status code: '#{cache[:status]}'"
80
+ puts "Filename: #{cache[:filename]}"
81
+ puts "\n\n"
82
+ end
83
+
84
+ def sort_cache(cache, key = :url_path)
85
+ cache.sort_by { |hsh| hsh[key] }
86
+ end
87
+ end
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: 3.0.1
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olly Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-15 00:00:00.000000000 Z
11
+ date: 2022-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -366,6 +366,7 @@ files:
366
366
  - lib/billy/watir/rspec.rb
367
367
  - lib/puffing-billy.rb
368
368
  - lib/puffing-billy/rspec.rb
369
+ - lib/tasks/billy.rake
369
370
  homepage: https://github.com/oesmith/puffing-billy
370
371
  licenses:
371
372
  - MIT