webmock 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +2 -7
  4. data/README.md +54 -53
  5. data/Rakefile +1 -1
  6. data/lib/webmock/callback_registry.rb +1 -1
  7. data/lib/webmock/http_lib_adapters/curb_adapter.rb +68 -6
  8. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +4 -4
  9. data/lib/webmock/http_lib_adapters/excon_adapter.rb +9 -9
  10. data/lib/webmock/http_lib_adapters/http_rb/request.rb +2 -2
  11. data/lib/webmock/http_lib_adapters/http_rb/response.rb +5 -5
  12. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +3 -3
  13. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +5 -5
  14. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +7 -7
  15. data/lib/webmock/http_lib_adapters/net_http.rb +3 -3
  16. data/lib/webmock/http_lib_adapters/patron_adapter.rb +4 -4
  17. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +14 -14
  18. data/lib/webmock/matchers/hash_including_matcher.rb +1 -1
  19. data/lib/webmock/rack_response.rb +3 -3
  20. data/lib/webmock/request_pattern.rb +8 -8
  21. data/lib/webmock/request_stub.rb +5 -5
  22. data/lib/webmock/util/uri.rb +2 -2
  23. data/lib/webmock/version.rb +1 -1
  24. data/minitest/webmock_spec.rb +3 -3
  25. data/spec/acceptance/curb/curb_spec.rb +64 -47
  26. data/spec/acceptance/curb/curb_spec_helper.rb +4 -4
  27. data/spec/acceptance/em_http_request/em_http_request_spec.rb +32 -32
  28. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +9 -9
  29. data/spec/acceptance/excon/excon_spec.rb +14 -14
  30. data/spec/acceptance/excon/excon_spec_helper.rb +6 -6
  31. data/spec/acceptance/http_rb/http_rb_spec.rb +1 -1
  32. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +7 -7
  33. data/spec/acceptance/httpclient/httpclient_spec.rb +20 -20
  34. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +5 -5
  35. data/spec/acceptance/manticore/manticore_spec.rb +11 -11
  36. data/spec/acceptance/manticore/manticore_spec_helper.rb +3 -3
  37. data/spec/acceptance/net_http/net_http_shared.rb +4 -4
  38. data/spec/acceptance/net_http/net_http_spec.rb +25 -25
  39. data/spec/acceptance/net_http/net_http_spec_helper.rb +4 -4
  40. data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
  41. data/spec/acceptance/patron/patron_spec.rb +10 -10
  42. data/spec/acceptance/patron/patron_spec_helper.rb +5 -5
  43. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +36 -36
  44. data/spec/acceptance/shared/callbacks.rb +11 -11
  45. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +5 -5
  46. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +4 -4
  47. data/spec/acceptance/shared/precedence_of_stubs.rb +4 -4
  48. data/spec/acceptance/shared/request_expectations.rb +90 -90
  49. data/spec/acceptance/shared/returning_declared_responses.rb +49 -49
  50. data/spec/acceptance/shared/stubbing_requests.rb +78 -78
  51. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +11 -11
  52. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +8 -8
  53. data/spec/spec_helper.rb +6 -3
  54. data/spec/support/webmock_server.rb +1 -1
  55. data/spec/unit/api_spec.rb +2 -2
  56. data/spec/unit/errors_spec.rb +3 -3
  57. data/spec/unit/matchers/hash_including_matcher_spec.rb +16 -16
  58. data/spec/unit/rack_response_spec.rb +2 -2
  59. data/spec/unit/request_body_diff_spec.rb +1 -1
  60. data/spec/unit/request_execution_verifier_spec.rb +1 -1
  61. data/spec/unit/request_pattern_spec.rb +115 -115
  62. data/spec/unit/request_signature_snippet_spec.rb +2 -2
  63. data/spec/unit/request_signature_spec.rb +16 -16
  64. data/spec/unit/request_stub_spec.rb +20 -20
  65. data/spec/unit/response_spec.rb +28 -28
  66. data/spec/unit/stub_registry_spec.rb +10 -10
  67. data/spec/unit/stub_request_snippet_spec.rb +6 -6
  68. data/spec/unit/util/hash_keys_stringifier_spec.rb +4 -4
  69. data/spec/unit/util/query_mapper_spec.rb +2 -2
  70. data/spec/unit/util/uri_spec.rb +1 -1
  71. data/test/http_request.rb +3 -3
  72. data/test/shared_test.rb +6 -6
  73. data/webmock.gemspec +4 -2
  74. metadata +32 -4
