webmock 3.14.0 → 3.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +124 -2
  3. data/README.md +46 -18
  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 +8 -1
  12. data/lib/webmock/http_lib_adapters/curb_adapter.rb +4 -2
  13. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +14 -6
  14. data/lib/webmock/http_lib_adapters/excon_adapter.rb +2 -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 +3 -3
  18. data/lib/webmock/http_lib_adapters/http_rb/request.rb +3 -1
  19. data/lib/webmock/http_lib_adapters/http_rb/response.rb +6 -1
  20. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +6 -2
  21. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +8 -2
  22. data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +2 -0
  23. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +2 -0
  24. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +2 -0
  25. data/lib/webmock/http_lib_adapters/net_http.rb +24 -115
  26. data/lib/webmock/http_lib_adapters/net_http_response.rb +2 -0
  27. data/lib/webmock/http_lib_adapters/patron_adapter.rb +2 -0
  28. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +2 -0
  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 +2 -0
  35. data/lib/webmock/request_body_diff.rb +2 -0
  36. data/lib/webmock/request_execution_verifier.rb +2 -0
  37. data/lib/webmock/request_pattern.rb +26 -8
  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 +10 -8
  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 +2 -0
  48. data/lib/webmock/stub_registry.rb +2 -0
  49. data/lib/webmock/stub_request_snippet.rb +2 -0
  50. data/lib/webmock/test_unit.rb +2 -0
  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 +22 -8
  55. data/lib/webmock/util/json.rb +2 -0
  56. data/lib/webmock/util/query_mapper.rb +2 -0
  57. data/lib/webmock/util/uri.rb +3 -1
  58. data/lib/webmock/util/values_stringifier.rb +2 -0
  59. data/lib/webmock/util/version_checker.rb +7 -5
  60. data/lib/webmock/version.rb +3 -1
  61. data/lib/webmock/webmock.rb +12 -0
  62. data/lib/webmock.rb +2 -0
  63. metadata +51 -183
  64. data/.gemtest +0 -0
  65. data/.github/workflows/CI.yml +0 -37
  66. data/.gitignore +0 -34
  67. data/.rspec-tm +0 -2
  68. data/Gemfile +0 -9
  69. data/Rakefile +0 -38
  70. data/minitest/test_helper.rb +0 -34
  71. data/minitest/test_webmock.rb +0 -9
  72. data/minitest/webmock_spec.rb +0 -60
  73. data/spec/acceptance/async_http_client/async_http_client_spec.rb +0 -375
  74. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +0 -73
  75. data/spec/acceptance/curb/curb_spec.rb +0 -499
  76. data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
  77. data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -462
  78. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +0 -77
  79. data/spec/acceptance/excon/excon_spec.rb +0 -77
  80. data/spec/acceptance/excon/excon_spec_helper.rb +0 -52
  81. data/spec/acceptance/http_rb/http_rb_spec.rb +0 -93
  82. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -54
  83. data/spec/acceptance/httpclient/httpclient_spec.rb +0 -217
  84. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +0 -57
  85. data/spec/acceptance/manticore/manticore_spec.rb +0 -107
  86. data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
  87. data/spec/acceptance/net_http/net_http_shared.rb +0 -153
  88. data/spec/acceptance/net_http/net_http_spec.rb +0 -369
  89. data/spec/acceptance/net_http/net_http_spec_helper.rb +0 -64
  90. data/spec/acceptance/net_http/real_net_http_spec.rb +0 -20
  91. data/spec/acceptance/patron/patron_spec.rb +0 -125
  92. data/spec/acceptance/patron/patron_spec_helper.rb +0 -54
  93. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +0 -313
  94. data/spec/acceptance/shared/callbacks.rb +0 -148
  95. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +0 -36
  96. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +0 -95
  97. data/spec/acceptance/shared/precedence_of_stubs.rb +0 -15
  98. data/spec/acceptance/shared/request_expectations.rb +0 -930
  99. data/spec/acceptance/shared/returning_declared_responses.rb +0 -409
  100. data/spec/acceptance/shared/stubbing_requests.rb +0 -678
  101. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +0 -135
  102. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +0 -60
  103. data/spec/acceptance/webmock_shared.rb +0 -41
  104. data/spec/fixtures/test.txt +0 -1
  105. data/spec/quality_spec.rb +0 -84
  106. data/spec/spec_helper.rb +0 -48
  107. data/spec/support/example_curl_output.txt +0 -22
  108. data/spec/support/failures.rb +0 -9
  109. data/spec/support/my_rack_app.rb +0 -53
  110. data/spec/support/network_connection.rb +0 -19
  111. data/spec/support/webmock_server.rb +0 -70
  112. data/spec/unit/api_spec.rb +0 -175
  113. data/spec/unit/errors_spec.rb +0 -129
  114. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +0 -17
  115. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +0 -12
  116. data/spec/unit/matchers/hash_excluding_matcher_spec.rb +0 -61
  117. data/spec/unit/matchers/hash_including_matcher_spec.rb +0 -87
  118. data/spec/unit/rack_response_spec.rb +0 -112
  119. data/spec/unit/request_body_diff_spec.rb +0 -90
  120. data/spec/unit/request_execution_verifier_spec.rb +0 -208
  121. data/spec/unit/request_pattern_spec.rb +0 -736
  122. data/spec/unit/request_registry_spec.rb +0 -95
  123. data/spec/unit/request_signature_snippet_spec.rb +0 -89
  124. data/spec/unit/request_signature_spec.rb +0 -155
  125. data/spec/unit/request_stub_spec.rb +0 -199
  126. data/spec/unit/response_spec.rb +0 -286
  127. data/spec/unit/stub_registry_spec.rb +0 -103
  128. data/spec/unit/stub_request_snippet_spec.rb +0 -115
  129. data/spec/unit/util/hash_counter_spec.rb +0 -39
  130. data/spec/unit/util/hash_keys_stringifier_spec.rb +0 -27
  131. data/spec/unit/util/headers_spec.rb +0 -28
  132. data/spec/unit/util/json_spec.rb +0 -33
  133. data/spec/unit/util/query_mapper_spec.rb +0 -157
  134. data/spec/unit/util/uri_spec.rb +0 -371
  135. data/spec/unit/util/version_checker_spec.rb +0 -65
  136. data/spec/unit/webmock_spec.rb +0 -60
  137. data/test/http_request.rb +0 -24
  138. data/test/shared_test.rb +0 -108
  139. data/test/test_helper.rb +0 -23
  140. data/test/test_webmock.rb +0 -12
  141. data/webmock.gemspec +0 -54
