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
@@ -19,7 +19,7 @@ shared_context "enabled and disabled webmock" do |*adapter_info|
19
19
 
20
20
  describe "when webmock is disabled except this lib" do
21
21
  before(:each) do
22
- WebMock.disable!(:except => [http_library])
22
+ WebMock.disable!(except: [http_library])
23
23
  end
24
24
  after(:each) do
25
25
  WebMock.enable!
@@ -30,7 +30,7 @@ shared_context "enabled and disabled webmock" do |*adapter_info|
30
30
  describe "when webmock is enabled except this lib" do
31
31
  before(:each) do
32
32
  WebMock.disable!
33
- WebMock.enable!(:except => [http_library])
33
+ WebMock.enable!(except: [http_library])
34
34
  end
35
35
  after(:each) do
36
36
  WebMock.enable!
@@ -52,7 +52,7 @@ shared_context "disabled WebMock" do
52
52
  end
53
53
 
54
54
  it "should return real response even if there are stubs" do
55
- stub_request(:get, /.*/).to_return(:body => "x")
55
+ stub_request(:get, /.*/).to_return(body: "x")
56
56
  expect(http_request(:get, webmock_server_url).body).to eq("hello world")
57
57
  end
58
58
 
@@ -80,7 +80,7 @@ shared_context "enabled WebMock" do
80
80
  end
81
81
 
82
82
  it "should return stubbed response" do
83
- stub_request(:get, /.*/).to_return(:body => "x")
83
+ stub_request(:get, /.*/).to_return(body: "x")
84
84
  expect(http_request(:get, "http://www.example.com/").body).to eq("x")
85
85
  end
86
86
 
@@ -1,14 +1,14 @@
1
1
  shared_context "precedence of stubs" do |*adapter_info|
2
2
  describe "when choosing a matching request stub" do
3
3
  it "should use the last declared matching request stub" do
4
- stub_request(:get, "www.example.com").to_return(:body => "abc")
5
- stub_request(:get, "www.example.com").to_return(:body => "def")
4
+ stub_request(:get, "www.example.com").to_return(body: "abc")
5
+ stub_request(:get, "www.example.com").to_return(body: "def")
6
6
  expect(http_request(:get, "http://www.example.com/").body).to eq("def")
7
7
  end
8
8
 
9
9
  it "should not be affected by the type of uri or request method" do
10
- stub_request(:get, "www.example.com").to_return(:body => "abc")
11
- stub_request(:any, /.*example.*/).to_return(:body => "def")
10
+ stub_request(:get, "www.example.com").to_return(body: "abc")
11
+ stub_request(:any, /.*example.*/).to_return(body: "def")
12
12
  expect(http_request(:get, "http://www.example.com/").body).to eq("def")
13
13
  end
14
14
  end
@@ -56,7 +56,7 @@ shared_context "request expectations" do |*adapter_info|
56
56
 
57
57
  it "should fail if request was executed with different method" do
58
58
  expect {
59
- http_request(:post, "http://www.example.com/", :body => "abc")
59
+ http_request(:post, "http://www.example.com/", body: "abc")
60
60
  expect(a_request(:get, "http://www.example.com")).to have_been_made
61
61
  }.to fail_with(%r(The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times))
62
62
  end
@@ -98,10 +98,10 @@ shared_context "request expectations" do |*adapter_info|
98
98
 
99
99
  it "should satisfy expectations even if requests were executed in different order than expectations were declared" do
100
100
  stub_request(:post, "http://www.example.com")
101
- http_request(:post, "http://www.example.com/", :body => "def")
102
- http_request(:post, "http://www.example.com/", :body => "abc")
103
- expect(WebMock).to have_requested(:post, "www.example.com").with(:body => "abc")
104
- expect(WebMock).to have_requested(:post, "www.example.com").with(:body => "def")
101
+ http_request(:post, "http://www.example.com/", body: "def")
102
+ http_request(:post, "http://www.example.com/", body: "abc")
103
+ expect(WebMock).to have_requested(:post, "www.example.com").with(body: "abc")
104
+ expect(WebMock).to have_requested(:post, "www.example.com").with(body: "def")
105
105
  end
106
106
 
