webmock 3.5.0 → 3.25.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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +476 -2
  3. data/README.md +166 -42
  4. data/lib/webmock/api.rb +2 -0
  5. data/lib/webmock/assertion_failure.rb +2 -0
  6. data/lib/webmock/callback_registry.rb +2 -0
  7. data/lib/webmock/config.rb +2 -0
  8. data/lib/webmock/cucumber.rb +2 -0
  9. data/lib/webmock/deprecation.rb +2 -0
  10. data/lib/webmock/errors.rb +2 -0
  11. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +228 -0
  12. data/lib/webmock/http_lib_adapters/curb_adapter.rb +14 -3
  13. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +22 -9
  14. data/lib/webmock/http_lib_adapters/excon_adapter.rb +5 -0
  15. data/lib/webmock/http_lib_adapters/http_lib_adapter.rb +2 -0
  16. data/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +2 -0
  17. data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
  18. data/lib/webmock/http_lib_adapters/http_rb/request.rb +17 -5
  19. data/lib/webmock/http_lib_adapters/http_rb/response.rb +49 -5
  20. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +11 -3
  21. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +8 -2
  22. data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +7 -5
  23. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +25 -7
  24. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +35 -15
  25. data/lib/webmock/http_lib_adapters/net_http.rb +59 -112
  26. data/lib/webmock/http_lib_adapters/net_http_response.rb +3 -1
  27. data/lib/webmock/http_lib_adapters/patron_adapter.rb +4 -2
  28. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +18 -2
  29. data/lib/webmock/matchers/any_arg_matcher.rb +2 -0
  30. data/lib/webmock/matchers/hash_argument_matcher.rb +2 -0
  31. data/lib/webmock/matchers/hash_excluding_matcher.rb +2 -0
  32. data/lib/webmock/matchers/hash_including_matcher.rb +2 -0
  33. data/lib/webmock/minitest.rb +2 -0
  34. data/lib/webmock/rack_response.rb +5 -1
  35. data/lib/webmock/request_body_diff.rb +3 -1
  36. data/lib/webmock/request_execution_verifier.rb +2 -0
  37. data/lib/webmock/request_pattern.rb +118 -61
  38. data/lib/webmock/request_registry.rb +2 -0
  39. data/lib/webmock/request_signature.rb +4 -2
  40. data/lib/webmock/request_signature_snippet.rb +2 -0
  41. data/lib/webmock/request_stub.rb +34 -0
  42. data/lib/webmock/response.rb +22 -14
  43. data/lib/webmock/responses_sequence.rb +2 -0
  44. data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +2 -0
  45. data/lib/webmock/rspec/matchers/webmock_matcher.rb +2 -0
  46. data/lib/webmock/rspec/matchers.rb +2 -0
  47. data/lib/webmock/rspec.rb +4 -1
  48. data/lib/webmock/stub_registry.rb +28 -11
  49. data/lib/webmock/stub_request_snippet.rb +2 -0
  50. data/lib/webmock/test_unit.rb +3 -3
  51. data/lib/webmock/util/hash_counter.rb +12 -6
  52. data/lib/webmock/util/hash_keys_stringifier.rb +2 -0
  53. data/lib/webmock/util/hash_validator.rb +2 -0
  54. data/lib/webmock/util/headers.rb +23 -10
  55. data/lib/webmock/util/parsers/json.rb +72 -0
  56. data/lib/webmock/util/parsers/parse_error.rb +7 -0
  57. data/lib/webmock/util/parsers/xml.rb +16 -0
  58. data/lib/webmock/util/query_mapper.rb +6 -2
  59. data/lib/webmock/util/uri.rb +11 -9
  60. data/lib/webmock/util/values_stringifier.rb +2 -0
  61. data/lib/webmock/util/version_checker.rb +7 -5
  62. data/lib/webmock/version.rb +3 -1
  63. data/lib/webmock/webmock.rb +22 -3
  64. data/lib/webmock.rb +5 -2
  65. metadata +99 -175
  66. data/.gemtest +0 -0
  67. data/.gitignore +0 -34
  68. data/.rspec-tm +0 -2
  69. data/.travis.yml +0 -21
  70. data/Gemfile +0 -9
  71. data/Rakefile +0 -30
  72. data/lib/webmock/util/json.rb +0 -67
  73. data/minitest/test_helper.rb +0 -34
  74. data/minitest/test_webmock.rb +0 -9
  75. data/minitest/webmock_spec.rb +0 -60
  76. data/spec/acceptance/curb/curb_spec.rb +0 -481
  77. data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
  78. data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -406
  79. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +0 -77
  80. data/spec/acceptance/excon/excon_spec.rb +0 -77
  81. data/spec/acceptance/excon/excon_spec_helper.rb +0 -50
  82. data/spec/acceptance/http_rb/http_rb_spec.rb +0 -82
  83. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -54
  84. data/spec/acceptance/httpclient/httpclient_spec.rb +0 -217
  85. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +0 -57
  86. data/spec/acceptance/manticore/manticore_spec.rb +0 -56
  87. data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
  88. data/spec/acceptance/net_http/net_http_shared.rb +0 -153
  89. data/spec/acceptance/net_http/net_http_spec.rb +0 -331
  90. data/spec/acceptance/net_http/net_http_spec_helper.rb +0 -64
  91. data/spec/acceptance/net_http/real_net_http_spec.rb +0 -20
  92. data/spec/acceptance/patron/patron_spec.rb +0 -125
  93. data/spec/acceptance/patron/patron_spec_helper.rb +0 -54
  94. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +0 -313
  95. data/spec/acceptance/shared/callbacks.rb +0 -147
  96. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +0 -36
  97. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +0 -95
  98. data/spec/acceptance/shared/precedence_of_stubs.rb +0 -15
  99. data/spec/acceptance/shared/request_expectations.rb +0 -923
  100. data/spec/acceptance/shared/returning_declared_responses.rb +0 -388
  101. data/spec/acceptance/shared/stubbing_requests.rb +0 -638
  102. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +0 -135
  103. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +0 -60
  104. data/spec/acceptance/webmock_shared.rb +0 -41
  105. data/spec/fixtures/test.txt +0 -1
  106. data/spec/quality_spec.rb +0 -84
  107. data/spec/spec_helper.rb +0 -48
  108. data/spec/support/example_curl_output.txt +0 -22
  109. data/spec/support/failures.rb +0 -9
  110. data/spec/support/my_rack_app.rb +0 -53
  111. data/spec/support/network_connection.rb +0 -19
  112. data/spec/support/webmock_server.rb +0 -69
  113. data/spec/unit/api_spec.rb +0 -175
  114. data/spec/unit/errors_spec.rb +0 -129
  115. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +0 -17
  116. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +0 -12
  117. data/spec/unit/matchers/hash_excluding_matcher_spec.rb +0 -61
  118. data/spec/unit/matchers/hash_including_matcher_spec.rb +0 -87
  119. data/spec/unit/rack_response_spec.rb +0 -112
  120. data/spec/unit/request_body_diff_spec.rb +0 -90
  121. data/spec/unit/request_execution_verifier_spec.rb +0 -208
  122. data/spec/unit/request_pattern_spec.rb +0 -596
  123. data/spec/unit/request_registry_spec.rb +0 -95
  124. data/spec/unit/request_signature_snippet_spec.rb +0 -89
  125. data/spec/unit/request_signature_spec.rb +0 -155
  126. data/spec/unit/request_stub_spec.rb +0 -199
  127. data/spec/unit/response_spec.rb +0 -282
  128. data/spec/unit/stub_registry_spec.rb +0 -103
  129. data/spec/unit/stub_request_snippet_spec.rb +0 -115
  130. data/spec/unit/util/hash_counter_spec.rb +0 -39
  131. data/spec/unit/util/hash_keys_stringifier_spec.rb +0 -27
  132. data/spec/unit/util/headers_spec.rb +0 -28
  133. data/spec/unit/util/json_spec.rb +0 -33
  134. data/spec/unit/util/query_mapper_spec.rb +0 -150
  135. data/spec/unit/util/uri_spec.rb +0 -299
  136. data/spec/unit/util/version_checker_spec.rb +0 -65
  137. data/spec/unit/webmock_spec.rb +0 -11
  138. data/test/http_request.rb +0 -24
  139. data/test/shared_test.rb +0 -108
  140. data/test/test_helper.rb +0 -23
  141. data/test/test_webmock.rb +0 -6
  142. data/webmock.gemspec +0 -46
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WebMock::Util::QueryMapper do
4
- subject { described_class }
5
-
6
- context '#query_to_values' do
7
- it 'should raise on invalid notation' do
8
- query = 'a=&b=c'
9
- expect { subject.query_to_values(query, {notation: 'foo'}) }.to raise_error(
10
- ArgumentError,
11
- 'Invalid notation. Must be one of: [:flat, :dot, :subscript, :flat_array].'
12
- )
13
- end
14
-
15
- it 'should parse hash queries' do
16
- # {"one" => {"two" => {"three" => ["four", "five"]}}}
17
- query = 'one%5Btwo%5D%5Bthree%5D%5B%5D=four&one%5Btwo%5D%5Bthree%5D%5B%5D=five'
18
- hsh = subject.query_to_values(query)
19
- expect(hsh['one']['two']['three']).to eq(%w(four five))
20
- end
21
-
22
- it 'should parse one nil value queries' do
23
- # {'a' => nil, 'b' => 'c'}
24
- query = 'a=&b=c'
25
- hsh = subject.query_to_values(query)
26
- expect(hsh['a']).to be_empty
27
- expect(hsh['b']).to eq('c')
28
- end
29
-
30
- it 'should parse array queries' do
31
- # {"one" => ["foo", "bar"]}
32
- query = 'one%5B%5D=foo&one%5B%5D=bar'
33
- hsh = subject.query_to_values(query)
34
- expect(hsh['one']).to eq(%w(foo bar))
35
- end
36
-
37
- it 'should parse string queries' do
38
- # {"one" => "two", "three" => "four"}
39
- query = 'one=two&three=four'
40
- hsh = subject.query_to_values(query)
41
- expect(hsh).to eq({'one' => 'two', 'three' => 'four'})
42
- end
43
-
44
- it 'should parse nested queries' do
45
- # [{"b"=>[{"c"=>[{"d"=>["1", {"e"=>"2"}]}]}]}]
46
- query = 'a%5B%5D%5Bb%5D%5B%5D%5Bc%5D%5B%5D%5Bd%5D%5B%5D=1&a%5B%5D%5Bb%5D%5B%5D%5Bc%5D%5B%5D%5Bd%5D%5B%5D%5Be%5D=2'
47
- hsh = subject.query_to_values(query)
48
- expect(hsh['a'][0]['b'][0]['c'][0]['d'][0]).to eq('1')
49
- expect(hsh['a'][0]['b'][0]['c'][0]['d'][1]['e']).to eq('2')
50
- end
51
-
52
- it "should parse nested repeated correctly" do
53
- query = "a[][b][]=one&a[][b][]=two"
54
- hsh = subject.query_to_values(query)
55
- expect(hsh['a']).to be_a(Array)
56
- expect(hsh['a'][0]).to eq({"b" => ['one']})
57
- expect(hsh['a'][1]).to eq({"b" => ['two']})
58
- end
59
-
60
- it "should parse nested non-repeated correctly" do
61
- query = "a[][b][]=one&a[][c][]=two"
62
- hsh = subject.query_to_values(query)
63
- expect(hsh['a']).to be_a(Array)
64
- expect(hsh['a'][0]['b']).to eq(['one'])
65
- expect(hsh['a'][0]['c']).to eq(['two'])
66
- end
67
-
68
- it 'should not attempt to mutate its query argument' do
69
- query = "a=foo".freeze
70
- hsh = subject.query_to_values(query)
71
- expect(hsh['a']).to eq('foo')
72
- end
73
-
74
- it "should parse hash query with key starting with non word character" do
75
- query = "a[$in]=1".freeze
76
- hsh = subject.query_to_values(query)
77
- expect(hsh).to eql({'a' => {'$in' => '1'}})
78
- end
79
- end
80
-
81
- context '#to_query' do
82
- it 'should transform nil value' do
83
- expect(subject.to_query('a', nil)).to eq('a')
84
- end
85
- it 'should transform string value' do
86
- expect(subject.to_query('a', 'b')).to eq('a=b')
87
- end
88
- it 'should transform hash value' do
89
- expect(subject.to_query('a', {'key' => 'value'})).to eq('a[key]=value')
90
- end
91
- it 'should transform hash value with keys that are symbols' do
92
- expect(subject.to_query('a', {key: 'value'})).to eq('a[key]=value')
93
- end
94
- it 'should transform array value' do
95
- expect(subject.to_query('a', ['b', 'c'])).to eq('a[0]=b&a[1]=c')
96
- end
97
- it 'should transform boolean values' do
98
- expect(subject.to_query('a', true)).to eq('a=true')
99
- expect(subject.to_query('a', false)).to eq('a=false')
100
- end
101
- end
102
-
103
- context '#values_to_query' do
104
- it 'converts values to a query string' do
105
- query = "key=value&other_key=other_value"
106
- values = [['key','value'],['other_key','other_value']]
107
- expect(subject.values_to_query values).to eq query
108
- end
109
-
110
- it 'converts values with missing keys to a query string' do
111
- query = "=value"
112
- values = { '' => 'value' }
113
- expect(subject.values_to_query values).to eq query
114
- end
115
-
116
- it 'converts values with nil keys to a query string' do
117
- query = "=value"
118
- values = { nil => 'value' }
119
- expect(subject.values_to_query values).to eq query
120
- end
121
- end
122
-
123
- it 'converts array values, vice versa' do
124
- query = "one%5B%5D=1&one%5B%5D=2" # one[]=1&one[]=2
125
- values = {"one" => ["1","2"]}
126
- expect(subject.values_to_query values).to eq query
127
- expect(subject.query_to_values query).to eq values
128
- end
129
-
130
- it 'converts hash values, vice versa' do
131
- query = "one%5Ba%5D=1&one%5Bb%5D=2" # one[a]=1&one[b]=2
132
- values = {"one" => {"a" => "1", "b" => "2"}}
133
- expect(subject.values_to_query values).to eq query
134
- expect(subject.query_to_values query).to eq values
135
- end
136
-
137
- it 'converts complex nested hashes, vice versa' do
138
- query = "one%5B%5D[foo]=bar&one%5B%5D[zoo]=car" # one[][foo]=bar&one[][zoo]=car
139
- values = {"one" => [{"foo" => "bar", "zoo" => "car"}]}
140
- expect(subject.values_to_query values).to eq query
141
- expect(subject.query_to_values query).to eq values
142
- end
143
-
144
- it 'converts complex nested array of hashes, vice versa' do
145
- query = "one%5B%5D[foo]=bar&one%5B%5D[foo]=bar&one%5B%5D[zoo]=car" # one[][foo]=bar&one[][foo]=bar&one[][zoo]=car
146
- values = {"one" => [{"foo" => "bar"}, {"foo" => "bar", "zoo" => "car"}]}
147
- expect(subject.values_to_query values).to eq query
148
- expect(subject.query_to_values query).to eq values
149
- end
150
- end
@@ -1,299 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- URIS_WITHOUT_PATH_OR_PARAMS =
5
- [
6
- "www.example.com",
7
- "www.example.com/",
8
- "www.example.com:80",
9
- "www.example.com:80/",
10
- "http://www.example.com",
11
- "http://www.example.com/",
12
- "http://www.example.com:80",
13
- "http://www.example.com:80/"
14
- ].sort
15
-
16
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS =
17
- [
18
- "www.example.com?a=b",
19
- "www.example.com/?a=b",
20
- "www.example.com:80?a=b",
21
- "www.example.com:80/?a=b",
22
- "http://www.example.com?a=b",
23
- "http://www.example.com/?a=b",
24
- "http://www.example.com:80?a=b",
25
- "http://www.example.com:80/?a=b"
26
- ].sort
27
-
28
- URIS_WITH_AUTH =
29
- [
30
- "a b:pass@www.example.com",
31
- "a b:pass@www.example.com/",
32
- "a b:pass@www.example.com:80",
33
- "a b:pass@www.example.com:80/",
34
- "http://a b:pass@www.example.com",
35
- "http://a b:pass@www.example.com/",
36
- "http://a b:pass@www.example.com:80",
37
- "http://a b:pass@www.example.com:80/",
38
- "a%20b:pass@www.example.com",
39
- "a%20b:pass@www.example.com/",
40
- "a%20b:pass@www.example.com:80",
41
- "a%20b:pass@www.example.com:80/",
42
- "http://a%20b:pass@www.example.com",
43
- "http://a%20b:pass@www.example.com/",
44
- "http://a%20b:pass@www.example.com:80",
45
- "http://a%20b:pass@www.example.com:80/"
46
- ].sort
47
-
48
- URIS_WITH_PATH_AND_PARAMS =
49
- [
50
- "www.example.com/my path/?a=my param&b=c d",
51
- "www.example.com/my%20path/?a=my%20param&b=c%20d",
52
- "www.example.com:80/my path/?a=my param&b=c d",
53
- "www.example.com:80/my%20path/?a=my%20param&b=c%20d",
54
- "http://www.example.com/my path/?a=my param&b=c d",
55
- "http://www.example.com/my%20path/?a=my%20param&b=c%20d",
56
- "http://www.example.com:80/my path/?a=my param&b=c d",
57
- "http://www.example.com:80/my%20path/?a=my%20param&b=c%20d",
58
- ].sort
59
-
60
- URIS_WITH_DIFFERENT_PORT =
61
- [
62
- "www.example.com:88",
63
- "www.example.com:88/",
64
- "http://www.example.com:88",
65
- "http://www.example.com:88/"
66
- ].sort
67
-
68
-
69
- URIS_FOR_HTTPS =
70
- [
71
- "https://www.example.com",
72
- "https://www.example.com/",
73
- "https://www.example.com:443",
74
- "https://www.example.com:443/"
75
- ].sort
76
-
77
-
78
- describe WebMock::Util::URI do
79
-
80
- describe "reporting variations of uri" do
81
-
82
- it "should find all variations of the same uri for all variations of uri with params and path" do
83
- URIS_WITH_PATH_AND_PARAMS.each do |uri|
84
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_PATH_AND_PARAMS)
85
- end
86
- end
87
-
88
- it "should find all variations of the same uri for all variations of uri with params but without path" do
89
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri|
90
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITHOUT_PATH_BUT_WITH_PARAMS)
91
- end
92
- end
93
-
94
- it "should find all variations of the same uri for all variations of uri without params or path" do
95
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
96
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITHOUT_PATH_OR_PARAMS)
97
- end
98
- end
99
-
100
- it "should find all variations of the same uri for all variations of uri with auth" do
101
- URIS_WITH_AUTH.each do |uri|
102
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_AUTH)
103
- end
104
- end
105
-
106
- it "should find all variations of the same uri for all variations of uri with different port" do
107
- URIS_WITH_DIFFERENT_PORT.each do |uri|
108
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_DIFFERENT_PORT)
109
- end
110
- end
111
-
112
- it "should find all variations of the same uri for all variations of https uris" do
113
- URIS_FOR_HTTPS.each do |uri|
114
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_HTTPS)
115
- end
116
- end
117
-
118
- end
119
-
120
- describe "normalized uri equality" do
121
-
122
- it "should successfully compare all variations of the same uri with path and params" do
123
- URIS_WITH_PATH_AND_PARAMS.each do |uri_a|
124
- URIS_WITH_PATH_AND_PARAMS.each do |uri_b|
125
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
126
- end
127
- end
128
- end
129
-
130
- it "should successfully compare all variations of the same uri with path but with params" do
131
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_a|
132
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_b|
133
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
134
- end
135
- end
136
- end
137
-
138
- it "should successfully compare all variations of the same uri without path or params" do
139
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_a|
140
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_b|
141
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
142
- end
143
- end
144
- end
145
-
146
- it "should successfully compare all variations of the same uri with authority" do
147
- URIS_WITH_AUTH.each do |uri_a|
148
- URIS_WITH_AUTH.each do |uri_b|
149
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
150
- end
151
- end
152
- end
153
-
154
- it "should successfully compare all variations of the same uri custom port" do
155
- URIS_WITH_DIFFERENT_PORT.each do |uri_a|
156
- URIS_WITH_DIFFERENT_PORT.each do |uri_b|
157
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
158
- end
159
- end
160
- end
161
-
162
- it "should successfully compare all variations of the same https uri" do
163
- URIS_FOR_HTTPS.each do |uri_a|
164
- URIS_FOR_HTTPS.each do |uri_b|
165
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
166
- end
167
- end
168
- end
169
-
170
- it "should successfully handle array parameters" do
171
- uri_string = 'http://www.example.com:80/path?a[]=b&a[]=c'
172
- uri = WebMock::Util::URI.normalize_uri(uri_string)
173
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"a"=>["b", "c"]})
174
- end
175
-
176
- it "should successfully handle hash parameters" do
177
- uri_string = 'http://www.example.com:80/path?a[d]=b&a[e]=c&a[b][c]=1'
178
- uri = WebMock::Util::URI.normalize_uri(uri_string)
179
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"a"=>{"d"=>"b", "e"=>"c", "b"=>{"c"=>"1"}}})
180
- end
181
-
182
- it "should successfully handle nested hash parameters" do
183
- uri_string = 'http://www.example.com:80/path?one[two][three][]=four&one[two][three][]=five'
184
- uri = WebMock::Util::URI.normalize_uri(uri_string)
185
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"one"=>{"two"=>{"three" => ["four", "five"]}}})
186
- end
187
-
188
- it "should successfully handle mixed array and hash parameters" do
189
- # derived from an elasticsearch query:
190
- # load => {
191
- # :include => [
192
- # { :staff => :email },
193
- # :business_name
194
- # ]
195
- # }
196
- uri_string = "http://www.example.com:80/path?load[include][][staff]=email&load[include][]=business_name"
197
- uri = WebMock::Util::URI.normalize_uri(uri_string)
198
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"load"=>{"include"=>[{"staff"=>"email"},"business_name"]}})
199
- end
200
-
201
- context "when query notation is set to :flat_array" do
202
- before :all do
203
- WebMock::Config.instance.query_values_notation = :flat_array
204
- end
205
-
206
- it "should successfully handle repeated paramters" do
207
- uri_string = "http://www.example.com:80/path?target=host1&target=host2"
208
- uri = WebMock::Util::URI.normalize_uri(uri_string)
209
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query, notation: WebMock::Config.instance.query_values_notation)).to eq([['target', 'host1'], ['target', 'host2']])
210
- end
211
- end
212
- end
213
-
214
- describe "sorting query values" do
215
-
216
- context "when query values is a Hash" do
217
- it "returns an alphabetically sorted hash" do
218
- sorted_query = WebMock::Util::URI.sort_query_values({"b"=>"one", "a"=>"two"})
219
- expect(sorted_query).to eq({"a"=>"two", "b"=>"one"})
220
- end
221
- end
222
-
223
- context "when query values is an Array" do
224
- it "returns an alphabetically sorted array" do
225
- sorted_query = WebMock::Util::URI.sort_query_values([["b","two"],["a","one_b"],["a","one_a"]])
226
- expect(sorted_query).to eq([["a","one_a"],["a","one_b"],["b","two"]])
227
- end
228
- end
229
- end
230
-
231
- describe "stripping default port" do
232
-
233
- it "should strip_default_port_from_uri strips 80 from http with path" do
234
- uri = "http://example.com:80/foo/bar"
235
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
236
- expect(stripped_uri).to eq("http://example.com/foo/bar")
237
- end
238
-
239
- it "should strip_default_port_from_uri strips 80 from http without path" do
240
- uri = "http://example.com:80"
241
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
242
- expect(stripped_uri).to eq("http://example.com")
243
- end
244
-
245
- it "should strip_default_port_from_uri strips 443 from https without path" do
246
- uri = "https://example.com:443"
247
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
248
- expect(stripped_uri).to eq("https://example.com")
249
- end
250
-
251
- it "should strip_default_port_from_uri strips 443 from https" do
252
- uri = "https://example.com:443/foo/bar"
253
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
254
- expect(stripped_uri).to eq("https://example.com/foo/bar")
255
- end
256
-
257
- it "should strip_default_port_from_uri does not strip 8080 from http" do
258
- uri = "http://example.com:8080/foo/bar"
259
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
260
- end
261
-
262
- it "should strip_default_port_from_uri does not strip 443 from http" do
263
- uri = "http://example.com:443/foo/bar"
264
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
265
- end
266
-
267
- it "should strip_default_port_from_uri does not strip 80 from query string" do
268
- uri = "http://example.com/?a=:80&b=c"
269
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
270
- end
271
-
272
- it "should strip_default_port_from_uri does not modify strings that do not start with http or https" do
273
- uri = "httpz://example.com:80/"
274
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
275
- end
276
-
277
- end
278
-
279
-
280
- describe "encoding userinfo" do
281
-
282
- it "should encode unsafe chars in userinfo does not encode userinfo safe punctuation" do
283
- userinfo = "user;&=+$,:secret"
284
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(userinfo)
285
- end
286
-
287
- it "should encode unsafe chars in userinfo does not encode rfc 3986 unreserved characters" do
288
- userinfo = "-.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
289
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(userinfo)
290
- end
291
-
292
- it "should encode unsafe chars in userinfo does encode other characters" do
293
- userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
294
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(safe_userinfo)
295
- end
296
-
297
- end
298
-
299
- end
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module WebMock
4
- describe VersionChecker do
5
- it 'prints a warning if the major version is too low' do
6
- checker = VersionChecker.new('foo', '0.7.3', '1.0.0', '1.1')
7
- expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 0.7.3. WebMock supports version >= 1.0.0, < 1.2.\e[0m")
8
- checker.check_version!
9
- end
10
-
11
- it 'prints a warning if the minor version is too low' do
12
- checker = VersionChecker.new('foo', '1.0.99', '1.1.3', '1.2')
13
- expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.99. WebMock supports version >= 1.1.3, < 1.3.\e[0m")
14
- checker.check_version!
15
- end
16
-
17
- it 'prints a warning if the patch version is too low' do
18
- checker = VersionChecker.new('foo', '1.0.8', '1.0.10', '1.2')
19
- expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.8. WebMock supports version >= 1.0.10, < 1.3.\e[0m")
20
- checker.check_version!
21
- end
22
-
23
- it 'prints a warning if the patch version is too low and max version is not specified' do
24
- checker = VersionChecker.new('foo', '1.0.8', '1.0.10')
25
- expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.8. WebMock supports version >= 1.0.10.\e[0m")
26
- checker.check_version!
27
- end
28
-
29
- it 'prints a warning if the major version is too high' do
30
- checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '1.1')
31
- expect(Kernel).to receive(:warn).with(/may not work with this version/)
32
- checker.check_version!
33
- end
34
-
35
- it 'prints a warning if the minor version is too high' do
36
- checker = VersionChecker.new('foo', '1.2.0', '1.0.0', '1.1')
37
- expect(Kernel).to receive(:warn).with(/may not work with this version/)
38
- checker.check_version!
39
- end
40
-
41
- it 'does not raise an error or print a warning when the major version is between the min and max' do
42
- checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '3.0')
43
- expect(Kernel).not_to receive(:warn)
44
- checker.check_version!
45
- end
46
-
47
- it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 0.7 and the version is 0.7.3' do
48
- checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '0.7')
49
- expect(Kernel).not_to receive(:warn)
50
- checker.check_version!
51
- end
52
-
53
- it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is not specified and the version is 0.8.3' do
54
- checker = VersionChecker.new('foo', '0.8.3', '0.6.5')
55
- expect(Kernel).not_to receive(:warn)
56
- checker.check_version!
57
- end
58
-
59
- it "prints warning if version is unsupported" do
60
- checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '3.0', ['2.0.0'])
61
- expect(Kernel).to receive(:warn).with(%r{You are using foo 2.0.0. WebMock does not support this version. WebMock supports versions >= 1.0.0, < 3.1, except versions 2.0.0.})
62
- checker.check_version!
63
- end
64
- end
65
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "WebMock version" do
4
- it "should report version" do
5
- expect(WebMock.version).to eq(WebMock::VERSION)
6
- end
7
-
8
- it "should not require safe_yaml" do
9
- expect(defined?SafeYAML).to eq(nil)
10
- end
11
- end
data/test/http_request.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'ostruct'
2
-
3
- module HttpRequestTestHelper
4
- def http_request(method, uri, options = {})
5
- begin
6
- uri = URI.parse(uri)
7
- rescue
8
- uri = Addressable::URI.heuristic_parse(uri)
9
- end
10
- response = nil
11
- clazz = ::Net::HTTP.const_get("#{method.to_s.capitalize}")
12
- req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers])
13
- req.basic_auth uri.user, uri.password if uri.user
14
- http = ::Net::HTTP.new(uri.host, uri.port)
15
- http.use_ssl = true if uri.scheme == "https"
16
- response = http.start {|http|
17
- http.request(req, options[:body])
18
- }
19
- OpenStruct.new({
20
- body: response.body,
21
- headers: response,
22
- status: response.code })
23
- end
24
- end
data/test/shared_test.rb DELETED
@@ -1,108 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/http_request')
2
-
3
- module SharedTest
4
- include HttpRequestTestHelper
5
-
6
- def setup
7
- super
8
- @stub_http = stub_http_request(:any, "http://www.example.com")
9
- @stub_https = stub_http_request(:any, "https://www.example.com")
10
- end
11
-
12
- def test_assert_requested_with_stub_and_block_raises_error
13
- assert_raises ArgumentError do
14
- assert_requested(@stub_http) {}
15
- end
16
- end
17
-
18
- def test_assert_not_requested_with_stub_and_block_raises_error
19
- assert_raises ArgumentError do
20
- assert_not_requested(@stub_http) {}
21
- end
22
- end
23
-
24
- def test_error_on_non_stubbed_request
25
- assert_raise_with_message(WebMock::NetConnectNotAllowedError, %r{Real HTTP connections are disabled. Unregistered request: GET http://www.example.net/ with headers}) do
26
- http_request(:get, "http://www.example.net/")
27
- end
28
- end
29
-
30
- def test_verification_that_expected_request_occured
31
- http_request(:get, "http://www.example.com/")
32
- assert_requested(:get, "http://www.example.com", times: 1)
33
- assert_requested(:get, "http://www.example.com")
34
- end
35
-
36
- def test_verification_that_expected_stub_occured
37
- http_request(:get, "http://www.example.com/")
38
- assert_requested(@stub_http, times: 1)
39
- assert_requested(@stub_http)
40
- end
41
-
42
- def test_verification_that_expected_request_didnt_occur
43
- expected_message = "The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times"
44
- expected_message += "\n\nThe following requests were made:\n\nNo requests were made.\n============================================================"
45
- assert_fail(expected_message) do
46
- assert_requested(:get, "http://www.example.com")
47
- end
48
- end
49
-
50
- def test_verification_that_expected_stub_didnt_occur
51
- expected_message = "The request ANY http://www.example.com/ was expected to execute 1 time but it executed 0 times"
52
- expected_message += "\n\nThe following requests were made:\n\nNo requests were made.\n============================================================"
53
- assert_fail(expected_message) do
54
- assert_requested(@stub_http)
55
- end
56
- end
57
-
58
- def test_verification_that_expected_request_occured_with_body_and_headers
59
- http_request(:get, "http://www.example.com/",
60
- body: "abc", headers: {'A' => 'a'})
61
- assert_requested(:get, "http://www.example.com",
62
- body: "abc", headers: {'A' => 'a'})
63
- end
64
-
65
- def test_verification_that_expected_request_occured_with_query_params
66
- stub_request(:any, "http://www.example.com").with(query: hash_including({"a" => ["b", "c"]}))
67
- http_request(:get, "http://www.example.com/?a[]=b&a[]=c&x=1")
68
- assert_requested(:get, "http://www.example.com",
69
- query: hash_including({"a" => ["b", "c"]}))
70
- end
71
-
72
- def test_verification_that_expected_request_not_occured_with_query_params
73
- stub_request(:any, 'http://www.example.com').with(query: hash_including(a: ['b', 'c']))
74
- stub_request(:any, 'http://www.example.com').with(query: hash_excluding(a: ['b', 'c']))
75
- http_request(:get, 'http://www.example.com/?a[]=b&a[]=c&x=1')
76
- assert_not_requested(:get, 'http://www.example.com', query: hash_excluding('a' => ['b', 'c']))
77
- end
78
-
79
- def test_verification_that_expected_request_occured_with_excluding_query_params
80
- stub_request(:any, 'http://www.example.com').with(query: hash_excluding('a' => ['b', 'c']))
81
- http_request(:get, 'http://www.example.com/?a[]=x&a[]=y&x=1')
82
- assert_requested(:get, 'http://www.example.com', query: hash_excluding('a' => ['b', 'c']))
83
- end
84
-
85
- def test_verification_that_non_expected_request_didnt_occur
86
- expected_message = %r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
87
- assert_fail(expected_message) do
88
- http_request(:get, "http://www.example.com/")
89
- assert_not_requested(:get, "http://www.example.com")
90
- end
91
- end
92
-
93
- def test_refute_requested_alias
94
- expected_message = %r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
95
- assert_fail(expected_message) do
96
- http_request(:get, "http://www.example.com/")
97
- refute_requested(:get, "http://www.example.com")
98
- end
99
- end
100
-
101
- def test_verification_that_non_expected_stub_didnt_occur
102
- expected_message = %r(The request ANY http://www.example.com/ was not expected to execute but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
103
- assert_fail(expected_message) do
104
- http_request(:get, "http://www.example.com/")
105
- assert_not_requested(@stub_http)
106
- end
107
- end
108
- end