@@ -1,157 +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
-
151
- it 'converts an empty array to ?' do
152
- query = "one%5B%5D"
153
- values = {"one" => []}
154
- expect(subject.values_to_query values).to eq query
155
- expect(subject.query_to_values query).to eq values
156
- end
157
- end
@@ -1,371 +0,0 @@
1
- require 'spec_helper'
2
-
3
- URIS_WITHOUT_PATH_OR_PARAMS =
4
- [
5
- "www.example.com",
6
- "www.example.com/",
7
- "www.example.com:80",
8
- "www.example.com:80/",
9
- "http://www.example.com",
10
- "http://www.example.com/",
11
- "http://www.example.com:80",
12
- "http://www.example.com:80/"
13
- ].sort
14
-
15
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS =
16
- [
17
- "www.example.com?a=b",
18
- "www.example.com/?a=b",
19
- "www.example.com:80?a=b",
20
- "www.example.com:80/?a=b",
21
- "http://www.example.com?a=b",
22
- "http://www.example.com/?a=b",
23
- "http://www.example.com:80?a=b",
24
- "http://www.example.com:80/?a=b"
25
- ].sort
26
-
27
- URIS_WITH_AUTH =
28
- [
29
- "a b:pass@www.example.com",
30
- "a b:pass@www.example.com/",
31
- "a b:pass@www.example.com:80",
32
- "a b:pass@www.example.com:80/",
33
- "http://a b:pass@www.example.com",
34
- "http://a b:pass@www.example.com/",
35
- "http://a b:pass@www.example.com:80",
36
- "http://a b:pass@www.example.com:80/",
37
- "a%20b:pass@www.example.com",
38
- "a%20b:pass@www.example.com/",
39
- "a%20b:pass@www.example.com:80",
40
- "a%20b:pass@www.example.com:80/",
41
- "http://a%20b:pass@www.example.com",
42
- "http://a%20b:pass@www.example.com/",
43
- "http://a%20b:pass@www.example.com:80",
44
- "http://a%20b:pass@www.example.com:80/"
45
- ].sort
46
-
47
- URIS_WITH_PATH_AND_PARAMS =
48
- [
49
- "www.example.com/my path/?a=my param&b=c d",
50
- "www.example.com/my%20path/?a=my%20param&b=c%20d",
51
- "www.example.com:80/my path/?a=my param&b=c d",
52
- "www.example.com:80/my%20path/?a=my%20param&b=c%20d",
53
- "http://www.example.com/my path/?a=my param&b=c d",
54
- "http://www.example.com/my%20path/?a=my%20param&b=c%20d",
55
- "http://www.example.com:80/my path/?a=my param&b=c d",
56
- "http://www.example.com:80/my%20path/?a=my%20param&b=c%20d",
57
- ].sort
58
-
59
- URIS_WITH_DIFFERENT_PORT =
60
- [
61
- "www.example.com:88",
62
- "www.example.com:88/",
63
- "http://www.example.com:88",
64
- "http://www.example.com:88/"
65
- ].sort
66
-
67
- URIS_FOR_HTTPS =
68
- [
69
- "https://www.example.com",
70
- "https://www.example.com/",
71
- "https://www.example.com:443",
72
- "https://www.example.com:443/"
73
- ].sort
74
-
75
- URIS_FOR_LOCALHOST =
76
- [
77
- "localhost",
78
- "localhost/",
79
- "localhost:80",
80
- "localhost:80/",
81
- "http://localhost",
82
- "http://localhost/",
83
- "http://localhost:80",
84
- "http://localhost:80/"
85
- ].sort
86
-
87
- URIS_WITH_SCHEME =
88
- [
89
- "http://www.example.com",
90
- "http://www.example.com/",
91
- "http://www.example.com:80",
92
- "http://www.example.com:80/"
93
- ].sort
94
-
95
- URIS_WITH_COLON_IN_PATH =
96
- [
97
- [
98
- "https://example.com/a/b:80",
99
- "https://example.com:443/a/b:80",
100
- ].sort,
101
- [
102
- "https://example.com:443/a/b:443",
103
- "https://example.com/a/b:443",
104
- ].sort,
105
- [
106
- "http://example.com/a/b:443",
107
- "example.com/a/b:443",
108
- "http://example.com:80/a/b:443",
109
- "example.com:80/a/b:443",
110
- ].sort,
111
- [
112
- "http://example.com/a/b:80",
113
- "example.com/a/b:80",
114
- "http://example.com:80/a/b:80",
115
- "example.com:80/a/b:80",
116
- ].sort
117
- ]
118
-
119
- describe WebMock::Util::URI do
120
-
121
- describe "reporting variations of uri" do
122
-
123
- it "should find all variations of the same uri for all variations of uri with params and path" do
124
- URIS_WITH_PATH_AND_PARAMS.each do |uri|
125
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_PATH_AND_PARAMS)
126
- end
127
- end
128
-
129
- it "should find all variations of the same uri for all variations of uri with params but without path" do
130
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri|
131
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITHOUT_PATH_BUT_WITH_PARAMS)
132
- end
133
- end
134
-
135
- it "should find all variations of the same uri for all variations of uri without params or path" do
136
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
137
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITHOUT_PATH_OR_PARAMS)
138
- end
139
- end
140
-
141
- it "should find all variations of the same uri for all variations of uri with auth" do
142
- URIS_WITH_AUTH.each do |uri|
143
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_AUTH)
144
- end
145
- end
146
-
147
- it "should find all variations of the same uri for all variations of uri with different port" do
148
- URIS_WITH_DIFFERENT_PORT.each do |uri|
149
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_WITH_DIFFERENT_PORT)
150
- end
151
- end
152
-
153
- it "should find all variations of the same uri for all variations of https uris" do
154
- URIS_FOR_HTTPS.each do |uri|
155
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_HTTPS)
156
- end
157
- end
158
-
159
- it "should find all variations of the same uri for all variations of host names uris without a period" do
160
- URIS_FOR_LOCALHOST.each do |uri|
161
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_LOCALHOST)
162
- end
163
- end
164
-
165
- it "should find all variations of the same uri with scheme for all variations when only_with_scheme is true" do
166
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
167
- variations_of_uri_with_scheme = WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true)
168
- expect(variations_of_uri_with_scheme.sort).to eq(URIS_WITH_SCHEME)
169
- end
170
- end
171
-
172
- it "should not replace :80 or :443 in path" do
173
- URIS_WITH_COLON_IN_PATH.each do |uris|
174
- uris.each do |uri|
175
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(uris)
176
- end
177
- end
178
- end
179
-
180
- it "should find all variations of uris with https, basic auth, a non-standard port and a path" do
181
- uri = "https://~%8A:pass@www.example.com:9000/foo"
182
- variations = [
183
- "https://~%8A:pass@www.example.com:9000/foo",
184
- "https://~\x8A:pass@www.example.com:9000/foo".force_encoding(Encoding::ASCII_8BIT)
185
- ]
186
-
187
- expect(WebMock::Util::URI.variations_of_uri_as_strings(uri)).to eq(variations)
188
- end
189
-
190
- end
191
-
192
- describe "normalized uri equality" do
193
-
194
- it "should successfully compare all variations of the same uri with path and params" do
195
- URIS_WITH_PATH_AND_PARAMS.each do |uri_a|
196
- URIS_WITH_PATH_AND_PARAMS.each do |uri_b|
197
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
198
- end
199
- end
200
- end
201
-
202
- it "should successfully compare all variations of the same uri with path but with params" do
203
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_a|
204
- URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_b|
205
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
206
- end
207
- end
208
- end
209
-
210
- it "should successfully compare all variations of the same uri without path or params" do
211
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_a|
212
- URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_b|
213
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
214
- end
215
- end
216
- end
217
-
218
- it "should successfully compare all variations of the same uri with authority" do
219
- URIS_WITH_AUTH.each do |uri_a|
220
- URIS_WITH_AUTH.each do |uri_b|
221
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
222
- end
223
- end
224
- end
225
-
226
- it "should successfully compare all variations of the same uri custom port" do
227
- URIS_WITH_DIFFERENT_PORT.each do |uri_a|
228
- URIS_WITH_DIFFERENT_PORT.each do |uri_b|
229
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
230
- end
231
- end
232
- end
233
-
234
- it "should successfully compare all variations of the same https uri" do
235
- URIS_FOR_HTTPS.each do |uri_a|
236
- URIS_FOR_HTTPS.each do |uri_b|
237
- expect(WebMock::Util::URI.normalize_uri(uri_a)).to be === WebMock::Util::URI.normalize_uri(uri_b)
238
- end
239
- end
240
- end
241
-
242
- it "should successfully handle array parameters" do
243
- uri_string = 'http://www.example.com:80/path?a[]=b&a[]=c'
244
- uri = WebMock::Util::URI.normalize_uri(uri_string)
245
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"a"=>["b", "c"]})
246
- end
247
-
248
- it "should successfully handle hash parameters" do
249
- uri_string = 'http://www.example.com:80/path?a[d]=b&a[e]=c&a[b][c]=1'
250
- uri = WebMock::Util::URI.normalize_uri(uri_string)
251
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"a"=>{"d"=>"b", "e"=>"c", "b"=>{"c"=>"1"}}})
252
- end
253
-
254
- it "should successfully handle nested hash parameters" do
255
- uri_string = 'http://www.example.com:80/path?one[two][three][]=four&one[two][three][]=five'
256
- uri = WebMock::Util::URI.normalize_uri(uri_string)
257
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"one"=>{"two"=>{"three" => ["four", "five"]}}})
258
- end
259
-
260
- it "should successfully handle mixed array and hash parameters" do
261
- # derived from an elasticsearch query:
262
- # load => {
263
- # :include => [
264
- # { :staff => :email },
265
- # :business_name
266
- # ]
267
- # }
268
- uri_string = "http://www.example.com:80/path?load[include][][staff]=email&load[include][]=business_name"
269
- uri = WebMock::Util::URI.normalize_uri(uri_string)
270
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query)).to eq({"load"=>{"include"=>[{"staff"=>"email"},"business_name"]}})
271
- end
272
-
273
- context "when query notation is set to :flat_array" do
274
- before :all do
275
- WebMock::Config.instance.query_values_notation = :flat_array
276
- end
277
-
278
- it "should successfully handle repeated paramters" do
279
- uri_string = "http://www.example.com:80/path?target=host1&target=host2"
280
- uri = WebMock::Util::URI.normalize_uri(uri_string)
281
- expect(WebMock::Util::QueryMapper.query_to_values(uri.query, notation: WebMock::Config.instance.query_values_notation)).to eq([['target', 'host1'], ['target', 'host2']])
282
- end
283
- end
284
- end
285
-
286
- describe "sorting query values" do
287
-
288
- context "when query values is a Hash" do
289
- it "returns an alphabetically sorted hash" do
290
- sorted_query = WebMock::Util::URI.sort_query_values({"b"=>"one", "a"=>"two"})
291
- expect(sorted_query).to eq({"a"=>"two", "b"=>"one"})
292
- end
293
- end
294
-
295
- context "when query values is an Array" do
296
- it "returns an alphabetically sorted array" do
297
- sorted_query = WebMock::Util::URI.sort_query_values([["b","two"],["a","one_b"],["a","one_a"]])
298
- expect(sorted_query).to eq([["a","one_a"],["a","one_b"],["b","two"]])
299
- end
300
- end
301
- end
302
-
303
- describe "stripping default port" do
304
-
305
- it "should strip_default_port_from_uri strips 80 from http with path" do
306
- uri = "http://example.com:80/foo/bar"
307
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
308
- expect(stripped_uri).to eq("http://example.com/foo/bar")
309
- end
310
-
311
- it "should strip_default_port_from_uri strips 80 from http without path" do
312
- uri = "http://example.com:80"
313
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
314
- expect(stripped_uri).to eq("http://example.com")
315
- end
316
-
317
- it "should strip_default_port_from_uri strips 443 from https without path" do
318
- uri = "https://example.com:443"
319
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
320
- expect(stripped_uri).to eq("https://example.com")
321
- end
322
-
323
- it "should strip_default_port_from_uri strips 443 from https" do
324
- uri = "https://example.com:443/foo/bar"
325
- stripped_uri = WebMock::Util::URI.strip_default_port_from_uri_string(uri)
326
- expect(stripped_uri).to eq("https://example.com/foo/bar")
327
- end
328
-
329
- it "should strip_default_port_from_uri does not strip 8080 from http" do
330
- uri = "http://example.com:8080/foo/bar"
331
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
332
- end
333
-
334
- it "should strip_default_port_from_uri does not strip 443 from http" do
335
- uri = "http://example.com:443/foo/bar"
336
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
337
- end
338
-
339
- it "should strip_default_port_from_uri does not strip 80 from query string" do
340
- uri = "http://example.com/?a=:80&b=c"
341
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
342
- end
343
-
344
- it "should strip_default_port_from_uri does not modify strings that do not start with http or https" do
345
- uri = "httpz://example.com:80/"
346
- expect(WebMock::Util::URI.strip_default_port_from_uri_string(uri)).to eq(uri)
347
- end
348
-
349
- end
350
-
351
-
352
- describe "encoding userinfo" do
353
-
354
- it "should encode unsafe chars in userinfo does not encode userinfo safe punctuation" do
355
- userinfo = "user;&=+$,:secret"
356
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(userinfo)
357
- end
358
-
359
- it "should encode unsafe chars in userinfo does not encode rfc 3986 unreserved characters" do
360
- userinfo = "-.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
361
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(userinfo)
362
- end
363
-
364
- it "should encode unsafe chars in userinfo does encode other characters" do
365
- userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
366
- expect(WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)).to eq(safe_userinfo)
367
- end
368
-
369
- end
370
-
371
- 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,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "WebMock" do
4
-
5
- describe ".version" do
6
- it "should report version" do
7
- expect(WebMock.version).to eq(WebMock::VERSION)
8
- end
9
-
10
- it "should not require safe_yaml" do
11
- expect(defined?SafeYAML).to eq(nil)
12
- end
13
-
14
- it "should alias enable_net_connect! to allow_net_connect!" do
15
- expect(WebMock.method(:enable_net_connect!)).to eq(WebMock.method(:allow_net_connect!))
16
- end
17
-
18
- it "should alias disallow_net_connect! to disable_net_connect!" do
19
- expect(WebMock.method(:disallow_net_connect!)).to eq(WebMock.method(:disable_net_connect!))
20
- end
21
- end
22
-
23
- describe ".net_connect_allowed?" do
24
- context 'enabled globally' do
25
- before do
26
- WebMock.enable_net_connect!
27
- end
28
-
29
- context 'without arguments' do
30
- it 'returns WebMock::Config.instance.allow_net_connect' do
31
- expect(WebMock.net_connect_allowed?).to eql(true)
32
- end
33
- end
34
- end
35
-
36
- context 'disabled with allowed remote string' do
37
- before do
38
- WebMock.disable_net_connect!(allow: "http://192.168.64.2:20031")
39
- end
40
-
41
- context 'without arguments' do
42
- it 'returns WebMock::Config.instance.allow_net_connect' do
43
- expect(WebMock.net_connect_allowed?).to eql(false)
44
- end
45
- end
46
- end
47
-
48
- context 'disabled globally' do
49
- before do
50
- WebMock.disable_net_connect!
51
- end
52
-
53
- context 'without arguments' do
54
- it 'returns WebMock::Config.instance.allow_net_connect' do
55
- expect(WebMock.net_connect_allowed?).to eql(false)
56
- end
57
- end
58
- end
59
- end
60
- 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