107
107
  describe "when matching requests with escaped or unescaped uris" do
@@ -141,28 +141,28 @@ shared_context "request expectations" do |*adapter_info|
141
141
  it "should satisfy expectation if the request was executed with query params declared as a hash in a query option" do
142
142
  expect {
143
143
  http_request(:get, "http://www.example.com/?a[]=b&a[]=c")
144
- expect(a_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})).to have_been_made
144
+ expect(a_request(:get, "www.example.com").with(query: {"a" => ["b", "c"]})).to have_been_made
145
145
  }.not_to raise_error
146
146
  end
147
147
 
148
148
  it "should satisfy expectation if the request was executed with query params declared as string in query option" do
149
149
  expect {
150
150
  http_request(:get, "http://www.example.com/?a[]=b&a[]=c")
151
- expect(a_request(:get, "www.example.com").with(:query => "a[]=b&a[]=c")).to have_been_made
151
+ expect(a_request(:get, "www.example.com").with(query: "a[]=b&a[]=c")).to have_been_made
152
152
  }.not_to raise_error
153
153
  end
154
154
 
155
155
  it "should satisfy expectation if the request was executed with query params both in uri and in query option" do
156
156
  expect {
157
157
  http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c")
158
- expect(a_request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]})).to have_been_made
158
+ expect(a_request(:get, "www.example.com/?x=3").with(query: {"a" => ["b", "c"]})).to have_been_made
159
159
  }.not_to raise_error
160
160
  end
161
161
 
162
162
  it "should satisfy expectation if the request was executed with only part query params declared as a hash in a query option" do
163
163
  expect {
164
164
  http_request(:get, "http://www.example.com/?a[]=b&a[]=c&b=1")
165
- expect(a_request(:get, "www.example.com").with(:query => hash_including({"a" => ["b", "c"]}))).to have_been_made
165
+ expect(a_request(:get, "www.example.com").with(query: hash_including({"a" => ["b", "c"]}))).to have_been_made
166
166
  }.not_to raise_error
167
167
  end
168
168
  end
@@ -384,32 +384,32 @@ shared_context "request expectations" do |*adapter_info|
384
384
 
385
385
  it "should satisfy expectation if request was executed with the same body" do
386
386
  expect {
387
- http_request(:post, "http://www.example.com/", :body => "abc")
388
- expect(a_request(:post, "www.example.com").with(:body => "abc")).to have_been_made
387
+ http_request(:post, "http://www.example.com/", body: "abc")
388
+ expect(a_request(:post, "www.example.com").with(body: "abc")).to have_been_made
389
389
  }.not_to raise_error
390
390
  end
391
391
 
392
392
  it "should fail if request was executed with different body" do
