webmock 1.21.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +8 -0
- data/CHANGELOG.md +51 -1
- data/Gemfile +0 -1
- data/README.md +17 -6
- data/lib/webmock.rb +4 -1
- data/lib/webmock/config.rb +2 -0
- data/lib/webmock/errors.rb +3 -21
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb +5 -0
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +123 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +16 -2
- data/lib/webmock/request_body_diff.rb +63 -0
- data/lib/webmock/request_execution_verifier.rb +24 -21
- data/lib/webmock/request_pattern.rb +2 -0
- data/lib/webmock/request_signature.rb +5 -1
- data/lib/webmock/request_signature_snippet.rb +61 -0
- data/lib/webmock/rspec/matchers.rb +0 -1
- data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +4 -0
- data/lib/webmock/rspec/matchers/webmock_matcher.rb +4 -0
- data/lib/webmock/stub_request_snippet.rb +4 -0
- data/lib/webmock/util/json.rb +25 -6
- data/lib/webmock/util/query_mapper.rb +6 -4
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +12 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +60 -0
- data/spec/acceptance/http_rb/http_rb_spec.rb +2 -2
- data/spec/acceptance/http_rb/http_rb_spec_helper.rb +1 -1
- data/spec/acceptance/httpclient/httpclient_spec.rb +8 -7
- data/spec/acceptance/manticore/manticore_spec.rb +56 -0
- data/spec/acceptance/manticore/manticore_spec_helper.rb +31 -0
- data/spec/acceptance/net_http/net_http_spec.rb +24 -1
- data/spec/acceptance/shared/request_expectations.rb +10 -10
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/errors_spec.rb +45 -4
- data/spec/unit/request_body_diff_spec.rb +90 -0
- data/spec/unit/request_execution_verifier_spec.rb +48 -11
- data/spec/unit/request_signature_snippet_spec.rb +89 -0
- data/spec/unit/request_signature_spec.rb +61 -23
- data/spec/unit/stub_registry_spec.rb +1 -1
- data/spec/unit/util/json_spec.rb +29 -3
- data/spec/unit/util/query_mapper_spec.rb +15 -4
- data/spec/unit/webmock_spec.rb +4 -0
- data/test/shared_test.rb +2 -2
- data/webmock.gemspec +4 -1
- metadata +63 -24
@@ -0,0 +1,31 @@
|
|
1
|
+
module ManticoreSpecHelper
|
2
|
+
def http_request(method, uri, options = {})
|
3
|
+
client = Manticore::Client.new
|
4
|
+
response = client.http(method, uri, options)
|
5
|
+
|
6
|
+
OpenStruct.new({
|
7
|
+
:body => response.body || '',
|
8
|
+
:headers => WebMock::Util::Headers.normalize_headers(join_array_values(response.headers)),
|
9
|
+
:status => response.code.to_s
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
def join_array_values(hash)
|
14
|
+
hash.reduce({}) do |h, (k,v)|
|
15
|
+
v = v.join(', ') if v.is_a?(Array)
|
16
|
+
h.merge(k => v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def client_timeout_exception_class
|
21
|
+
Manticore::ConnectTimeout
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection_refused_exception_class
|
25
|
+
Manticore::SocketException
|
26
|
+
end
|
27
|
+
|
28
|
+
def http_library
|
29
|
+
:manticore
|
30
|
+
end
|
31
|
+
end
|
@@ -9,7 +9,7 @@ include NetHTTPSpecHelper
|
|
9
9
|
describe "Net:HTTP" do
|
10
10
|
include_examples "with WebMock"
|
11
11
|
|
12
|
-
let(:port){ WebMockServer.instance.port }
|
12
|
+
let(:port) { WebMockServer.instance.port }
|
13
13
|
|
14
14
|
describe "marshalling" do
|
15
15
|
class TestMarshalingInWebMockNetHTTP
|
@@ -106,6 +106,28 @@ describe "Net:HTTP" do
|
|
106
106
|
expect(Net::HTTP.start("www.example.com") { |query| query.get("/") }.body).to eq("abc"*100000)
|
107
107
|
end
|
108
108
|
|
109
|
+
it "raises an ArgumentError if passed headers as symbols" do
|
110
|
+
uri = URI.parse("http://google.com/")
|
111
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
112
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
113
|
+
|
114
|
+
# Net::HTTP calls downcase on header keys assigned with []=
|
115
|
+
# In Ruby 1.8.7 symbols do not respond to downcase
|
116
|
+
#
|
117
|
+
# Meaning you can not assign header keys as symbols in ruby 1.8.7 using []=
|
118
|
+
if :symbol.respond_to?(:downcase)
|
119
|
+
request[:InvalidHeaderSinceItsASymbol] = "this will not be valid"
|
120
|
+
else
|
121
|
+
request.instance_eval do
|
122
|
+
@header = request.to_hash.merge({:InvalidHeaderSinceItsASymbol => "this will not be valid"})
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
expect do
|
127
|
+
http.request(request)
|
128
|
+
end.to raise_error ArgumentError, "Net:HTTP does not accept headers as symbols"
|
129
|
+
end
|
130
|
+
|
109
131
|
it "should handle multiple values for the same response header" do
|
110
132
|
stub_http_request(:get, "www.example.com").to_return(:headers => { 'Set-Cookie' => ['foo=bar', 'bar=bazz'] })
|
111
133
|
response = Net::HTTP.get_response(URI.parse("http://www.example.com/"))
|
@@ -169,6 +191,7 @@ describe "Net:HTTP" do
|
|
169
191
|
@http.use_ssl = true
|
170
192
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
171
193
|
end
|
194
|
+
|
172
195
|
describe "when net http is allowed" do
|
173
196
|
it "should not connect to the server until the request", :net_connect => true do
|
174
197
|
WebMock.allow_net_connect!
|
@@ -31,7 +31,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
31
31
|
expect {
|
32
32
|
http_request(:get, "http://www.example.com/")
|
33
33
|
expect(a_request(:get, "http://www.example.com")).not_to have_been_made
|
34
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
34
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should fail resulting with failure with a message and executed requests listed" do
|
@@ -626,7 +626,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
626
626
|
expect {
|
627
627
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
628
628
|
expect(a_request(:post, "www.example.com").with { |req| req.body == "wadus" }).not_to have_been_made
|
629
|
-
}.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute
|
629
|
+
}.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
|
630
630
|
end
|
631
631
|
end
|
632
632
|
|
@@ -692,7 +692,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
692
692
|
expect {
|
693
693
|
http_request(:get, "http://www.example.com/")
|
694
694
|
expect(WebMock).not_to have_requested(:get, "http://www.example.com")
|
695
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
695
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
696
696
|
end
|
697
697
|
|
698
698
|
it "should satisfy expectation if request was executed and expectation had block which evaluated to true" do
|
@@ -713,7 +713,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
713
713
|
expect {
|
714
714
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
715
715
|
expect(WebMock).not_to have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
|
716
|
-
}.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute
|
716
|
+
}.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
|
717
717
|
end
|
718
718
|
end
|
719
719
|
|
@@ -737,14 +737,14 @@ shared_context "request expectations" do |*adapter_info|
|
|
737
737
|
expect {
|
738
738
|
http_request(:get, "http://www.example.com/")
|
739
739
|
assert_not_requested(:get, "http://www.example.com")
|
740
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
740
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
741
741
|
end
|
742
742
|
|
743
743
|
it "should fail if request expected not to be made was made and expectation block evaluated to true" do
|
744
744
|
expect {
|
745
745
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
746
746
|
assert_not_requested(:post, "www.example.com") { |req| req.body == "wadus" }
|
747
|
-
}.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute
|
747
|
+
}.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
|
748
748
|
end
|
749
749
|
|
750
750
|
it "should satisfy expectation if request was made and expectation block evaluated to true" do
|
@@ -777,7 +777,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
777
777
|
expect {
|
778
778
|
http_request(:get, "http://www.example.com/")
|
779
779
|
assert_not_requested(stub_http)
|
780
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
780
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
781
781
|
end
|
782
782
|
end
|
783
783
|
end
|
@@ -809,7 +809,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
809
809
|
stub = stub_request(:get, "http://www.example.com")
|
810
810
|
http_request(:get, "http://www.example.com/")
|
811
811
|
expect(stub).not_to have_been_requested
|
812
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
812
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
813
813
|
end
|
814
814
|
|
815
815
|
it "should fail request not expected to be made was made and expectation block evaluated to true" do
|
@@ -817,7 +817,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
817
817
|
stub = stub_request(:post, "www.example.com").with { |req| req.body == "wadus" }
|
818
818
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
819
819
|
expect(stub).not_to have_been_requested
|
820
|
-
}.to fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute
|
820
|
+
}.to fail_with(%r(The request POST http://www.example.com/ with given block was not expected to execute but it executed 1 time))
|
821
821
|
end
|
822
822
|
|
823
823
|
it "should satisfy expectation if request was made and expectation block evaluated to true" do
|
@@ -852,7 +852,7 @@ shared_context "request expectations" do |*adapter_info|
|
|
852
852
|
expect {
|
853
853
|
http_request(:get, "http://www.example.com/")
|
854
854
|
expect(a_request(:get, "http://www.example.com")).not_to have_been_made
|
855
|
-
}.to fail_with(%r(The request GET http://www.example.com/ was expected to execute
|
855
|
+
}.to fail_with(%r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time))
|
856
856
|
end
|
857
857
|
end
|
858
858
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,9 @@ unless RUBY_PLATFORM =~ /java/
|
|
6
6
|
require 'em-http'
|
7
7
|
require 'typhoeus'
|
8
8
|
end
|
9
|
+
if RUBY_PLATFORM =~ /java/
|
10
|
+
require 'manticore'
|
11
|
+
end
|
9
12
|
|
10
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
14
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -45,6 +48,7 @@ RSpec.configure do |config|
|
|
45
48
|
config.filter_run :focus => true
|
46
49
|
config.run_all_when_everything_filtered = true
|
47
50
|
end
|
51
|
+
RSpec::Expectations.configuration.warn_about_potential_false_positives = false
|
48
52
|
|
49
53
|
def fail()
|
50
54
|
raise_error(RSpec::Expectations::ExpectationNotMetError)
|
data/spec/unit/errors_spec.rb
CHANGED
@@ -21,6 +21,7 @@ describe "errors" do
|
|
21
21
|
allow(WebMock::RequestStub).to receive(:from_request_signature).and_return(request_stub)
|
22
22
|
allow(WebMock::StubRequestSnippet).to receive(:new).
|
23
23
|
with(request_stub).and_return(stub_result)
|
24
|
+
allow_any_instance_of(WebMock::RequestBodyDiff).to receive(:body_diff).and_return({})
|
24
25
|
|
25
26
|
expected = \
|
26
27
|
"Real HTTP connections are disabled. Unregistered request: #{request_signature}" \
|
@@ -48,6 +49,44 @@ describe "errors" do
|
|
48
49
|
end.to raise_exception exception
|
49
50
|
end
|
50
51
|
|
52
|
+
it "should print body diff if available" do
|
53
|
+
allow(WebMock::StubRegistry.instance).to receive(:request_stubs).and_return([request_stub])
|
54
|
+
allow(WebMock::RequestStub).to receive(:from_request_signature).and_return(request_stub)
|
55
|
+
allow(WebMock::StubRequestSnippet).to receive(:new).
|
56
|
+
with(request_stub).and_return(stub_result)
|
57
|
+
allow_any_instance_of(WebMock::RequestBodyDiff).to receive(:body_diff).and_return(body_diff)
|
58
|
+
expected = \
|
59
|
+
"Real HTTP connections are disabled. Unregistered request: #{request_signature}" \
|
60
|
+
"\n\nYou can stub this request with the following snippet:" \
|
61
|
+
"\n\n#{stub_result}" \
|
62
|
+
"\n\nregistered request stubs:" \
|
63
|
+
"\n\n#{stub_result}" \
|
64
|
+
"\n\nBody diff:\n [[\"+\", \"test\", \"test2\"], [\"-\", \"test3\"], [\"~\", \"test5\", \"test6\"]]" \
|
65
|
+
"\n\n\n============================================================"
|
66
|
+
expect(WebMock::NetConnectNotAllowedError.new(request_signature).message).to eq(expected)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "WebMock.show_body_diff? is false" do
|
70
|
+
before do
|
71
|
+
WebMock.hide_body_diff!
|
72
|
+
end
|
73
|
+
it "should not show body diff" do
|
74
|
+
allow(WebMock::StubRegistry.instance).to receive(:request_stubs).and_return([request_stub])
|
75
|
+
allow(WebMock::RequestStub).to receive(:from_request_signature).and_return(request_stub)
|
76
|
+
allow(WebMock::StubRequestSnippet).to receive(:new).
|
77
|
+
with(request_stub).and_return(stub_result)
|
78
|
+
expect_any_instance_of(WebMock::RequestBodyDiff).to_not receive(:body_diff)
|
79
|
+
expected = \
|
80
|
+
"Real HTTP connections are disabled. Unregistered request: #{request_signature}" \
|
81
|
+
"\n\nYou can stub this request with the following snippet:" \
|
82
|
+
"\n\n#{stub_result}" \
|
83
|
+
"\n\nregistered request stubs:" \
|
84
|
+
"\n\n#{stub_result}" \
|
85
|
+
"\n\n============================================================"
|
86
|
+
expect(WebMock::NetConnectNotAllowedError.new(request_signature).message).to eq(expected)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
51
90
|
context "WebMock.show_stubbing_instructions? is false" do
|
52
91
|
before do
|
53
92
|
WebMock.hide_stubbing_instructions!
|
@@ -69,6 +108,7 @@ describe "errors" do
|
|
69
108
|
allow(WebMock::RequestStub).to receive(:from_request_signature).and_return(request_stub)
|
70
109
|
allow(WebMock::StubRequestSnippet).to receive(:new).
|
71
110
|
with(request_stub).and_return(stub_result)
|
111
|
+
allow(request_stub).to receive(:request_pattern).and_return(body_pattern)
|
72
112
|
|
73
113
|
expected = \
|
74
114
|
"Real HTTP connections are disabled. Unregistered request: #{request_signature}" \
|
@@ -80,9 +120,10 @@ describe "errors" do
|
|
80
120
|
end
|
81
121
|
end
|
82
122
|
|
83
|
-
let(:request_signature) { double(:to_s => rand(10**20).to_s) }
|
84
|
-
let(:stub_result) { double(:to_s => rand(10**20).to_s) }
|
85
|
-
let(:request_stub) { double }
|
86
|
-
|
123
|
+
let(:request_signature) { double(:request_signature, :to_s => rand(10**20).to_s) }
|
124
|
+
let(:stub_result) { double(:stub_result, :to_s => rand(10**20).to_s) }
|
125
|
+
let(:request_stub) { double(:request_stub) }
|
126
|
+
let(:body_pattern) { double(:body_pattern, :body_pattern => nil)}
|
127
|
+
let(:body_diff) { [["+", "test", "test2"], ["-", "test3"], ["~", "test5", "test6"]] }
|
87
128
|
end
|
88
129
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe WebMock::RequestBodyDiff do
|
4
|
+
subject { WebMock::RequestBodyDiff.new(request_signature, request_stub) }
|
5
|
+
|
6
|
+
let(:uri) { "http://example.com" }
|
7
|
+
let(:method) { "GET" }
|
8
|
+
|
9
|
+
let(:request_stub) { WebMock::RequestStub.new(method, uri) }
|
10
|
+
let(:request_signature) { WebMock::RequestSignature.new(method, uri) }
|
11
|
+
|
12
|
+
let(:request_stub_body) { { "key" => "value"} }
|
13
|
+
let(:request_signature_body) { {"key" => "different value"}.to_json }
|
14
|
+
|
15
|
+
let(:request_pattern) {
|
16
|
+
WebMock::RequestPattern.new(
|
17
|
+
method, uri, {:body => request_stub_body}
|
18
|
+
)
|
19
|
+
}
|
20
|
+
|
21
|
+
before :each do
|
22
|
+
request_stub.request_pattern = request_pattern
|
23
|
+
request_signature.headers = {"Content-Type" => "application/json"}
|
24
|
+
request_signature.body = request_signature_body
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#body_diff" do
|
28
|
+
context "request signature is unparseable json" do
|
29
|
+
let(:request_signature_body) { "youcan'tparsethis!" }
|
30
|
+
|
31
|
+
it "returns an empty hash" do
|
32
|
+
expect(subject.body_diff).to eq({})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "request stub body as unparseable json" do
|
37
|
+
let(:request_stub_body) { "youcan'tparsethis!" }
|
38
|
+
|
39
|
+
it "returns an empty hash" do
|
40
|
+
expect(subject.body_diff).to eq({})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "request stub body pattern is hash" do
|
45
|
+
let(:request_stub_body) { { "key" => "value"} }
|
46
|
+
|
47
|
+
it "generates a diff" do
|
48
|
+
expect(subject.body_diff).to eq(
|
49
|
+
[["~", "key", "different value", "value"]]
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "request signature doesn't have json headers" do
|
55
|
+
before :each do
|
56
|
+
request_signature.headers = {"Content-Type" => "application/xml"}
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns an empty hash" do
|
60
|
+
expect(subject.body_diff).to eq({})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "request stub body pattern is a string" do
|
65
|
+
let(:request_stub_body) { { "key" => "value"}.to_json }
|
66
|
+
|
67
|
+
it "generates a diff" do
|
68
|
+
expect(subject.body_diff).to eq(
|
69
|
+
[["~", "key", "different value", "value"]]
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "stub request has no request pattern" do
|
75
|
+
let(:request_signature_body) { nil }
|
76
|
+
|
77
|
+
it "returns an empty hash" do
|
78
|
+
expect(subject.body_diff).to eq({})
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "stub request has no body pattern" do
|
83
|
+
let(:request_stub_body) { nil }
|
84
|
+
|
85
|
+
it "returns an empty hash" do
|
86
|
+
expect(subject.body_diff).to eq({})
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -9,10 +9,47 @@ describe WebMock::RequestExecutionVerifier do
|
|
9
9
|
@executed_requests_info = "\n\nThe following requests were made:\n\nexecuted requests\n" + "="*60
|
10
10
|
end
|
11
11
|
|
12
|
+
describe "description" do
|
13
|
+
|
14
|
+
it "reports the description" do
|
15
|
+
@verifier.expected_times_executed = 2
|
16
|
+
expect(@verifier.description).to eq "request www.example.com 2 times"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "reports description correctly when expectation is 1 time" do
|
20
|
+
@verifier.expected_times_executed = 1
|
21
|
+
expect(@verifier.description).to eq "request www.example.com 1 time"
|
22
|
+
end
|
23
|
+
|
24
|
+
context "at_least_times_executed is set" do
|
25
|
+
it "reports description correctly when expectation at least 2 times" do
|
26
|
+
@verifier.at_least_times_executed = 2
|
27
|
+
expect(@verifier.description).to eq "request www.example.com at least 2 times"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "reports description correctly when expectation is at least 3 times" do
|
31
|
+
@verifier.at_least_times_executed = 3
|
32
|
+
expect(@verifier.description).to eq "request www.example.com at least 3 times"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "at_most_times_executed is set" do
|
37
|
+
it "reports description correctly when expectation is at most 2 times" do
|
38
|
+
@verifier.at_most_times_executed = 2
|
39
|
+
expect(@verifier.description).to eq "request www.example.com at most 2 times"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "reports description correctly when expectation is at most 1 time" do
|
43
|
+
@verifier.at_most_times_executed = 1
|
44
|
+
expect(@verifier.description).to eq "request www.example.com at most 1 time"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
12
49
|
|
13
50
|
describe "failure message" do
|
14
51
|
|
15
|
-
it "
|
52
|
+
it "reports the failure message" do
|
16
53
|
@verifier.times_executed = 0
|
17
54
|
@verifier.expected_times_executed = 2
|
18
55
|
expected_text = "The request www.example.com was expected to execute 2 times but it executed 0 times"
|
@@ -20,7 +57,7 @@ describe WebMock::RequestExecutionVerifier do
|
|
20
57
|
expect(@verifier.failure_message).to eq(expected_text)
|
21
58
|
end
|
22
59
|
|
23
|
-
it "
|
60
|
+
it "reports failure message correctly when executed times is one" do
|
24
61
|
@verifier.times_executed = 1
|
25
62
|
@verifier.expected_times_executed = 1
|
26
63
|
expected_text = "The request www.example.com was expected to execute 1 time but it executed 1 time"
|
@@ -67,7 +104,7 @@ describe WebMock::RequestExecutionVerifier do
|
|
67
104
|
|
68
105
|
describe "negative failure message" do
|
69
106
|
|
70
|
-
it "
|
107
|
+
it "reports failure message if it executed number of times specified" do
|
71
108
|
@verifier.times_executed = 2
|
72
109
|
@verifier.expected_times_executed = 2
|
73
110
|
expected_text = "The request www.example.com was not expected to execute 2 times but it executed 2 times"
|
@@ -75,9 +112,9 @@ describe WebMock::RequestExecutionVerifier do
|
|
75
112
|
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
76
113
|
end
|
77
114
|
|
78
|
-
it "
|
115
|
+
it "reports failure message when not expected request but it executed" do
|
79
116
|
@verifier.times_executed = 1
|
80
|
-
expected_text = "The request www.example.com was expected to execute
|
117
|
+
expected_text = "The request www.example.com was not expected to execute but it executed 1 time"
|
81
118
|
expected_text << @executed_requests_info
|
82
119
|
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
83
120
|
end
|
@@ -122,14 +159,14 @@ describe WebMock::RequestExecutionVerifier do
|
|
122
159
|
|
123
160
|
describe "matches?" do
|
124
161
|
|
125
|
-
it "
|
162
|
+
it "succeeds if request was executed expected number of times" do
|
126
163
|
expect(WebMock::RequestRegistry.instance).
|
127
164
|
to receive(:times_executed).with(@request_pattern).and_return(10)
|
128
165
|
@verifier.expected_times_executed = 10
|
129
166
|
expect(@verifier.matches?).to be_truthy
|
130
167
|
end
|
131
168
|
|
132
|
-
it "
|
169
|
+
it "fails if request was not executed expected number of times" do
|
133
170
|
expect(WebMock::RequestRegistry.instance).
|
134
171
|
to receive(:times_executed).with(@request_pattern).and_return(10)
|
135
172
|
@verifier.expected_times_executed = 5
|
@@ -140,26 +177,26 @@ describe WebMock::RequestExecutionVerifier do
|
|
140
177
|
|
141
178
|
describe "does_not_match?" do
|
142
179
|
|
143
|
-
it "
|
180
|
+
it "fails if request executed expected number of times" do
|
144
181
|
expect(WebMock::RequestRegistry.instance).
|
145
182
|
to receive(:times_executed).with(@request_pattern).and_return(10)
|
146
183
|
@verifier.expected_times_executed = 10
|
147
184
|
expect(@verifier.does_not_match?).to be_falsey
|
148
185
|
end
|
149
186
|
|
150
|
-
it "
|
187
|
+
it "succeeds if request was not executed at all and expected number of times was not set" do
|
151
188
|
expect(WebMock::RequestRegistry.instance).
|
152
189
|
to receive(:times_executed).with(@request_pattern).and_return(0)
|
153
190
|
expect(@verifier.does_not_match?).to be_truthy
|
154
191
|
end
|
155
192
|
|
156
|
-
it "
|
193
|
+
it "fails if request was executed and expected number of times was not set" do
|
157
194
|
expect(WebMock::RequestRegistry.instance).
|
158
195
|
to receive(:times_executed).with(@request_pattern).and_return(1)
|
159
196
|
expect(@verifier.does_not_match?).to be_falsey
|
160
197
|
end
|
161
198
|
|
162
|
-
it "
|
199
|
+
it "succeeds if request was not executed expected number of times" do
|
163
200
|
expect(WebMock::RequestRegistry.instance).
|
164
201
|
to receive(:times_executed).with(@request_pattern).and_return(10)
|
165
202
|
@verifier.expected_times_executed = 5
|