@@ -18,11 +18,11 @@ module EMHttpRequestSpecHelper
18
18
  EventMachine.run {
19
19
  request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}")
20
20
  http = request.send(method, {
21
- :timeout => 30,
22
- :body => options[:body],
23
- :file => options[:file],
24
- :query => options[:query],
25
- :head => head
21
+ timeout: 30,
22
+ body: options[:body],
23
+ file: options[:file],
24
+ query: options[:query],
25
+ head: head
26
26
  }, &block)
27
27
  http.errback {
28
28
  error_set = true
@@ -35,10 +35,10 @@ module EMHttpRequestSpecHelper
35
35
  }
36
36
  http.callback {
37
37
  response = OpenStruct.new({
38
- :body => http.response,
39
- :headers => WebMock::Util::Headers.normalize_headers(extract_response_headers(http)),
40
- :message => http.response_header.http_reason,
41
- :status => http.response_header.status.to_s
38
+ body: http.response,
39
+ headers: WebMock::Util::Headers.normalize_headers(extract_response_headers(http)),
40
+ message: http.response_header.http_reason,
41
+ status: http.response_header.status.to_s
42
42
  })
43
43
  EventMachine.stop
44
44
  }
@@ -7,40 +7,40 @@ describe "Excon" do
7
7
  include_context "with WebMock", :no_status_message, :no_url_auth
8
8
 
9
9
  it 'should allow Excon requests to use query hash paramters' do
10
- stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(:body => "abc")
11
- expect(Excon.new('http://example.com').get(:path => "resource/", :query => {:a => 1, :b => 2}).body).to eq("abc")
10
+ stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(body: "abc")
11
+ expect(Excon.new('http://example.com').get(path: "resource/", query: {a: 1, b: 2}).body).to eq("abc")
12
12
  end
13
13
 
14
14
  it 'should support Excon :expects options' do
15
- stub_request(:get, "http://example.com/").to_return(:body => 'a')
16
- expect { Excon.new('http://example.com').get(:expects => 204) }.to raise_error(Excon::Errors::OK)
15
+ stub_request(:get, "http://example.com/").to_return(body: 'a')
16
+ expect { Excon.new('http://example.com').get(expects: 204) }.to raise_error(Excon::Errors::OK)
17
17
  end
18
18
 
19
19
  context "with response_block" do
20
- it "should support excon response_block for real requests", :net_connect => true do
20
+ it "should support excon response_block for real requests", net_connect: true do
21
21
  a = []
22
22
  WebMock.allow_net_connect!
23
- r = Excon.new('http://httpstat.us/200').get(:response_block => lambda {|e, remaining, total| a << e}, :chunk_size => 1)
23
+ r = Excon.new('http://httpstat.us/200').get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
24
24
  expect(a).to eq(["2", "0", "0", " ", "O", "K"])
25
25
  expect(r.body).to eq("")
26
26
  end
27
27
 
28
28
  it "should support excon response_block" do
29
29
  a = []
30
- stub_request(:get, "http://example.com/").to_return(:body => "abc")
31
- r = Excon.new('http://example.com').get(:response_block => lambda {|e, remaining, total| a << e}, :chunk_size => 1)
30
+ stub_request(:get, "http://example.com/").to_return(body: "abc")
31
+ r = Excon.new('http://example.com').get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
32
32
  expect(a).to eq(['a', 'b', 'c'])
33
33
  expect(r.body).to eq("")
34
34
  end
35
35
 
36
- it "should invoke callbacks with response body even if a real request is made", :net_connect => true do
36
+ it "should invoke callbacks with response body even if a real request is made", net_connect: true do
37
37
  a = []
38
38
  WebMock.allow_net_connect!
39
39
  response = nil
40
40
  WebMock.after_request { |_, res|
41
41
  response = res
42
42
  }
43
- r = Excon.new('http://httpstat.us/200').get(:response_block => lambda {|e, remaining, total| a << e}, :chunk_size => 1)
43
+ r = Excon.new('http://httpstat.us/200').get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
44
44
  expect(response.body).to eq("200 OK")
45
45
  expect(a).to eq(["2", "0", "0", " ", "O", "K"])
46
46
  expect(r.body).to eq("")
@@ -51,14 +51,14 @@ describe "Excon" do
51
51
  let(:file_contents) { File.read(__FILE__) }
52
52
 
53
53
  it 'handles file uploads correctly' do
54
- stub_request(:put, "http://example.com/upload").with(:body => file_contents)
54
+ stub_request(:put, "http://example.com/upload").with(body: file_contents)
55
55
 
56
56
  yielded_request_body = nil
57
57
  WebMock.after_request do |req, res|
58
58
  yielded_request_body = req.body
59
59
  end
60
60
 
61
- Excon.new("http://example.com").put(:path => "upload", :body => file)
61
+ Excon.new("http://example.com").put(path: "upload", body: file)
62
62
 
63
63
  expect(yielded_request_body).to eq(file_contents)
64
64
  end
@@ -66,8 +66,8 @@ describe "Excon" do
66
66
  describe '.request_params_from' do
67
67
 
68
68
  it 'rejects invalid request keys' do
69
- request_params = WebMock::HttpLibAdapters::ExconAdapter.request_params_from(:body => :keep, :fake => :reject)
70
- expect(request_params).to eq(:body => :keep)
69
+ request_params = WebMock::HttpLibAdapters::ExconAdapter.request_params_from(body: :keep, fake: :reject)
70
+ expect(request_params).to eq(body: :keep)
71
71
  end
72
72
 
73
73
  end
@@ -14,10 +14,10 @@ module ExconSpecHelper
14
14
  end
15
15
 
16
16
  if Gem::Version.new(Excon::VERSION) < Gem::Version.new("0.29.0")
17
- options = options.merge(:method => method, :nonblock => false) # Dup and merge
17
+ options = options.merge(method: method, nonblock: false) # Dup and merge
18
18
  response = Excon.new(uri, excon_options).request(options, &block)
19
19
  else
20
- options = options.merge(:method => method) # Dup and merge
20
+ options = options.merge(method: method) # Dup and merge
21
21
  response = Excon.new(uri, excon_options.merge(nonblock: false)).request(options, &block)
22
22
  end
23
23
 
@@ -28,10 +28,10 @@ module ExconSpecHelper
28
28
  end
29
29
 
30
30
  OpenStruct.new \
31
- :body => response.body,
32
- :headers => headers,
33
- :status => response.status.to_s,
34
- :message => ""
31
+ body: response.body,
32
+ headers: headers,
33
+ status: response.status.to_s,
34
+ message: ""
35
35
  end
36
36
 
37
37
  def client_timeout_exception_class
@@ -36,7 +36,7 @@ describe "HTTP.rb" do
36
36
  end
37
37
 
38
38
  context "following redirects" do
39
- let(:options) { { :follow => true } }
39
+ let(:options) { { follow: true } }
40
40
  let(:response) { http_request(:get, "http://example.com", options) }
41
41
  let(:headers) { response.headers }
42
42
 
@@ -11,10 +11,10 @@ module HttpRbSpecHelper
11
11
  response = chain.request(method, normalize_uri(uri), options)
12
12
 
13
13
  OpenStruct.new({
14
- :body => response.body.to_s,
15
- :headers => normalize_headers(response.headers.to_h),
16
- :status => response.code.to_s,
17
- :message => response.reason
14
+ body: response.body.to_s,
15
+ headers: normalize_headers(response.headers.to_h),
16
+ status: response.code.to_s,
17
+ message: response.reason
18
18
  })
19
19
  end
20
20
 
@@ -43,9 +43,9 @@ module HttpRbSpecHelper
43
43
 
44
44
  def stub_simple_request(host, status = 200, headers = {}, body = nil)
45
45
  stub_request(:any, host).to_return({
46
- :status => status,
47
- :headers => headers.merge({ "Host" => host }),
48
- :body => body
46
+ status: status,
47
+ headers: headers.merge({ "Host" => host }),
48
+ body: body
49
49
  })
50
50
  end
51
51
  end
@@ -15,15 +15,15 @@ describe "HTTPClient" do
15
15
  include_examples "with WebMock"
16
16
 
17
17
  it "should raise a clearly readable error if request with multipart body is sent" do
18
- stub_request(:post, 'www.example.com').with(:body => {:type => 'image'})
18
+ stub_request(:post, 'www.example.com').with(body: {type: 'image'})
19
19
 
20
20
  expect {
21
- HTTPClient.new.post_content('www.example.com', :type => 'image', :file => File.new('spec/fixtures/test.txt'))
21
+ HTTPClient.new.post_content('www.example.com', type: 'image', file: File.new('spec/fixtures/test.txt'))
22
22
  }.to raise_error(ArgumentError, "WebMock does not support matching body for multipart/form-data requests yet :(")