393
393
  expect {
394
- http_request(:post, "http://www.example.com/", :body => "abc")
394
+ http_request(:post, "http://www.example.com/", body: "abc")
395
395
  expect(a_request(:post, "www.example.com").
396
- with(:body => "def")).to have_been_made
396
+ with(body: "def")).to have_been_made
397
397
  }.to fail_with(%r(The request POST http://www.example.com/ with body "def" was expected to execute 1 time but it executed 0 times))
398
398
  end
399
399
 
400
400
  describe "when expected request body is declared as a regexp" do
401
401
  it "should satisfy expectation if request was executed with body matching regexp" do
402
402
  expect {
403
- http_request(:post, "http://www.example.com/", :body => "abc")
404
- expect(a_request(:post, "www.example.com").with(:body => /^abc$/)).to have_been_made
403
+ http_request(:post, "http://www.example.com/", body: "abc")
404
+ expect(a_request(:post, "www.example.com").with(body: /^abc$/)).to have_been_made
405
405
  }.not_to raise_error
406
406
  end
407
407
 
408
408
  it "should fail if request was executed with body not matching regexp" do
409
409
  expect {
410
- http_request(:post, "http://www.example.com/", :body => "abc")
410
+ http_request(:post, "http://www.example.com/", body: "abc")
411
411
  expect(a_request(:post, "www.example.com").
412
- with(:body => /^xabc/)).to have_been_made
412
+ with(body: /^xabc/)).to have_been_made
413
413
  }.to fail_with(%r(The request POST http://www.example.com/ with body /\^xabc/ was expected to execute 1 time but it executed 0 times))
414
414
  end
415
415
 
@@ -422,22 +422,22 @@ shared_context "request expectations" do |*adapter_info|
422
422
  describe "when request is made with url encoded body matching hash" do
423
423
  it "should satisfy expectation" do
424
424
  expect {
425
- http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&c[d][]=f&b=five')
426
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
425
+ http_request(:post, "http://www.example.com/", body: 'a=1&c[d][]=e&c[d][]=f&b=five')
426
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
427
427
  }.not_to raise_error
428
428
  end
429
429
 
430
430
  it "should satisfy expectation even if url encoded params have different order" do
431
431
  expect {
432
- http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&b=five&c[d][]=f')
433
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
432
+ http_request(:post, "http://www.example.com/", body: 'a=1&c[d][]=e&b=five&c[d][]=f')
433
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
434
434
  }.not_to raise_error
435
435
  end
436
436
 
437
437
  it "should fail if request is executed with url encoded body not matching hash" do
438
438
  expect {
439
- http_request(:post, "http://www.example.com/", :body => 'c[d][]=f&a=1&c[d][]=e')
440
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
439
+ http_request(:post, "http://www.example.com/", body: 'c[d][]=f&a=1&c[d][]=e')
440
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
441
441
  }.to fail_with(fail_message)
442
442
  end
443
443
  end
@@ -445,25 +445,25 @@ shared_context "request expectations" do |*adapter_info|
445
445
  describe "when request is executed with json body matching hash and Content-Type is set to json" do
446
446
  it "should satisfy expectation" do
447
447
  expect {
448
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
449
- :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}")
450
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
448
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
449
+ body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}")
450
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
451
451
  }.not_to raise_error
452
452
  end
453
453
 
454
454
  it "should satisfy expectation even if json body is in different form" do
455
455
  expect {
456
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
457
- :body => "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}")
458
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
456
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
457
+ body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}")
458
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
459
459
  }.not_to raise_error
460
460
  end
461
461
 
462
462
  it "should satisfy expectation even if json body contains date string" do
463
463
  expect {
464
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
465
- :body => "{\"foo\":\"2010-01-01\"}")
466
- expect(a_request(:post, "www.example.com").with(:body => {"foo" => "2010-01-01"})).to have_been_made
464
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
465
+ body: "{\"foo\":\"2010-01-01\"}")
466
+ expect(a_request(:post, "www.example.com").with(body: {"foo" => "2010-01-01"})).to have_been_made
467
467
  }.not_to raise_error
468
468
  end
469
469
  end
@@ -474,25 +474,25 @@ shared_context "request expectations" do |*adapter_info|
474
474
 
475
475
  it "should satisfy expectation" do
476
476
  expect {
477
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
478
- :body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
479
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
477
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
478
+ body: "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
479
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
480
480
  }.not_to raise_error
481
481
  end
482
482
 
483
483
  it "should satisfy expectation even if xml body is in different form" do
484
484
  expect {
485
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
486
- :body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
487
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
485
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
486
+ body: "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
487
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
488
488
  }.not_to raise_error
489
489
  end
490
490
 
491
491
  it "should satisfy expectation even if xml body contains date string" do
492
492
  expect {
493
- http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
494
- :body => "<opt foo=\"2010-01-01\">\n</opt>\n")
495
- expect(a_request(:post, "www.example.com").with(:body => {"opt" => {"foo" => "2010-01-01"}})).to have_been_made
493
+ http_request(:post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
494
+ body: "<opt foo=\"2010-01-01\">\n</opt>\n")
495
+ expect(a_request(:post, "www.example.com").with(body: {"opt" => {"foo" => "2010-01-01"}})).to have_been_made
496
496
  }.not_to raise_error
497
497
  end
498
498
  end
@@ -505,15 +505,15 @@ shared_context "request expectations" do |*adapter_info|
505
505
  describe "when request is made with url encoded body matching hash" do
506
506
  it "should satisfy expectation" do
507
507
  expect {
508
- http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&c[d][]=f&b=five')
509
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
508
+ http_request(:post, "http://www.example.com/", body: 'a=1&c[d][]=e&c[d][]=f&b=five')
509
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
510
510
  }.not_to raise_error
511
511
  end
512
512
 
513
513
  it "should fail if request is executed with url encoded body not matching hash" do
514
514
  expect {
515
- http_request(:post, "http://www.example.com/", :body => 'c[d][]=f&a=1&c[d][]=e')
516
- expect(a_request(:post, "www.example.com").with(:body => body_hash)).to have_been_made
515
+ http_request(:post, "http://www.example.com/", body: 'c[d][]=f&a=1&c[d][]=e')
516
+ expect(a_request(:post, "www.example.com").with(body: body_hash)).to have_been_made
517
517
  }.to fail_with(fail_message)
518
518
  end
519
519
  end
@@ -522,77 +522,77 @@ shared_context "request expectations" do |*adapter_info|
522
522
  describe "when request with headers is expected" do
523
523
  it "should satisfy expectation if request was executed with the same headers" do
524
524
  expect {
525
- http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
525
+ http_request(:get, "http://www.example.com/", headers: SAMPLE_HEADERS)
526
526
  expect(a_request(:get, "www.example.com").
527
- with(:headers => SAMPLE_HEADERS)).to have_been_made
527
+ with(headers: SAMPLE_HEADERS)).to have_been_made
528
528
  }.not_to raise_error
529
529
  end
530
530
 
531
531
  it "should satisfy expectation if request was executed with the same headers but with header value declared as array" do
532
532
  expect {
533
- http_request(:get, "http://www.example.com/", :headers => {"a" => "b"})
533
+ http_request(:get, "http://www.example.com/", headers: {"a" => "b"})
534
534
  expect(a_request(:get, "www.example.com").
535
- with(:headers => {"a" => ["b"]})).to have_been_made
535
+ with(headers: {"a" => ["b"]})).to have_been_made
536
536
  }.not_to raise_error
537
537
  end
538
538
 
539
539
  describe "when multiple headers with the same key are passed" do
540
540
  it "should satisfy expectation" do
541
541
  expect {
542
- http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
542
+ http_request(:get, "http://www.example.com/", headers: {"a" => ["b", "c"]})
543
543
  expect(a_request(:get, "www.example.com").
544
- with(:headers => {"a" => ["b", "c"]})).to have_been_made
544
+ with(headers: {"a" => ["b", "c"]})).to have_been_made
545
545
  }.not_to raise_error
546
546
  end
547
547
 
548
548
  it "should satisfy expectation even if request was executed with the same headers but different order" do
549
549
  expect {
550
- http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
550
+ http_request(:get, "http://www.example.com/", headers: {"a" => ["b", "c"]})
551
551
  expect(a_request(:get, "www.example.com").
552
- with(:headers => {"a" => ["c", "b"]})).to have_been_made
552
+ with(headers: {"a" => ["c", "b"]})).to have_been_made
553
553
  }.not_to raise_error
554
554
  end
555
555
 
556
556
  it "should fail if request was executed with different headers" do
557
557
  expect {
558
- http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
558
+ http_request(:get, "http://www.example.com/", headers: {"a" => ["b", "c"]})
559
559
  expect(a_request(:get, "www.example.com").
560
- with(:headers => {"a" => ["b", "d"]})).to have_been_made
560
+ with(headers: {"a" => ["b", "d"]})).to have_been_made
561
561
  }.to fail_with(%r(The request GET http://www.example.com/ with headers \{'A'=>\['b', 'd'\]\} was expected to execute 1 time but it executed 0 times))
562
562
  end
563
563
  end
564
564
 
565
565
  it "should fail if request was executed with different headers" do
566
566
  expect {
567
- http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
567
+ http_request(:get, "http://www.example.com/", headers: SAMPLE_HEADERS)
568
568
  expect(a_request(:get, "www.example.com").
569
- with(:headers => { 'Content-Length' => '9999'})).to have_been_made
569
+ with(headers: { 'Content-Length' => '9999'})).to have_been_made
570
570
  }.to fail_with(%r(The request GET http://www.example.com/ with headers \{'Content-Length'=>'9999'\} was expected to execute 1 time but it executed 0 times))
571
571
  end
572
572
 
573
573
  it "should fail if request was executed with less headers" do
574
574
  expect {
575
- http_request(:get, "http://www.example.com/", :headers => {'A' => 'a'})
575
+ http_request(:get, "http://www.example.com/", headers: {'A' => 'a'})
576
576
  expect(a_request(:get, "www.example.com").
577
- with(:headers => {'A' => 'a', 'B' => 'b'})).to have_been_made
577
+ with(headers: {'A' => 'a', 'B' => 'b'})).to have_been_made
578
578
  }.to fail_with(%r(The request GET http://www.example.com/ with headers \{'A'=>'a', 'B'=>'b'\} was expected to execute 1 time but it executed 0 times))
579
579
  end
580
580
 
581
581
  it "should satisfy expectation if request was executed with more headers" do
582
582
  expect {
583
583
  http_request(:get, "http://www.example.com/",
584
- :headers => {'A' => 'a', 'B' => 'b'}
584
+ headers: {'A' => 'a', 'B' => 'b'}
585
585
  )
586
586
  expect(a_request(:get, "www.example.com").
587
- with(:headers => {'A' => 'a'})).to have_been_made
587
+ with(headers: {'A' => 'a'})).to have_been_made
588
588
  }.not_to raise_error
589
589
  end
590
590
 
591
591
  it "should satisfy expectation if request was executed with body and headers but they were not specified in expectantion" do
592
592
  expect {
593
593
  http_request(:post, "http://www.example.com/",
594
- :body => "abc",
595
- :headers => SAMPLE_HEADERS
594
+ body: "abc",
595
+ headers: SAMPLE_HEADERS
596
596
  )
597
597
  expect(a_request(:post, "www.example.com")).to have_been_made
598
598
  }.not_to raise_error
@@ -600,17 +600,17 @@ shared_context "request expectations" do |*adapter_info|
600
600
 
601
601
  it "should satisfy expectation if request was executed with headers matching regular expressions" do
602
602
  expect {
603
- http_request(:get, "http://www.example.com/", :headers => { 'some-header' => 'MyAppName' })
603
+ http_request(:get, "http://www.example.com/", headers: { 'some-header' => 'MyAppName' })
604
604
  expect(a_request(:get, "www.example.com").
605
- with(:headers => { :some_header => /^MyAppName$/ })).to have_been_made
605
+ with(headers: { some_header: /^MyAppName$/ })).to have_been_made
606
606
  }.not_to raise_error
607
607
  end
608
608
 
609
609
  it "should fail if request was executed with headers not matching regular expression" do
610
610
  expect {
611
- http_request(:get, "http://www.example.com/", :headers => { 'some-header' => 'xMyAppName' })
611
+ http_request(:get, "http://www.example.com/", headers: { 'some-header' => 'xMyAppName' })
612
612
  expect(a_request(:get, "www.example.com").
613
- with(:headers => { :some_header => /^MyAppName$/ })).to have_been_made
613
+ with(headers: { some_header: /^MyAppName$/ })).to have_been_made
614
614
  }.to fail_with(%r(The request GET http://www.example.com/ with headers \{'Some-Header'=>/\^MyAppName\$/\} was expected to execute 1 time but it executed 0 times))
615
615
  end
616
616
  end
@@ -618,27 +618,27 @@ shared_context "request expectations" do |*adapter_info|
618
618
  describe "when expectation contains a request matching block" do
619
619
  it "should satisfy expectation if request was executed and block evaluated to true" do
620
620
  expect {
621
- http_request(:post, "http://www.example.com/", :body => "wadus")
621
+ http_request(:post, "http://www.example.com/", body: "wadus")
622
622
  expect(a_request(:post, "www.example.com").with { |req| req.body == "wadus" }).to have_been_made
623
623
  }.not_to raise_error
624
624
  end
625
625
 
626
626
  it "should fail if request was executed and block evaluated to false" do
627
627
  expect {
628
- http_request(:post, "http://www.example.com/", :body => "abc")
628
+ http_request(:post, "http://www.example.com/", body: "abc")
629
629
  expect(a_request(:post, "www.example.com").with { |req| req.body == "wadus" }).to have_been_made
630
630
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
631
631
  end
632
632
 
633
633
  it "should fail if request was not expected but it executed and block matched request" do
634
634
  expect {
635
- http_request(:post, "http://www.example.com/", :body => "wadus")
635
+ http_request(:post, "http://www.example.com/", body: "wadus")
636
636
  expect(a_request(:post, "www.example.com").with { |req| req.body == "wadus" }).not_to have_been_made
637
637
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
638
638
  end
639
639
  end
640
640
 
641
- describe "with userinfo", :unless => (adapter_info.include?(:no_url_auth)) do
641
+ describe "with userinfo", unless: (adapter_info.include?(:no_url_auth)) do
642
642
  before(:each) do
643
643
  stub_request(:any, "http://user:pass@www.example.com")
644
644
  stub_request(:any, "http://user:pazz@www.example.com")
@@ -721,7 +721,7 @@ shared_context "request expectations" do |*adapter_info|
721
721
  }.not_to raise_error
722
722
  end
723
723
 
724
- it "should fail if request was executed with basic auth header and credentials were provided in url", :unless => (adapter_info.include?(:no_url_auth)) do
724
+ it "should fail if request was executed with basic auth header and credentials were provided in url", unless: (adapter_info.include?(:no_url_auth)) do
725
725
  expect {
726
726
  stub_request(:any, "http://user:pass@www.example.com")
727
727
  http_request(:get, "http://user:pass@www.example.com/")
@@ -740,8 +740,8 @@ shared_context "request expectations" do |*adapter_info|
740
740
 
741
741
  it "should satisfy expectation if request with body and headers was expected and request was made" do
742
742
  expect {
743
- http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'a'})
744
- expect(WebMock).to have_requested(:post, "http://www.example.com").with(:body => "abc", :headers => {'A' => 'a'}).once
743
+ http_request(:post, "http://www.example.com/", body: "abc", headers: {'A' => 'a'})
744
+ expect(WebMock).to have_requested(:post, "http://www.example.com").with(body: "abc", headers: {'A' => 'a'}).once
745
745
  }.not_to raise_error
746
746
  end
747
747
 
@@ -754,21 +754,21 @@ shared_context "request expectations" do |*adapter_info|
754
754
 
755
755
  it "should satisfy expectation if request was executed and expectation had block which evaluated to true" do
756
756
  expect {
757
- http_request(:post, "http://www.example.com/", :body => "wadus")
757
+ http_request(:post, "http://www.example.com/", body: "wadus")
758
758
  expect(WebMock).to have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
759
759
  }.not_to raise_error
760
760
  end
761
761
 
762
762
  it "should fail if request was executed and expectation had block which evaluated to false" do
763
763
  expect {
764
- http_request(:post, "http://www.example.com/", :body => "abc")
764
+ http_request(:post, "http://www.example.com/", body: "abc")
765
765
  expect(WebMock).to have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
766
766
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
767
767
  end
768
768
 
769
769
  it "should fail if request was expected not to be made but was made and block matched request" do
770
770
  expect {
771
- http_request(:post, "http://www.example.com/", :body => "wadus")
771
+ http_request(:post, "http://www.example.com/", body: "wadus")
772
772
  expect(WebMock).not_to have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
773
773
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
774
774
  end
@@ -778,15 +778,15 @@ shared_context "request expectations" do |*adapter_info|
778
778
  it "should satisfy expectation if requests was made" do
779
779
  expect {
780
780
  http_request(:get, "http://www.example.com/")
781
- assert_requested(:get, "http://www.example.com", :times => 1)
781
+ assert_requested(:get, "http://www.example.com", times: 1)
782
782
  assert_requested(:get, "http://www.example.com")
783
783
  }.not_to raise_error
784
784
  end
785
785
 
786
786
  it "should satisfy expectation if request was made with body and headers" do
787
787
  expect {
788
- http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'a'})
789
- assert_requested(:post, "http://www.example.com", :body => "abc", :headers => {'A' => 'a'})
788
+ http_request(:post, "http://www.example.com/", body: "abc", headers: {'A' => 'a'})
789
+ assert_requested(:post, "http://www.example.com", body: "abc", headers: {'A' => 'a'})
790
790
  }.not_to raise_error
791
791
  end
792
792
 
@@ -799,21 +799,21 @@ shared_context "request expectations" do |*adapter_info|
799
799
 
800
800
  it "should fail if request expected not to be made was made and expectation block evaluated to true" do
801
801
  expect {
802
- http_request(:post, "http://www.example.com/", :body => "wadus")
802
+ http_request(:post, "http://www.example.com/", body: "wadus")
803
803
  assert_not_requested(:post, "www.example.com") { |req| req.body == "wadus" }
804
804
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
805
805
  end
806
806
 
807
807
  it "should satisfy expectation if request was made and expectation block evaluated to true" do
808
808
  expect {
809
- http_request(:post, "http://www.example.com/", :body => "wadus")
809
+ http_request(:post, "http://www.example.com/", body: "wadus")
810
810
  assert_requested(:post, "www.example.com") { |req| req.body == "wadus" }
811
811
  }.not_to raise_error
812
812
  end
813
813
 
814
814
  it "should fail if request was made and expectation block evaluated to false" do
815
815
  expect {
816
- http_request(:post, "http://www.example.com/", :body => "abc")
816
+ http_request(:post, "http://www.example.com/", body: "abc")
817
817
  assert_requested(:post, "www.example.com") { |req| req.body == "wadus" }
818
818
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
819
819
  end
@@ -824,7 +824,7 @@ shared_context "request expectations" do |*adapter_info|
824
824
  stub_http = stub_http_request(:get, "http://www.example.com")
825
825
  expect {
826
826
  http_request(:get, "http://www.example.com/")
827
- assert_requested(stub_http, :times => 1)
827
+ assert_requested(stub_http, times: 1)
828
828
  assert_requested(stub_http)
829
829
  }.not_to raise_error
830
830
  end
@@ -856,8 +856,8 @@ shared_context "request expectations" do |*adapter_info|
856
856
  end
857
857
 
858
858
  it "should satisfy expectation if expected request with body and headers was made" do
859
- stub = stub_request(:post, "http://www.example.com").with(:body => "abc", :headers => {'A' => 'a'})
860
- http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'a'})
859
+ stub = stub_request(:post, "http://www.example.com").with(body: "abc", headers: {'A' => 'a'})
860
+ http_request(:post, "http://www.example.com/", body: "abc", headers: {'A' => 'a'})
861
861
  expect(stub).to have_been_requested.once
862
862
  end
863
863
 
@@ -872,14 +872,14 @@ shared_context "request expectations" do |*adapter_info|
872
872
  it "should fail request not expected to be made was made and expectation block evaluated to true" do
873
873
  expect {
874
874
  stub = stub_request(:post, "www.example.com").with { |req| req.body == "wadus" }
875
- http_request(:post, "http://www.example.com/", :body => "wadus")
875
+ http_request(:post, "http://www.example.com/", body: "wadus")
876
876
  expect(stub).not_to have_been_requested
877
877
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
878
878
  end
879
879
 
880
880
  it "should satisfy expectation if request was made and expectation block evaluated to true" do
881
881
  stub = stub_request(:post, "www.example.com").with { |req| req.body == "wadus" }
882
- http_request(:post, "http://www.example.com/", :body => "wadus")
882
+ http_request(:post, "http://www.example.com/", body: "wadus")
883
883
  expect(stub).to have_been_requested
884
884
  end
885
885
 
@@ -887,13 +887,13 @@ shared_context "request expectations" do |*adapter_info|
887
887
  expect {
888
888
  stub_request(:any, /.+/) #stub any request
889
889
  stub = stub_request(:post, "www.example.com").with { |req| req.body == "wadus" }
890
- http_request(:post, "http://www.example.com/", :body => "abc")
890
+ http_request(:post, "http://www.example.com/", body: "abc")
891
891
  expect(stub).to have_been_requested
892
892
  }.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
893
893
  end
894
894
  end
895
895
 
896
- describe "when net connect is allowed", :net_connect => true do
896
+ describe "when net connect is allowed", net_connect: true do
897
897
  before(:each) do
898
898
  WebMock.allow_net_connect!
899
899
  end