puffing-billy 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5097ebc685dd2798f2c9e7dbfed3b3582c790b77fc07f94623700c077e143ce7
4
- data.tar.gz: c30e447c5ed810078fd484151d0c7e3f58f081ec1fe08e093ce3b9f626894a9b
3
+ metadata.gz: d6e9bb7a75fe76a33e705c89f01e30fa987d1df3f4cfee135bb53393f28a4398
4
+ data.tar.gz: 47e189ad311796a8a192479fc60034d2651f1879d8e17c42afb174f6296a491f
5
5
  SHA512:
6
- metadata.gz: 80c4f30830aeeaccb1da191d4035ff98149bb297410c9d5717aa9214b879cb314bcea019fe1124cd62a111224c8e6602e0cd8cce3a2e3b337e238a16dc50f0d7
7
- data.tar.gz: 237e7116829180c69d2263ae2cfd02f28c23a4e72f414b0a298f307047798dbb86c591a9cd01c10f0b1aec6d80d43caaae5c93ba8408efd4d3644120b4bbcfaf
6
+ metadata.gz: 21e38be3cbfe954494685117ec5828cc989b9d2997170f33bfe08e2259bfdaec52e3468e7483db6a8883f5505b06dd7b7a5c1d8ccfe81447ab866d5da94ef323
7
+ data.tar.gz: 8fc3ba732c1ab60daa5599c0eb77e3c02d4a5a083b43941680e2798898ae6b11addd0f0060de6aa5cabb1c7f5cd2b598ca5d485fe6019da0e5ca12549a46037c
@@ -1,3 +1,8 @@
1
+ v2.1.0, 2019-03-17
2
+ -------------------
3
+ * Allow stubbing all request methods [#263](https://github.com/oesmith/puffing-billy/pull/263)
4
+ * Accept all encodings [#265](https://github.com/oesmith/puffing-billy/pull/265)
5
+
1
6
  v2.0.0, 2019-01-30
2
7
  -------------------
3
8
  * Add driver registration for apparition driver [#258](https://github.com/oesmith/puffing-billy/pull/258)
data/README.md CHANGED
@@ -118,8 +118,9 @@ proxy.stub('https://example.com/proc/').and_return(Proc.new { |params, headers,
118
118
  # a Proc and use the pass_request method. You can manipulate the request
119
119
  # (headers, URL, HTTP method, etc) and also the response from the upstream
120
120
  # server. The scope of the delivered callable is the user scope where
121
- # it was defined.
122
- proxy.stub('http://example.com/').and_return(Proc.new { |*args|
121
+ # it was defined. Setting method to 'all' will intercept requests regardless of
122
+ # the method.
123
+ proxy.stub('http://example.com/', method => 'all').and_return(Proc.new { |*args|
123
124
  response = Billy.pass_request(*args)
124
125
  response[:headers]['Content-Type'] = 'text/plain'
125
126
  response[:body] = 'Hello World!'
@@ -519,10 +520,11 @@ RSpec.configure do |config|
519
520
  end
520
521
  ```
521
522
 
522
- ## Separate Cache Directory for Each Test (in Cucumber)
523
-
524
- If you want the cache for each test to be independent, i.e. have it's own directory where the cache files are stored, you can use a Before tag like so:
523
+ ## Separate Cache Directory for Each Test
524
+ If you want the cache for each test to be independent, i.e. have it's own directory where the cache files are stored, you can do so.
525
525
 
526
+ ### in Cucumber
527
+ use a Before tag:
526
528
  ```rb
527
529
  Before('@javascript') do |scenario, block|
528
530
  Billy.configure do |c|
@@ -534,6 +536,29 @@ Before('@javascript') do |scenario, block|
534
536
  end
535
537
  ```
536
538
 
539
+ ### in Rspec
540
+ use a before(:each) block:
541
+ ```rb
542
+ RSpec.configure do |config|
543
+ base_cache_path = Billy.config.cache_path
544
+ base_certs_path = Billy.config.certs_path
545
+ config.before :each do |x|
546
+ feature_name = x.metadata[:example_group][:description].underscore.gsub(' ', '_')
547
+ scenario_name = x.metadata[:description].underscore.gsub(' ', '_')
548
+ Billy.configure do |c|
549
+ cache_scenario_folder_path = "#{base_cache_path}/#{feature_name}/#{scenario_name}/"
550
+ FileUtils.mkdir_p(cache_scenario_folder_path) unless File.exist?(cache_scenario_folder_path)
551
+ c.cache_path = cache_scenario_folder_path
552
+
553
+ certs_scenario_folder_path = "#{base_certs_path}/#{feature_name}/#{scenario_name}/"
554
+ FileUtils.mkdir_p(certs_scenario_folder_path) unless File.exist?(certs_scenario_folder_path)
555
+ c.certs_path = certs_scenario_folder_path
556
+ end
557
+ end
558
+ end
559
+ ```
560
+
561
+
537
562
  ## Stub requests recording
538
563
 
539
564
  If you want to record requests to stubbed URIs, set the following configuration option:
@@ -67,7 +67,7 @@ module Billy
67
67
 
68
68
  def build_request_options(url, headers, body)
69
69
  headers = Hash[headers.map { |k, v| [k.downcase, v] }]
70
- headers.delete('accept-encoding')
70
+ headers['accept-encoding'] = ''
71
71
 
72
72
  uri = Addressable::URI.parse(url)
73
73
  headers.merge!({'authorization' => [uri.user, uri.password]}) if uri.userinfo
@@ -62,7 +62,7 @@ module Billy
62
62
  end
63
63
 
64
64
  def matches?(method, url)
65
- if method == @method
65
+ if @method == 'ALL' || method == @method
66
66
  if @url.is_a?(Regexp)
67
67
  url.match(@url)
68
68
  else
@@ -1,3 +1,3 @@
1
1
  module Billy
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -43,6 +43,17 @@ describe Billy::ProxyRequestStub do
43
43
  expect(stub.matches?('GET', 'http://example.com/foo/bar/')).to be
44
44
  expect(stub.matches?('GET', 'http://example.com/foo/bar/?baz=bap')).to be
45
45
  end
46
+
47
+ it 'should match all methods' do
48
+ expect(Billy::ProxyRequestStub.new('http://example.com', method: :all)
49
+ .matches?('GET', 'http://example.com')).to be
50
+ expect(Billy::ProxyRequestStub.new('http://example.com', method: :all)
51
+ .matches?('POST', 'http://example.com')).to be
52
+ expect(Billy::ProxyRequestStub.new('http://example.com', method: :all)
53
+ .matches?('OPTIONS', 'http://example.com')).to be
54
+ expect(Billy::ProxyRequestStub.new('http://example.com', method: :all)
55
+ .matches?('HEAD', 'http://example.com')).to be
56
+ end
46
57
  end
47
58
 
48
59
  context "#matches? (with strip_query_params false in config)" do
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.0.0
4
+ version: 2.1.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-01-30 00:00:00.000000000 Z
11
+ date: 2019-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec