webmock 3.2.1 → 3.3.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
- SHA256:
3
- metadata.gz: 179133602a27a9b18e133abc3ed4f2cdc0dd40b654584328ece6a78c0158abd5
4
- data.tar.gz: c32e65dbc8de6903fc1074fc705d0484a2029d5c78bf55d8a67606867040f642
2
+ SHA1:
3
+ metadata.gz: 9824be80903ce63b7e2f3a3b61c5924ba3d884ff
4
+ data.tar.gz: 4666fd52ab43ddd61feabf9b53b565b332d56d17
5
5
  SHA512:
6
- metadata.gz: 047c1a68dc3afcb1eb74ab1b4aa0f77edf0f7d17972b15abdde404d8305ad1fafa7a2915e0c82ed7337af935ca7740e4c9cc9d6ea8b83071b484b51c3da3624f
7
- data.tar.gz: 3aa1f21106c10505bc565455c9c7db69f70ae70a0e4cf61e57545f56db997f3363ec6479f789df31b688b7586aa727ef6f9332851f7edeb0a572eec18a410091
6
+ metadata.gz: a9e1a7c45d9e2ae020ebb116edcd3d52b529df4a29495f0539f234738f34dff65d2e38c45de3a2361cb203be364c94d1e1eebd88ccbdaac27d0c0ed15e7f614c
7
+ data.tar.gz: 421aca9b146365fa1f0c6425435620b290323e10230acdf39fe6b572fc3072aad7bca874243176b4cf03a39eb4ed239a3063b640f2abe3e7ebf9e6b15fb44785
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.3.0
4
+
5
+ * Better formatting of outputted request stub snippets, displayed on failures due to unstubbed requests.
6
+
7
+ Thanks to [Olia Kremmyda](https://github.com/Olia-Kremmyda)
8
+
9
+
3
10
  ## 3.2.1
4
11
 
5
12
  * Fixed Ruby warning under Ruby 2.5
data/README.md CHANGED
@@ -1053,6 +1053,7 @@ People who submitted patches and new features or suggested improvements. Many th
1053
1053
  * Olia Kremmyda
1054
1054
  * Michał Matyas
1055
1055
  * Matt Brictson
1056
+ * Olia Kremmyda
1056
1057
 
1057
1058
  For a full list of contributors you can visit the
1058
1059
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -344,6 +344,10 @@ module WebMock
344
344
  WebMock::Util::Headers.sorted_headers_string(@pattern)
345
345
  end
346
346
 
347
+ def pp_to_s
348
+ WebMock::Util::Headers.pp_headers_string(@pattern)
349
+ end
350
+
347
351
  private
348
352
 
349
353
  def empty_headers?(headers)
@@ -16,13 +16,13 @@ module WebMock
16
16
  with = "".dup
17
17
 
18
18
  if (request_pattern.body_pattern)
19
- with << "body: #{request_pattern.body_pattern.to_s}"
19
+ with << "\n body: #{request_pattern.body_pattern.to_s}"
20
20
  end
21
21
 
22
22
  if (request_pattern.headers_pattern)
23
- with << ",\n " unless with.empty?
23
+ with << ",\n " unless with.empty?
24
24
 
25
- with << "headers: #{request_pattern.headers_pattern.to_s}"
25
+ with << " headers: #{request_pattern.headers_pattern.pp_to_s}"
26
26
  end
27
27
  string << ".\n with(#{with})" unless with.empty?
28
28
  if with_response
@@ -34,6 +34,21 @@ module WebMock
34
34
  str << '}'
35
35
  end
36
36
 
37
+ def self.pp_headers_string(headers)
38
+ headers = WebMock::Util::Headers.normalize_headers(headers)
39
+ seperator = "\n\t "
40
+ str = "{#{seperator} ".dup
41
+ str << headers.map do |k,v|
42
+ v = case v
43
+ when Regexp then v.inspect
44
+ when Array then "["+v.map{|w| "'#{w.to_s}'"}.join(", ")+"]"
45
+ else "'#{v.to_s}'"
46
+ end
47
+ "'#{k}'=>#{v}"
48
+ end.sort.join(",#{seperator} ")
49
+ str << "\n }"
50
+ end
51
+
37
52
  def self.decode_userinfo_from_header(header)
38
53
  header.sub(/^Basic /, "").unpack("m").first
39
54
  end
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.2.1' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.3.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -60,7 +60,7 @@ RSpec.describe WebMock::RequestSignatureSnippet do
60
60
  result = subject.request_stubs
61
61
  result.sub!("registered request stubs:\n\n", "")
62
62
  expect(result).to eq(
63
- "stub_request(:get, \"https://www.example.com/\").\n with(body: {\"a\"=>\"b\"})"
63
+ "stub_request(:get, \"https://www.example.com/\").\n with(\n body: {\"a\"=>\"b\"})"
64
64
  )
65
65
  end
66
66
 
@@ -74,7 +74,7 @@ RSpec.describe WebMock::RequestSignatureSnippet do
74
74
  result = subject.request_stubs
75
75
  result.sub!("registered request stubs:\n\n", "")
76
76
  expect(result).to eq(
77
- "stub_request(:get, \"https://www.example.com/\").\n with(body: {\"a\"=>\"b\"})\n\nBody diff:\n [[\"-\", \"key\", \"different value\"], [\"+\", \"a\", \"b\"]]\n"
77
+ "stub_request(:get, \"https://www.example.com/\").\n with(\n body: {\"a\"=>\"b\"})\n\nBody diff:\n [[\"-\", \"key\", \"different value\"], [\"+\", \"a\", \"b\"]]\n"
78
78
  )
79
79
  end
80
80
  end
@@ -16,7 +16,7 @@ describe WebMock::StubRequestSnippet do
16
16
  it "should print stub request snippet with body if available" do
17
17
  @request_signature.body = "abcdef"
18
18
  expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
19
- "\n with(body: \"abcdef\")." +
19
+ "\n with(\n body: \"abcdef\")." +
20
20
  "\n to_return(status: 200, body: \"\", headers: {})"
21
21
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
22
22
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected)
@@ -25,7 +25,7 @@ describe WebMock::StubRequestSnippet do
25
25
  it "should print stub request snippet with multiline body" do