23
23
  end
24
24
 
25
25
  it "should yield block on response if block provided" do
26
- stub_request(:get, "www.example.com").to_return(:body => "abc")
26
+ stub_request(:get, "www.example.com").to_return(body: "abc")
27
27
  response_body = ""
28
28
  http_request(:get, "http://www.example.com/") do |body|
29
29
  response_body = body
@@ -32,10 +32,10 @@ describe "HTTPClient" do
32
32
  end
33
33
 
34
34
  it "should match requests if headers are the same but in different order" do
35
- stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
35
+ stub_request(:get, "www.example.com").with(headers: {"a" => ["b", "c"]} )
36
36
  expect(http_request(
37
37
  :get, "http://www.example.com/",
38
- :headers => {"a" => ["c", "b"]}).status).to eq("200")
38
+ headers: {"a" => ["c", "b"]}).status).to eq("200")
39
39
  end
40
40
 
41
41
  describe "when using async requests" do
@@ -47,7 +47,7 @@ describe "HTTPClient" do
47
47
  end
48
48
 
49
49
  it "should work with get_content" do
50
- stub_request(:get, 'www.example.com').to_return(:status => 200, :body => 'test', :headers => {})
50
+ stub_request(:get, 'www.example.com').to_return(status: 200, body: 'test', headers: {})
51
51
  str = ''
52
52
  HTTPClient.get_content('www.example.com') do |content|
53
53
  str << content
@@ -57,9 +57,9 @@ describe "HTTPClient" do
57
57
 
58
58
  it "should work via JSONClient subclass" do
59
59
  stub_request(:get, 'www.example.com').to_return(
60
- :status => 200,
61
- :body => '{"test": "foo"}',
62
- :headers => {'Content-Type' => 'application/json'}
60
+ status: 200,
61
+ body: '{"test": "foo"}',
62
+ headers: {'Content-Type' => 'application/json'}
63
63
  )
64
64
  content = JSONClient.get('www.example.com').content
65
65
  expect(content).to eq("test" => "foo")
@@ -79,7 +79,7 @@ describe "HTTPClient" do
79
79
  }
80
80
  ]}
81
81
 
82
- let(:make_request) {HTTPClient.new.post("http://www.example.com", :body => body, :header => header)}
82
+ let(:make_request) {HTTPClient.new.post("http://www.example.com", body: body, header: header)}
83
83
 
84
84
  before do
85
85
  stub_request(:post, "www.example.com")
@@ -105,7 +105,7 @@ describe "HTTPClient" do
105
105
  before do
106
106
  @client = HTTPClient.new
107
107
  @client.request_filter << Filter.new
108
- stub_request(:get, 'www.example.com').with(:headers => {'Authorization' => 'Bearer 0123456789'})
108
+ stub_request(:get, 'www.example.com').with(headers: {'Authorization' => 'Bearer 0123456789'})
109
109
  end
110
110
 
111
111
  it "supports request filters" do
@@ -131,13 +131,13 @@ describe "HTTPClient" do
131
131
  nil # to let the request be made for real
132
132
  end
133
133
 
134
- http_request(:get, webmock_server_url, :client => client, :headers => { "Cookie" => "bar=; foo=" })
134
+ http_request(:get, webmock_server_url, client: client, headers: { "Cookie" => "bar=; foo=" })
135
135
 
136
136
  if defined? HTTP::CookieJar
137
- http_request(:get, webmock_server_url, :client => client, :headers => { "Cookie" => "bar=; foo=" })
137
+ http_request(:get, webmock_server_url, client: client, headers: { "Cookie" => "bar=; foo=" })
138
138
  else
139
139
  # If http-cookie is not present, then the cookie headers will saved between requests
140
- http_request(:get, webmock_server_url, :client => client)
140
+ http_request(:get, webmock_server_url, client: client)
141
141
  end
142
142
 
143
143
  expect(request_signatures.size).to eq(2)
@@ -149,8 +149,8 @@ describe "HTTPClient" do
149
149
  context 'session headers' do
150
150
  it "client sends a User-Agent header when given an agent_name explicitly to the client" do
151
151
  user_agent = "Client/0.1"
152
- stub_request(:get, "www.example.com").with(:headers => { 'User-agent' => "#{user_agent} #{HTTPClient::LIB_NAME}" })
153
- HTTPClient.new(:agent_name => user_agent).get("www.example.com")
152
+ stub_request(:get, "www.example.com").with(headers: { 'User-agent' => "#{user_agent} #{HTTPClient::LIB_NAME}" })
153
+ HTTPClient.new(agent_name: user_agent).get("www.example.com")
154
154
  end
155
155
 
156
156
  it "client sends the Accept, User-Agent, and Date by default" do
@@ -165,7 +165,7 @@ describe "HTTPClient" do
165
165
 
166
166
  it "explicitly defined headers take precedence over session defaults" do
167
167
  headers = { 'Accept' => 'foo/bar', 'User-Agent' => 'custom', 'Date' => 'today' }
168
- stub_request(:get, "www.example.com").with(:headers => headers)
168
+ stub_request(:get, "www.example.com").with(headers: headers)
169
169
  HTTPClient.new.get("www.example.com", nil, headers)
170
170
  end
171
171
  end
@@ -181,7 +181,7 @@ describe "HTTPClient" do
181
181
  context 'httpclient streams response' do
182
182
  before do
183
183
  WebMock.allow_net_connect!
184
- WebMock.after_request(:except => [:other_lib]) do |_, response|
184
+ WebMock.after_request(except: [:other_lib]) do |_, response|
185
185
  @response = response
186
186
  end
187
187
  end
@@ -197,9 +197,9 @@ describe "HTTPClient" do
197
197
 
198
198
  context 'credentials' do
199
199
  it 'are detected when manually specifying Authorization header' do
200
- stub_request(:get, 'username:password@www.example.com').to_return(:status => 200)
200
+ stub_request(:get, 'username:password@www.example.com').to_return(status: 200)
201
201
  headers = {'Authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='}
202
- expect(http_request(:get, 'http://www.example.com/', {:headers => headers}).status).to eql('200')
202
+ expect(http_request(:get, 'http://www.example.com/', {headers: headers}).status).to eql('200')
203
203
  end
204
204
  end
205
205
  end
@@ -12,7 +12,7 @@ module HTTPClientSpecHelper
12
12
  c.set_basic_auth(nil, options[:basic_auth][0], options[:basic_auth][1])
13
13
  end
14
14
  params = [method, uri.normalize.to_s,
15
- WebMock::Util::QueryMapper.query_to_values(uri.query, :notation => WebMock::Config.instance.query_values_notation), options[:body], options[:headers] || {}]
15
+ WebMock::Util::QueryMapper.query_to_values(uri.query, notation: WebMock::Config.instance.query_values_notation), options[:body], options[:headers] || {}]
16
16
  if HTTPClientSpecHelper.async_mode
17
17
  connection = c.request_async(*params)
18
18
  connection.join
@@ -22,10 +22,10 @@ module HTTPClientSpecHelper
22
22
  end
23
23
  headers = merge_headers(response)
24
24
  OpenStruct.new({
25
- :body => HTTPClientSpecHelper.async_mode ? response.content.read : response.content,
26
- :headers => headers,
27
- :status => response.code.to_s,
28
- :message => response.reason
25
+ body: HTTPClientSpecHelper.async_mode ? response.content.read : response.content,
26
+ headers: headers,
27
+ status: response.code.to_s,
28
+ message: response.reason
29
29
  })
30
30
  end
31
31
 
@@ -11,43 +11,43 @@ if RUBY_PLATFORM =~ /java/
11
11
 
12
12
  context "calling http methods on Manticore directly using Manticore's facade" do
13
13
  it "handles GET" do
14
- stub_request(:get, "http://example-foo.com").to_return(:status => 301)
14
+ stub_request(:get, "http://example-foo.com").to_return(status: 301)
15
15
  response = Manticore.get("http://example-foo.com")
16
16
  expect(response.code).to eq(301)
17
17
  end
18
18
 
19
19
  it "handles POST" do
20
- stub_request(:post, "http://example-foo.com").to_return(:status => 201)
21
- response = Manticore.post("http://example-foo.com", {:hello => "world"})
20
+ stub_request(:post, "http://example-foo.com").to_return(status: 201)
21
+ response = Manticore.post("http://example-foo.com", {hello: "world"})
22
22
  expect(response.code).to eq(201)
23
23
  end
24
24
 
25
25
  it "handles PUT" do
26
- stub_request(:put, "http://example-foo.com").to_return(:status => 409)
27
- response = Manticore.put("http://example-foo.com", {:hello => "world"})
26
+ stub_request(:put, "http://example-foo.com").to_return(status: 409)
27
+ response = Manticore.put("http://example-foo.com", {hello: "world"})
28
28
  expect(response.code).to eq(409)