26
26
  @request_signature.body = "abc\ndef"
27
27
  expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
28
- "\n with(body: \"abc\\ndef\")." +
28
+ "\n with(\n body: \"abc\\ndef\")." +
29
29
  "\n to_return(status: 200, body: \"\", headers: {})"
30
30
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
31
31
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected)
@@ -34,7 +34,7 @@ describe WebMock::StubRequestSnippet do
34
34
  it "should print stub request snippet with headers if any" do
35
35
  @request_signature.headers = {'B' => 'b', 'A' => 'a'}
36
36
  expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
37
- "\n with(headers: {\'A\'=>\'a\', \'B\'=>\'b\'})." +
37
+ "\n with( headers: {\n\t\ 'A\'=>\'a\',\n\t \'B\'=>\'b\'\n })." +
38
38
  "\n to_return(status: 200, body: \"\", headers: {})"
39
39
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
40
40
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected)
@@ -44,7 +44,7 @@ describe WebMock::StubRequestSnippet do
44
44
  @request_signature.body = "abcdef"
45
45
  @request_signature.headers = {'B' => 'b', 'A' => 'a'}
46
46
  expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
47
- "\n with(body: \"abcdef\",\n headers: {\'A\'=>\'a\', \'B\'=>\'b\'})." +
47
+ "\n with(\n body: \"abcdef\",\n headers: {\n\t \'A\'=>\'a\',\n\t \'B\'=>\'b\'\n })." +
48
48
  "\n to_return(status: 200, body: \"\", headers: {})"
49
49
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
50
50
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected)
@@ -52,7 +52,7 @@ describe WebMock::StubRequestSnippet do
52
52
 
53
53
  it "should not print to_return part if not wanted" do
54
54
  expected = 'stub_request(:get, "http://www.example.com/").'+
55
- "\n with(body: \"abcdef\")"
55
+ "\n with(\n body: \"abcdef\")"
56
56
  stub = WebMock::RequestStub.new(:get, "www.example.com").with(body: "abcdef").to_return(body: "hello")
57
57
  expect(WebMock::StubRequestSnippet.new(stub).to_s(false)).to eq(expected)
58
58
  end
@@ -68,8 +68,11 @@ describe WebMock::StubRequestSnippet do
68
68
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
69
69
  expected = <<-STUB
70
70
  stub_request(:post, "http://www.example.com/").
71
- with(body: {"user"=>{"first_name"=>"Bartosz"}},
72
- headers: {'Content-Type'=>'application/x-www-form-urlencoded'}).
71
+ with(
72
+ body: {"user"=>{"first_name"=>"Bartosz"}},
73
+ headers: {
74
+ \t 'Content-Type'=>'application/x-www-form-urlencoded'
75
+ }).
73
76
  to_return(status: 200, body: \"\", headers: {})
74
77
  STUB
75
78
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected.strip)
@@ -82,8 +85,11 @@ stub_request(:post, "http://www.example.com/").
82
85
  @request_stub = WebMock::RequestStub.from_request_signature(@request_signature)
83
86
  expected = <<-STUB
84
87
  stub_request(:post, "http://www.example.com/").
85
- with(body: "#{multipart_form_body}",
86
- headers: {'Content-Type'=>'multipart/form-data; boundary=ABC123'}).
88
+ with(
89
+ body: "#{multipart_form_body}",
90
+ headers: {
91
+ \t 'Content-Type'=>'multipart/form-data; boundary=ABC123'
92
+ }).
87
93
  to_return(status: 200, body: \"\", headers: {})
88
94
  STUB
89
95
  expect(WebMock::StubRequestSnippet.new(@request_stub).to_s).to eq(expected.strip)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -398,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
398
  version: '0'
399
399
  requirements: []
400
400
  rubyforge_project: webmock
401
- rubygems_version: 2.7.3
401
+ rubygems_version: 2.6.13
402
402
  signing_key:
403
403
  specification_version: 4
404
404
  summary: Library for stubbing HTTP requests in Ruby.