29
29
  end
30
30
 
31
31
  it "handles PATCH" do
32
- stub_request(:patch, "http://example-foo.com").to_return(:status => 409)
33
- response = Manticore.patch("http://example-foo.com", {:hello => "world"})
32
+ stub_request(:patch, "http://example-foo.com").to_return(status: 409)
33
+ response = Manticore.patch("http://example-foo.com", {hello: "world"})
34
34
  expect(response.code).to eq(409)
35
35
  end
36
36
 
37
37
  it "handles DELETE" do
38
- stub_request(:delete, "http://example-foo.com").to_return(:status => 204)
39
- response = Manticore.delete("http://example-foo.com", {:id => 1})
38
+ stub_request(:delete, "http://example-foo.com").to_return(status: 204)
39
+ response = Manticore.delete("http://example-foo.com", {id: 1})
40
40
  expect(response.code).to eq(204)
41
41
  end
42
42
 
43
43
  it "handles OPTIONS" do
44
- stub_request(:options, "http://example-foo.com").to_return(:status => 200)
44
+ stub_request(:options, "http://example-foo.com").to_return(status: 200)
45
45
  response = Manticore.options("http://example-foo.com")
46
46
  expect(response.code).to eq(200)
47
47
  end
48
48
 
49
49
  it "handles HEAD" do
50
- stub_request(:head, "http://example-foo.com").to_return(:status => 204)
50
+ stub_request(:head, "http://example-foo.com").to_return(status: 204)
51
51
  response = Manticore.head("http://example-foo.com")
52
52
  expect(response.code).to eq(204)
53
53
  end
@@ -8,9 +8,9 @@ module ManticoreSpecHelper
8
8
 
9
9
  response = client.http(method, uri, options)
10
10
  OpenStruct.new({
11
- :body => response.body || '',
12
- :headers => WebMock::Util::Headers.normalize_headers(join_array_values(response.headers)),
13
- :status => response.code.to_s
11
+ body: response.body || '',
12
+ headers: WebMock::Util::Headers.normalize_headers(join_array_values(response.headers)),
13
+ status: response.code.to_s
14
14
  })
15
15
  end
16
16
 
@@ -1,17 +1,17 @@
1
1
  shared_examples_for "Net::HTTP" do
2
- describe "when making real requests", :net_connect => true do
2
+ describe "when making real requests", net_connect: true do
3
3
  let(:port){ WebMockServer.instance.port }
4
4
 
5
5
  before(:each) do
6
6
  @http = Net::HTTP.new("localhost", port)
7
7
  end
8
8
 
9
- it "should return a Net::ReadAdapter from response.body when a real request is made with a block and #read_body", :net_connect => true do
9
+ it "should return a Net::ReadAdapter from response.body when a real request is made with a block and #read_body", net_connect: true do
10
10
  response = Net::HTTP.new("localhost", port).request_get('/') { |r| r.read_body { } }
11
11
  expect(response.body).to be_a(Net::ReadAdapter)
12
12
  end
13
13
 
14
- it "should handle requests with block passed to read_body", :net_connect => true do
14
+ it "should handle requests with block passed to read_body", net_connect: true do
15
15
  body = ""
16
16
  req = Net::HTTP::Get.new("/")
17
17
  Net::HTTP.start("localhost", port) do |http|
@@ -24,7 +24,7 @@ shared_examples_for "Net::HTTP" do
24
24
  expect(body).to match(/hello world/)
25
25
  end
26
26
 
27
- it "should connect only once when connected on start", :net_connect => true do
27
+ it "should connect only once when connected on start", net_connect: true do
28
28
  @http = Net::HTTP.new('localhost', port)
29
29
  socket_id_before_request = socket_id_after_request = nil
30
30
  @http.start {|conn|
@@ -102,13 +102,13 @@ describe "Net:HTTP" do
102
102
  end
103
103
 
104
104
  it "should work with block provided" do
105
- stub_http_request(:get, "www.example.com").to_return(:body => "abc"*100000)
105
+ stub_http_request(:get, "www.example.com").to_return(body: "abc"*100000)
106
106
  expect(Net::HTTP.start("www.example.com") { |query| query.get("/") }.body).to eq("abc"*100000)
107
107
  end
108
108
 
109
109
  it "should handle requests with raw binary data" do
110
110
  body = "\x14\x00\x00\x00\x70\x69\x6e\x67\x00\x00"
111
- stub_http_request(:post, "www.example.com").with(:body => body).to_return(:body => "abc")
111
+ stub_http_request(:post, "www.example.com").with(body: body).to_return(body: "abc")
112
112
  req = Net::HTTP::Post.new("/")
113
113
  req.body = body
114
114
  req.content_type = "application/octet-stream"
@@ -128,7 +128,7 @@ describe "Net:HTTP" do
128
128
  request[:InvalidHeaderSinceItsASymbol] = "this will not be valid"
129
129
  else
130
130
  request.instance_eval do
131
- @header = request.to_hash.merge({:InvalidHeaderSinceItsASymbol => "this will not be valid"})
131
+ @header = request.to_hash.merge({InvalidHeaderSinceItsASymbol: "this will not be valid"})
132
132
  end
133
133
  end
134
134
 
@@ -145,13 +145,13 @@ describe "Net:HTTP" do
145
145
  end
146
146
 
147
147
  it "should handle multiple values for the same response header" do
148
- stub_http_request(:get, "www.example.com").to_return(:headers => { 'Set-Cookie' => ['foo=bar', 'bar=bazz'] })
148
+ stub_http_request(:get, "www.example.com").to_return(headers: { 'Set-Cookie' => ['foo=bar', 'bar=bazz'] })
149
149
  response = Net::HTTP.get_response(URI.parse("http://www.example.com/"))
150
150
  expect(response.get_fields('Set-Cookie')).to eq(['bar=bazz', 'foo=bar'])
151
151
  end
152
152
 
153
153
  it "should yield block on response" do
154
- stub_http_request(:get, "www.example.com").to_return(:body => "abc")
154
+ stub_http_request(:get, "www.example.com").to_return(body: "abc")
155
155
  response_body = ""
156
156
  http_request(:get, "http://www.example.com/") do |response|
157
157
  response_body = response.body
@@ -160,21 +160,21 @@ describe "Net:HTTP" do
160
160
  end
161
161
 
162
162
  it "should handle Net::HTTP::Post#body" do
163
- stub_http_request(:post, "www.example.com").with(:body => "my_params").to_return(:body => "abc")
163
+ stub_http_request(:post, "www.example.com").with(body: "my_params").to_return(body: "abc")
164
164
  req = Net::HTTP::Post.new("/")
165
165
  req.body = "my_params"
166
166
  expect(Net::HTTP.start("www.example.com") { |http| http.request(req)}.body).to eq("abc")
167
167
  end
168
168
 
169
169
  it "should handle Net::HTTP::Post#body_stream" do
170
- stub_http_request(:post, "www.example.com").with(:body => "my_params").to_return(:body => "abc")
170
+ stub_http_request(:post, "www.example.com").with(body: "my_params").to_return(body: "abc")
171
171
  req = Net::HTTP::Post.new("/")
172
172
  req.body_stream = StringIO.new("my_params")
173
173
  expect(Net::HTTP.start("www.example.com") { |http| http.request(req)}.body).to eq("abc")
174
174
  end
175
175
 
176
176
  it "should behave like Net::HTTP and raise error if both request body and body argument are set" do
177
- stub_http_request(:post, "www.example.com").with(:body => "my_params").to_return(:body => "abc")
177
+ stub_http_request(:post, "www.example.com").with(body: "my_params").to_return(body: "abc")
178
178
  req = Net::HTTP::Post.new("/")
179
179
  req.body = "my_params"
180
180
  expect {
@@ -183,12 +183,12 @@ describe "Net:HTTP" do
183
183
  end
184
184
 
185
185
  it "should return a Net::ReadAdapter from response.body when a stubbed request is made with a block and #read_body" do
186
- WebMock.stub_request(:get, 'http://example.com/').to_return(:body => "the body")
186
+ WebMock.stub_request(:get, 'http://example.com/').to_return(body: "the body")
187
187
  response = Net::HTTP.new('example.com', 80).request_get('/') { |r| r.read_body { } }
188
188
  expect(response.body).to be_a(Net::ReadAdapter)
189
189
  end
190
190
 
191
- it "should have request 1 time executed in registry after 1 real request", :net_connect => true do
191
+ it "should have request 1 time executed in registry after 1 real request", net_connect: true do
192
192
  WebMock.allow_net_connect!
193
193
  http = Net::HTTP.new('localhost', port)
194
194
  http.get('/') {}
@@ -197,7 +197,7 @@ describe "Net:HTTP" do
197
197
  end
198
198
 
199
199
  it "should work with Addressable::URI passed to Net::HTTP.get_response" do
200
- stub_request(:get, 'http://www.example.com/hello?a=1').to_return(:body => "abc")
200
+ stub_request(:get, 'http://www.example.com/hello?a=1').to_return(body: "abc")
201
201
  expect(Net::HTTP.get_response(Addressable::URI.parse('http://www.example.com/hello?a=1')).body).to eq("abc")
202
202
  end
203
203
 
@@ -209,15 +209,15 @@ describe "Net:HTTP" do
209
209
  end
210
210
 
211
211
  describe "when net http is allowed" do
212
- it "should not connect to the server until the request", :net_connect => true do
212
+ it "should not connect to the server until the request", net_connect: true do
213
213
  WebMock.allow_net_connect!
214
214
  @http.start {|conn|
215
215
  expect(conn.peer_cert).to be_nil
216
216
  }
217
217
  end
218
218
 
219
- it "should connect to the server on start", :net_connect => true do
220
- WebMock.allow_net_connect!(:net_http_connect_on_start => true)
219
+ it "should connect to the server on start", net_connect: true do
220
+ WebMock.allow_net_connect!(net_http_connect_on_start: true)
221
221
  @http.start {|conn|
222
222
  cert = OpenSSL::X509::Certificate.new conn.peer_cert
223
223
  expect(cert).to be_a(OpenSSL::X509::Certificate)
@@ -227,28 +227,28 @@ describe "Net:HTTP" do
227
227
  end
228
228
 
229
229
  describe "when net http is disabled and allowed only for some hosts" do
230
- it "should not connect to the server until the request", :net_connect => true do
231
- WebMock.disable_net_connect!(:allow => "www.google.com")
230
+ it "should not connect to the server until the request", net_connect: true do
231
+ WebMock.disable_net_connect!(allow: "www.google.com")
232
232
  @http.start {|conn|
233
233
  expect(conn.peer_cert).to be_nil
234
234
  }
235
235
  end
236
236
 
237
- it "should connect to the server on start", :net_connect => true do
238
- WebMock.disable_net_connect!(:allow => "www.google.com", :net_http_connect_on_start => true)
237
+ it "should connect to the server on start", net_connect: true do
238
+ WebMock.disable_net_connect!(allow: "www.google.com", net_http_connect_on_start: true)
239
239
  @http.start {|conn|
240
240
  cert = OpenSSL::X509::Certificate.new conn.peer_cert
241
241
  expect(cert).to be_a(OpenSSL::X509::Certificate)
242
242
  }
243
243
  end
244
244
 
245
- it "should connect to the server if the URI matches an regex", :net_connect => true do
246
- WebMock.disable_net_connect!(:allow => /google.com/)
245
+ it "should connect to the server if the URI matches an regex", net_connect: true do
246
+ WebMock.disable_net_connect!(allow: /google.com/)
247
247
  Net::HTTP.get('www.google.com','/')
248
248
  end
249
249
 
250
- it "should connect to the server if the URI matches any regex the array", :net_connect => true do
251
- WebMock.disable_net_connect!(:allow => [/google.com/, /yahoo.com/])
250
+ it "should connect to the server if the URI matches any regex the array", net_connect: true do
251
+ WebMock.disable_net_connect!(allow: [/google.com/, /yahoo.com/])
252
252
  Net::HTTP.get('www.google.com','/')
253
253
  end
254
254
 
@@ -258,19 +258,19 @@ describe "Net:HTTP" do
258
258
 
259
259
  describe "when net_http_connect_on_start is true" do
260
260
  before(:each) do
261
- WebMock.allow_net_connect!(:net_http_connect_on_start => true)
261
+ WebMock.allow_net_connect!(net_http_connect_on_start: true)
262
262
  end
263
263
  it_should_behave_like "Net::HTTP"
264
264
  end
265
265
 
266
266
  describe "when net_http_connect_on_start is false" do
267
267
  before(:each) do
268
- WebMock.allow_net_connect!(:net_http_connect_on_start => false)
268
+ WebMock.allow_net_connect!(net_http_connect_on_start: false)
269
269
  end
270
270
  it_should_behave_like "Net::HTTP"
271
271
  end
272
272
 
273
- describe 'after_request callback support', :net_connect => true do
273
+ describe 'after_request callback support', net_connect: true do
274
274
  let(:expected_body_regex) { /hello world/ }
275
275
 
276
276
  before(:each) do