webmock 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +35 -0
- data/README.md +10 -24
- data/VERSION +1 -1
- data/lib/webmock.rb +4 -0
- data/lib/webmock/api.rb +1 -1
- data/lib/webmock/assertion_failure.rb +2 -4
- data/lib/webmock/cucumber.rb +8 -0
- data/lib/webmock/errors.rb +13 -1
- data/lib/webmock/http_lib_adapters/curb.rb +2 -2
- data/lib/webmock/http_lib_adapters/em_http_request.rb +31 -17
- data/lib/webmock/http_lib_adapters/httpclient.rb +3 -3
- data/lib/webmock/http_lib_adapters/net_http.rb +2 -2
- data/lib/webmock/http_lib_adapters/patron.rb +2 -2
- data/lib/webmock/request_execution_verifier.rb +18 -4
- data/lib/webmock/request_pattern.rb +1 -1
- data/lib/webmock/request_registry.rb +13 -28
- data/lib/webmock/request_signature.rb +15 -2
- data/lib/webmock/rspec.rb +32 -1
- data/lib/webmock/{adapters/rspec → rspec}/matchers.rb +4 -0
- data/lib/webmock/{adapters/rspec → rspec/matchers}/request_pattern_matcher.rb +0 -0
- data/lib/webmock/{adapters/rspec → rspec/matchers}/webmock_matcher.rb +0 -0
- data/lib/webmock/stub_registry.rb +43 -0
- data/lib/webmock/stub_request_snippet.rb +27 -0
- data/lib/webmock/test_unit.rb +20 -1
- data/lib/webmock/util/hash_counter.rb +9 -4
- data/lib/webmock/util/hash_keys_stringifier.rb +23 -0
- data/lib/webmock/webmock.rb +14 -4
- data/spec/curb_spec.rb +1 -1
- data/spec/curb_spec_helper.rb +0 -4
- data/spec/em_http_request_spec.rb +5 -0
- data/spec/em_http_request_spec_helper.rb +0 -4
- data/spec/errors_spec.rb +17 -0
- data/spec/httpclient_spec_helper.rb +0 -4
- data/spec/net_http_spec_helper.rb +2 -8
- data/spec/patron_spec_helper.rb +4 -11
- data/spec/request_execution_verifier_spec.rb +14 -4
- data/spec/request_registry_spec.rb +29 -80
- data/spec/request_signature_spec.rb +77 -3
- data/spec/spec_helper.rb +0 -18
- data/spec/stub_registry_spec.rb +86 -0
- data/spec/stub_request_snippet_spec.rb +47 -0
- data/spec/util/hash_counter_spec.rb +15 -0
- data/spec/util/hash_keys_stringifier_spec.rb +27 -0
- data/spec/webmock_shared.rb +63 -66
- data/test/test_helper.rb +5 -1
- data/test/test_webmock.rb +5 -2
- data/webmock.gemspec +17 -7
- metadata +19 -9
- data/lib/webmock/adapters/rspec.rb +0 -33
- data/lib/webmock/adapters/test_unit.rb +0 -19
@@ -3,102 +3,26 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe WebMock::RequestRegistry do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
WebMock::RequestRegistry.instance.
|
6
|
+
WebMock::RequestRegistry.instance.reset!
|
7
7
|
@request_pattern = WebMock::RequestPattern.new(:get, "www.example.com")
|
8
8
|
@request_signature = WebMock::RequestSignature.new(:get, "www.example.com")
|
9
|
-
@request_stub = WebMock::RequestStub.new(:get, "www.example.com")
|
10
9
|
end
|
11
10
|
|
12
|
-
describe "
|
11
|
+
describe "reset!" do
|
13
12
|
before(:each) do
|
14
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
15
13
|
WebMock::RequestRegistry.instance.requested_signatures.put(@request_signature)
|
16
14
|
end
|
17
15
|
|
18
|
-
it "should clean request stubs" do
|
19
|
-
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
20
|
-
WebMock::RequestRegistry.instance.reset_webmock
|
21
|
-
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
22
|
-
end
|
23
|
-
|
24
16
|
it "should clean list of executed requests" do
|
25
17
|
WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 1
|
26
|
-
WebMock::RequestRegistry.instance.
|
18
|
+
WebMock::RequestRegistry.instance.reset!
|
27
19
|
WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 0
|
28
20
|
end
|
29
21
|
|
30
22
|
end
|
31
23
|
|
32
|
-
describe "registering and reporting registered requests" do
|
33
|
-
|
34
|
-
it "should return registered stub" do
|
35
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub).should == @request_stub
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should report if request stub is not registered" do
|
39
|
-
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should register and report registered stib" do
|
43
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
44
|
-
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "response for request" do
|
51
|
-
|
52
|
-
it "should report registered evaluated response for request pattern" do
|
53
|
-
@request_stub.to_return(:body => "abc")
|
54
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
55
|
-
WebMock::RequestRegistry.instance.response_for_request(@request_signature).
|
56
|
-
should == WebMock::Response.new(:body => "abc")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should report evaluated response" do
|
60
|
-
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
61
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
62
|
-
response1 = WebMock::RequestRegistry.instance.response_for_request(@request_signature)
|
63
|
-
response1.should == WebMock::Response.new(:body => "get")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should report clone of theresponse" do
|
67
|
-
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
68
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
69
|
-
response1 = WebMock::RequestRegistry.instance.response_for_request(@request_signature)
|
70
|
-
response2 = WebMock::RequestRegistry.instance.response_for_request(@request_signature)
|
71
|
-
response1.should_not be(response2)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should report nothing if no response for request is registered" do
|
75
|
-
WebMock::RequestRegistry.instance.response_for_request(@request_signature).should == nil
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should always return last registered matching response" do
|
79
|
-
@request_stub1 = WebMock::RequestStub.new(:get, "www.example.com")
|
80
|
-
@request_stub1.to_return(:body => "abc")
|
81
|
-
@request_stub2 = WebMock::RequestStub.new(:get, "www.example.com")
|
82
|
-
@request_stub2.to_return(:body => "def")
|
83
|
-
@request_stub3 = WebMock::RequestStub.new(:get, "www.example.org")
|
84
|
-
@request_stub3.to_return(:body => "ghj")
|
85
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub1)
|
86
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub2)
|
87
|
-
WebMock::RequestRegistry.instance.register_request_stub(@request_stub3)
|
88
|
-
WebMock::RequestRegistry.instance.response_for_request(@request_signature).
|
89
|
-
should == WebMock::Response.new(:body => "def")
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
24
|
describe "times executed" do
|
95
25
|
|
96
|
-
def times_executed(request_pattern)
|
97
|
-
self.requested.hash.select { |executed_request_pattern, times_executed|
|
98
|
-
executed_request_pattern.match(request_pattern)
|
99
|
-
}.inject(0) {|sum, (_, times_executed)| sum =+ times_executed }
|
100
|
-
end
|
101
|
-
|
102
26
|
before(:each) do
|
103
27
|
@request_stub1 = WebMock::RequestStub.new(:get, "www.example.com")
|
104
28
|
@request_stub2 = WebMock::RequestStub.new(:get, "www.example.net")
|
@@ -117,10 +41,35 @@ describe WebMock::RequestRegistry do
|
|
117
41
|
end
|
118
42
|
|
119
43
|
it "should report number of times all matching pattern were requested" do
|
120
|
-
|
44
|
+
WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, /.*example.*/)).should == 3
|
121
45
|
end
|
46
|
+
end
|
122
47
|
|
48
|
+
describe "request_signatures" do
|
49
|
+
it "should return hash of unique request signatures with accumulated number" do
|
50
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
|
51
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
|
52
|
+
WebMock::RequestRegistry.instance.requested_signatures.
|
53
|
+
get(WebMock::RequestSignature.new(:get, "www.example.com")).should == 2
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "to_s" do
|
58
|
+
it "should output string with all executed requests and numbers of executions" do
|
59
|
+
[
|
60
|
+
WebMock::RequestSignature.new(:get, "www.example.com"),
|
61
|
+
WebMock::RequestSignature.new(:get, "www.example.com"),
|
62
|
+
WebMock::RequestSignature.new(:put, "www.example.org"),
|
63
|
+
].each do |s|
|
64
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(s)
|
65
|
+
end
|
66
|
+
WebMock::RequestRegistry.instance.to_s.should ==
|
67
|
+
"GET http://www.example.com/ was made 2 times\nPUT http://www.example.org/ was made 1 time\n"
|
68
|
+
end
|
123
69
|
|
70
|
+
it "should output info if no requests were executed" do
|
71
|
+
WebMock::RequestRegistry.instance.to_s.should == "No requests were made."
|
72
|
+
end
|
124
73
|
end
|
125
74
|
|
126
75
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe WebMock::RequestSignature do
|
4
|
-
|
4
|
+
|
5
5
|
describe "initialization" do
|
6
6
|
|
7
7
|
it "should have assigned normalized uri" do
|
@@ -33,5 +33,79 @@ describe WebMock::RequestSignature do
|
|
33
33
|
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s.should ==
|
34
34
|
"GET http://www.example.com/ with body 'abc' with headers {'A'=>'a', 'B'=>'b'}"
|
35
35
|
end
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
describe "hash" do
|
38
|
+
it "should report same hash for two signatures with the same values" do
|
39
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com",
|
40
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
|
41
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
|
42
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
|
43
|
+
signature1.hash.should == signature2.hash
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should report different hash for two signatures with different method" do
|
47
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
|
48
|
+
signature2 = WebMock::RequestSignature.new(:put, "www.example.com")
|
49
|
+
signature1.hash.should_not == signature2.hash
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should report different hash for two signatures with different uri" do
|
53
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
|
54
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.org")
|
55
|
+
signature1.hash.should_not == signature2.hash
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should report different hash for two signatures with different body" do
|
59
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")
|
60
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "def")
|
61
|
+
signature1.hash.should_not == signature2.hash
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should report different hash for two signatures with different headers" do
|
65
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com",
|
66
|
+
:headers => {'A' => 'a'})
|
67
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
|
68
|
+
:headers => {'A' => 'A'})
|
69
|
+
signature1.hash.should_not == signature2.hash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe "eql?" do
|
75
|
+
it "should be true for two signatures with the same values" do
|
76
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com",
|
77
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
|
78
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
|
79
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
|
80
|
+
|
81
|
+
signature1.should eql(signature2)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be false for two signatures with different method" do
|
85
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
|
86
|
+
signature2 = WebMock::RequestSignature.new(:put, "www.example.com")
|
87
|
+
signature1.should_not eql(signature2)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should be false for two signatures with different uri" do
|
91
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
|
92
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.org")
|
93
|
+
signature1.should_not eql(signature2)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be false for two signatures with different body" do
|
97
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")
|
98
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "def")
|
99
|
+
signature1.should_not eql(signature2)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be false for two signatures with different headers" do
|
103
|
+
signature1 = WebMock::RequestSignature.new(:get, "www.example.com",
|
104
|
+
:headers => {'A' => 'a'})
|
105
|
+
signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
|
106
|
+
:headers => {'A' => 'A'})
|
107
|
+
signature1.should_not eql(signature2)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,8 +14,6 @@ require 'webmock/rspec'
|
|
14
14
|
|
15
15
|
require 'network_connection'
|
16
16
|
|
17
|
-
require 'json'
|
18
|
-
|
19
17
|
RSpec.configure do |config|
|
20
18
|
config.include WebMock::API
|
21
19
|
unless NetworkConnection.is_network_available?
|
@@ -49,19 +47,3 @@ def setup_expectations_for_real_example_com_request(options = {})
|
|
49
47
|
setup_expectations_for_real_request(defaults.merge(options))
|
50
48
|
end
|
51
49
|
|
52
|
-
def client_specific_request_string(string)
|
53
|
-
method = string.gsub(/.*Unregistered request: ([^ ]+).+/, '\1')
|
54
|
-
has_body = string.include?(" with body")
|
55
|
-
default_headers = default_client_request_headers(method, has_body)
|
56
|
-
if default_headers
|
57
|
-
if string.include?(" with headers")
|
58
|
-
current_headers = JSON.parse(string.gsub(/.*with headers (\{[^}]+\}).*/, '\1').gsub("=>",":").gsub("'","\""))
|
59
|
-
default_headers = WebMock::Util::Headers.normalize_headers(default_headers)
|
60
|
-
default_headers.merge!(current_headers)
|
61
|
-
string.gsub!(/(.*) with headers.*/,'\1')
|
62
|
-
end
|
63
|
-
string << " with headers #{WebMock::Util::Headers.sorted_headers_string(default_headers)}"
|
64
|
-
end
|
65
|
-
string
|
66
|
-
end
|
67
|
-
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe WebMock::StubRegistry do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
WebMock::StubRegistry.instance.reset!
|
7
|
+
@request_pattern = WebMock::RequestPattern.new(:get, "www.example.com")
|
8
|
+
@request_signature = WebMock::RequestSignature.new(:get, "www.example.com")
|
9
|
+
@request_stub = WebMock::RequestStub.new(:get, "www.example.com")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "reset!" do
|
13
|
+
before(:each) do
|
14
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should clean request stubs" do
|
18
|
+
WebMock::StubRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
19
|
+
WebMock::StubRegistry.instance.reset!
|
20
|
+
WebMock::StubRegistry.instance.registered_request?(@request_signature).should == nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "registering and reporting registered requests" do
|
25
|
+
|
26
|
+
it "should return registered stub" do
|
27
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub).should == @request_stub
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should report if request stub is not registered" do
|
31
|
+
WebMock::StubRegistry.instance.registered_request?(@request_signature).should == nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should register and report registered stib" do
|
35
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
|
36
|
+
WebMock::StubRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "response for request" do
|
43
|
+
|
44
|
+
it "should report registered evaluated response for request pattern" do
|
45
|
+
@request_stub.to_return(:body => "abc")
|
46
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
|
47
|
+
WebMock::StubRegistry.instance.response_for_request(@request_signature).
|
48
|
+
should == WebMock::Response.new(:body => "abc")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should report evaluated response" do
|
52
|
+
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
53
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
|
54
|
+
response1 = WebMock::StubRegistry.instance.response_for_request(@request_signature)
|
55
|
+
response1.should == WebMock::Response.new(:body => "get")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should report clone of theresponse" do
|
59
|
+
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
60
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
|
61
|
+
response1 = WebMock::StubRegistry.instance.response_for_request(@request_signature)
|
62
|
+
response2 = WebMock::StubRegistry.instance.response_for_request(@request_signature)
|
63
|
+
response1.should_not be(response2)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should report nothing if no response for request is registered" do
|
67
|
+
WebMock::StubRegistry.instance.response_for_request(@request_signature).should == nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should always return last registered matching response" do
|
71
|
+
@request_stub1 = WebMock::RequestStub.new(:get, "www.example.com")
|
72
|
+
@request_stub1.to_return(:body => "abc")
|
73
|
+
@request_stub2 = WebMock::RequestStub.new(:get, "www.example.com")
|
74
|
+
@request_stub2.to_return(:body => "def")
|
75
|
+
@request_stub3 = WebMock::RequestStub.new(:get, "www.example.org")
|
76
|
+
@request_stub3.to_return(:body => "ghj")
|
77
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub1)
|
78
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub2)
|
79
|
+
WebMock::StubRegistry.instance.register_request_stub(@request_stub3)
|
80
|
+
WebMock::StubRegistry.instance.response_for_request(@request_signature).
|
81
|
+
should == WebMock::Response.new(:body => "def")
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe WebMock::StubRequestSnippet do
|
4
|
+
describe "to_s" do
|
5
|
+
before(:each) do
|
6
|
+
@request_signature = WebMock::RequestSignature.new(:get, "www.example.com/?a=b&c=d")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should print stub request snippet with url with params and method and empty successful response" do
|
10
|
+
expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").\n to_return(:status => 200, :body => "", :headers => {}))
|
11
|
+
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should print stub request snippet with body if available" do
|
15
|
+
@request_signature.body = "abcdef"
|
16
|
+
expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
|
17
|
+
"\n with(:body => \"abcdef\")." +
|
18
|
+
"\n to_return(:status => 200, :body => \"\", :headers => {})"
|
19
|
+
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should print stub request snippet with multiline body" do
|
23
|
+
@request_signature.body = "abc\ndef"
|
24
|
+
expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
|
25
|
+
"\n with(:body => \"abc\\ndef\")." +
|
26
|
+
"\n to_return(:status => 200, :body => \"\", :headers => {})"
|
27
|
+
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should print stub request snippet with headers if any" do
|
31
|
+
@request_signature.headers = {'B' => 'b', 'A' => 'a'}
|
32
|
+
expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
|
33
|
+
"\n with(:headers => {\'A\'=>\'a\', \'B\'=>\'b\'})." +
|
34
|
+
"\n to_return(:status => 200, :body => \"\", :headers => {})"
|
35
|
+
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should print stub request snippet with body and headers" do
|
39
|
+
@request_signature.body = "abcdef"
|
40
|
+
@request_signature.headers = {'B' => 'b', 'A' => 'a'}
|
41
|
+
expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
|
42
|
+
"\n with(:body => \"abcdef\", \n :headers => {\'A\'=>\'a\', \'B\'=>\'b\'})." +
|
43
|
+
"\n to_return(:status => 200, :body => \"\", :headers => {})"
|
44
|
+
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -21,4 +21,19 @@ describe WebMock::Util::HashCounter do
|
|
21
21
|
counter.get(:def).should == 0
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "each" do
|
25
|
+
it "should provide elements in order of the last modified" do
|
26
|
+
counter = WebMock::Util::HashCounter.new
|
27
|
+
counter.put(:a)
|
28
|
+
counter.put(:b)
|
29
|
+
counter.put(:c)
|
30
|
+
counter.put(:b)
|
31
|
+
counter.put(:a)
|
32
|
+
counter.put(:d)
|
33
|
+
|
34
|
+
elements = []
|
35
|
+
counter.each {|k,v| elements << [k,v]}
|
36
|
+
elements.should == [[:c, 1], [:b, 2], [:a, 2], [:d, 1]]
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe WebMock::Util::HashKeysStringifier do
|
4
|
+
|
5
|
+
it "should recursively stringify all symbol keys" do
|
6
|
+
hash = {
|
7
|
+
:a => {
|
8
|
+
:b => [
|
9
|
+
{
|
10
|
+
:c => [{:d => "1"}]
|
11
|
+
}
|
12
|
+
]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
stringified = {
|
16
|
+
'a' => {
|
17
|
+
'b' => [
|
18
|
+
{
|
19
|
+
'c' => [{'d' => "1"}]
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
WebMock::Util::HashKeysStringifier.stringify_keys!(hash).should == stringified
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/webmock_shared.rb
CHANGED
@@ -21,7 +21,7 @@ end
|
|
21
21
|
shared_examples_for "WebMock" do
|
22
22
|
before(:each) do
|
23
23
|
WebMock.disable_net_connect!
|
24
|
-
WebMock
|
24
|
+
WebMock.reset!
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "when web connect" do
|
@@ -63,11 +63,16 @@ shared_examples_for "WebMock" do
|
|
63
63
|
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
|
64
64
|
http_request(:get, "http://www.example.com/").body.should == "abc"
|
65
65
|
end
|
66
|
+
|
67
|
+
it "should return stubbed response if request with path was stubbed" do
|
68
|
+
stub_http_request(:get, "www.example.com/hello_world").to_return(:body => "abc")
|
69
|
+
http_request(:get, "http://www.example.com/hello_world").body.should == "abc"
|
70
|
+
end
|
66
71
|
|
67
72
|
it "should raise exception if request was not stubbed" do
|
68
73
|
lambda {
|
69
74
|
http_request(:get, "http://www.example.com/")
|
70
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
75
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
@@ -84,7 +89,7 @@ shared_examples_for "WebMock" do
|
|
84
89
|
it "should raise exception if request was not stubbed" do
|
85
90
|
lambda {
|
86
91
|
http_request(:get, "http://www.example.com/")
|
87
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
92
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
88
93
|
end
|
89
94
|
|
90
95
|
it "should allow a real request to localhost" do
|
@@ -119,7 +124,7 @@ shared_examples_for "WebMock" do
|
|
119
124
|
it "should raise exception if request was not stubbed" do
|
120
125
|
lambda {
|
121
126
|
http_request(:get, "http://www.example.com/")
|
122
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
127
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
123
128
|
end
|
124
129
|
|
125
130
|
it "should allow a real request to allowed host", :net_connect => true do
|
@@ -133,18 +138,18 @@ shared_examples_for "WebMock" do
|
|
133
138
|
describe "on uri" do
|
134
139
|
|
135
140
|
it "should match the request by uri with non escaped params if request have escaped parameters" do
|
136
|
-
stub_http_request(:get, "www.example.com/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
|
137
|
-
http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").body.should == "abc"
|
141
|
+
stub_http_request(:get, "www.example.com/hello/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
|
142
|
+
http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
|
138
143
|
end
|
139
144
|
|
140
145
|
it "should match the request by uri with escaped parameters even if request has non escaped params" do
|
141
|
-
stub_http_request(:get, "www.example.com/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
|
142
|
-
http_request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
|
146
|
+
stub_http_request(:get, "www.example.com/hello/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
|
147
|
+
http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
|
143
148
|
end
|
144
149
|
|
145
150
|
it "should match the request by regexp matching non escaped params uri if request params are escaped" do
|
146
151
|
stub_http_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
|
147
|
-
http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").body.should == "abc"
|
152
|
+
http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
|
148
153
|
end
|
149
154
|
|
150
155
|
end
|
@@ -180,8 +185,7 @@ shared_examples_for "WebMock" do
|
|
180
185
|
http_request(:get, "http://www.example.com/").status.should == "200"
|
181
186
|
lambda {
|
182
187
|
http_request(:delete, "http://www.example.com/")
|
183
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
184
|
-
"Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/")
|
188
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
|
185
189
|
)
|
186
190
|
end
|
187
191
|
|
@@ -207,8 +211,7 @@ shared_examples_for "WebMock" do
|
|
207
211
|
stub_http_request(:post, "www.example.com").with(:body => "abc")
|
208
212
|
lambda {
|
209
213
|
http_request(:post, "http://www.example.com/", :body => "def")
|
210
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
211
|
-
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'"))
|
214
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
|
212
215
|
end
|
213
216
|
|
214
217
|
describe "with regular expressions" do
|
@@ -224,8 +227,7 @@ shared_examples_for "WebMock" do
|
|
224
227
|
stub_http_request(:post, "www.example.com").with(:body => /^abc/)
|
225
228
|
lambda {
|
226
229
|
http_request(:post, "http://www.example.com/", :body => "xabc")
|
227
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
228
|
-
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'"))
|
230
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
|
229
231
|
end
|
230
232
|
|
231
233
|
end
|
@@ -255,9 +257,7 @@ shared_examples_for "WebMock" do
|
|
255
257
|
http_request(
|
256
258
|
:post, "http://www.example.com/",
|
257
259
|
:body => 'c[d][]=f&a=1&c[d][]=e').status.should == "200"
|
258
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
259
|
-
"Real HTTP connections are disabled. Unregistered request: "+
|
260
|
-
"POST http://www.example.com/ with body 'c[d][]=f&a=1&c[d][]=e'"))
|
260
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'c\[d\]\[\]=f&a=1&c\[d\]\[\]=e'))
|
261
261
|
end
|
262
262
|
|
263
263
|
end
|
@@ -281,7 +281,7 @@ shared_examples_for "WebMock" do
|
|
281
281
|
|
282
282
|
describe "for request with xml body and content type is set to xml" do
|
283
283
|
before(:each) do
|
284
|
-
WebMock.
|
284
|
+
WebMock.reset!
|
285
285
|
stub_http_request(:post, "www.example.com").
|
286
286
|
with(:body => { "opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']} }})
|
287
287
|
end
|
@@ -343,8 +343,7 @@ shared_examples_for "WebMock" do
|
|
343
343
|
http_request(
|
344
344
|
:get, "http://www.example.com/",
|
345
345
|
:headers => {"a" => ["b", "d"]})
|
346
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
347
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'A'=>['b', 'd']})))
|
346
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
|
348
347
|
end
|
349
348
|
|
350
349
|
end
|
@@ -363,8 +362,7 @@ shared_examples_for "WebMock" do
|
|
363
362
|
http_request(
|
364
363
|
:get, "http://www.example.com/",
|
365
364
|
:headers => { 'Content-Length' => '9999'})
|
366
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
367
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Content-Length'=>'9999'})))
|
365
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
|
368
366
|
end
|
369
367
|
|
370
368
|
it "should not match if accept header is different" do
|
@@ -374,8 +372,7 @@ shared_examples_for "WebMock" do
|
|
374
372
|
http_request(
|
375
373
|
:get, "http://www.example.com/",
|
376
374
|
:headers => { 'Accept' => 'application/xml'})
|
377
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
378
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Accept'=>'application/xml'})))
|
375
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
|
379
376
|
end
|
380
377
|
|
381
378
|
describe "with regular expressions" do
|
@@ -394,8 +391,7 @@ shared_examples_for "WebMock" do
|
|
394
391
|
http_request(
|
395
392
|
:get, "http://www.example.com/",
|
396
393
|
:headers => { 'user-agent' => 'xMyAppName' })
|
397
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
398
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'User-Agent'=>'xMyAppName'})))
|
394
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
|
399
395
|
end
|
400
396
|
|
401
397
|
end
|
@@ -412,24 +408,21 @@ shared_examples_for "WebMock" do
|
|
412
408
|
stub_http_request(:get, "user:pass@www.example.com")
|
413
409
|
lambda {
|
414
410
|
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
|
415
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
416
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
|
411
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
|
417
412
|
end
|
418
413
|
|
419
414
|
it "should not match if credentials are stubbed but not provided in the request" do
|
420
415
|
stub_http_request(:get, "user:pass@www.example.com")
|
421
416
|
lambda {
|
422
417
|
http_request(:get, "http://www.example.com/").status.should == "200"
|
423
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
424
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/)))
|
418
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
425
419
|
end
|
426
420
|
|
427
421
|
it "should not match if credentials are not stubbed but exist in the request" do
|
428
422
|
stub_http_request(:get, "www.example.com")
|
429
423
|
lambda {
|
430
424
|
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
|
431
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
432
|
-
%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
|
425
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
|
433
426
|
end
|
434
427
|
|
435
428
|
end
|
@@ -445,8 +438,7 @@ shared_examples_for "WebMock" do
|
|
445
438
|
stub_http_request(:get, "www.example.com").with { |request| false }
|
446
439
|
lambda {
|
447
440
|
http_request(:get, "http://www.example.com/")
|
448
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
449
|
-
"Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
|
441
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
450
442
|
end
|
451
443
|
|
452
444
|
it "should pass the request to the block" do
|
@@ -456,8 +448,7 @@ shared_examples_for "WebMock" do
|
|
456
448
|
:body => "wadus").status.should == "200"
|
457
449
|
lambda {
|
458
450
|
http_request(:post, "http://www.example.com/", :body => "jander")
|
459
|
-
}.should raise_error(WebMock::NetConnectNotAllowedError,
|
460
|
-
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'"))
|
451
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
|
461
452
|
end
|
462
453
|
|
463
454
|
end
|
@@ -879,28 +870,34 @@ shared_examples_for "WebMock" do
|
|
879
870
|
lambda {
|
880
871
|
http_request(:get, "http://www.example.com/")
|
881
872
|
a_request(:get, "http://www.example.com").should_not have_been_made
|
882
|
-
}.should fail_with(
|
873
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time))
|
874
|
+
end
|
875
|
+
|
876
|
+
it "should fail with message with executed requests listed" do
|
877
|
+
lambda {
|
878
|
+
http_request(:get, "http://www.example.com/")
|
879
|
+
a_request(:get, "http://www.example.com").should_not have_been_made
|
880
|
+
}.should fail_with(%r{The following requests were made:\n\nGET http://www.example.com/.+was made 1 time})
|
883
881
|
end
|
884
|
-
|
885
882
|
|
886
883
|
it "should fail if request was not executed" do
|
887
884
|
lambda {
|
888
885
|
a_request(:get, "http://www.example.com").should have_been_made
|
889
|
-
}.should fail_with(
|
886
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times))
|
890
887
|
end
|
891
888
|
|
892
889
|
it "should fail if request was executed to different uri" do
|
893
890
|
lambda {
|
894
891
|
http_request(:get, "http://www.example.com/")
|
895
892
|
a_request(:get, "http://www.example.org").should have_been_made
|
896
|
-
}.should fail_with(
|
893
|
+
}.should fail_with(%r(The request GET http://www.example.org/ was expected to execute 1 time but it executed 0 times))
|
897
894
|
end
|
898
895
|
|
899
896
|
it "should fail if request was executed with different method" do
|
900
897
|
lambda {
|
901
898
|
http_request(:post, "http://www.example.com/", :body => "abc")
|
902
899
|
a_request(:get, "http://www.example.com").should have_been_made
|
903
|
-
}.should fail_with(
|
900
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times))
|
904
901
|
end
|
905
902
|
|
906
903
|
it "should pass if request was executed with different form of uri" do
|
@@ -928,7 +925,7 @@ shared_examples_for "WebMock" do
|
|
928
925
|
lambda {
|
929
926
|
http_request(:get, "http://www.example.com:80/")
|
930
927
|
a_request(:get, "www.example.com:90").should have_been_made
|
931
|
-
}.should fail_with(
|
928
|
+
}.should fail_with(%r(The request GET http://www.example.com:90/ was expected to execute 1 time but it executed 0 times))
|
932
929
|
end
|
933
930
|
|
934
931
|
it "should pass if request was executed with different form of uri with https port" do
|
@@ -1001,21 +998,21 @@ shared_examples_for "WebMock" do
|
|
1001
998
|
http_request(:get, "http://www.example.com/")
|
1002
999
|
http_request(:get, "http://www.example.com/")
|
1003
1000
|
a_request(:get, "http://www.example.com").should have_been_made
|
1004
|
-
}.should fail_with(
|
1001
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 1 time but it executed 2 times))
|
1005
1002
|
end
|
1006
1003
|
|
1007
1004
|
it "should fail if requested less times than expected" do
|
1008
1005
|
lambda {
|
1009
1006
|
http_request(:get, "http://www.example.com/")
|
1010
1007
|
a_request(:get, "http://www.example.com").should have_been_made.twice
|
1011
|
-
}.should fail_with(
|
1008
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 2 times but it executed 1 time))
|
1012
1009
|
end
|
1013
1010
|
|
1014
1011
|
it "should fail if requested less times than expected when 3 times expected" do
|
1015
1012
|
lambda {
|
1016
1013
|
http_request(:get, "http://www.example.com/")
|
1017
1014
|
a_request(:get, "http://www.example.com").should have_been_made.times(3)
|
1018
|
-
}.should fail_with(
|
1015
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 3 times but it executed 1 time))
|
1019
1016
|
end
|
1020
1017
|
|
1021
1018
|
it "should succeed if request was executed with the same body" do
|
@@ -1030,7 +1027,7 @@ shared_examples_for "WebMock" do
|
|
1030
1027
|
http_request(:get, "http://www.example.com/", :body => "abc")
|
1031
1028
|
a_request(:get, "www.example.com").
|
1032
1029
|
with(:body => "def").should have_been_made
|
1033
|
-
}.should fail_with(
|
1030
|
+
}.should fail_with(%r(The request GET http://www.example.com/ with body "def" was expected to execute 1 time but it executed 0 times))
|
1034
1031
|
end
|
1035
1032
|
|
1036
1033
|
describe "when expected body is declared as regexp" do
|
@@ -1047,14 +1044,14 @@ shared_examples_for "WebMock" do
|
|
1047
1044
|
http_request(:get, "http://www.example.com/", :body => /^abc/)
|
1048
1045
|
a_request(:get, "www.example.com").
|
1049
1046
|
with(:body => "xabc").should have_been_made
|
1050
|
-
}.should fail_with(
|
1047
|
+
}.should fail_with(%r(The request GET http://www.example.com/ with body "xabc" was expected to execute 1 time but it executed 0 times))
|
1051
1048
|
end
|
1052
1049
|
|
1053
1050
|
end
|
1054
1051
|
|
1055
1052
|
describe "when expected body is declared as a hash" do
|
1056
1053
|
let(:body_hash) { {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']}} }
|
1057
|
-
let(:fail_message) {
|
1054
|
+
let(:fail_message) {%r(The request POST http://www.example.com/ with body \{"a"=>"1", "b"=>"five", "c"=>\{"d"=>\["e", "f"\]\}\} was expected to execute 1 time but it executed 0 times)}
|
1058
1055
|
|
1059
1056
|
describe "when request is executed with url encoded body matching hash" do
|
1060
1057
|
|
@@ -1164,7 +1161,7 @@ shared_examples_for "WebMock" do
|
|
1164
1161
|
http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
|
1165
1162
|
a_request(:get, "www.example.com").
|
1166
1163
|
with(:headers => {"a" => ["b", "d"]}).should have_been_made
|
1167
|
-
}.should fail_with(
|
1164
|
+
}.should 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))
|
1168
1165
|
end
|
1169
1166
|
|
1170
1167
|
end
|
@@ -1174,7 +1171,7 @@ shared_examples_for "WebMock" do
|
|
1174
1171
|
http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
|
1175
1172
|
a_request(:get, "www.example.com").
|
1176
1173
|
with(:headers => { 'Content-Length' => '9999'}).should have_been_made
|
1177
|
-
}.should fail_with(
|
1174
|
+
}.should 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))
|
1178
1175
|
end
|
1179
1176
|
|
1180
1177
|
it "should fail if request was executed with less headers" do
|
@@ -1182,7 +1179,7 @@ shared_examples_for "WebMock" do
|
|
1182
1179
|
http_request(:get, "http://www.example.com/", :headers => {'A' => 'a'})
|
1183
1180
|
a_request(:get, "www.example.com").
|
1184
1181
|
with(:headers => {'A' => 'a', 'B' => 'b'}).should have_been_made
|
1185
|
-
}.should fail_with(
|
1182
|
+
}.should 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))
|
1186
1183
|
end
|
1187
1184
|
|
1188
1185
|
it "should succeed if request was executed with more headers" do
|
@@ -1218,7 +1215,7 @@ shared_examples_for "WebMock" do
|
|
1218
1215
|
http_request(:get, "http://www.example.com/", :headers => { 'user_agent' => 'xMyAppName' })
|
1219
1216
|
a_request(:get, "www.example.com").
|
1220
1217
|
with(:headers => { :user_agent => /^MyAppName$/ }).should have_been_made
|
1221
|
-
}.should fail_with(
|
1218
|
+
}.should fail_with(%r(The request GET http://www.example.com/ with headers \{'User-Agent'=>/\^MyAppName\$/\} was expected to execute 1 time but it executed 0 times))
|
1222
1219
|
end
|
1223
1220
|
|
1224
1221
|
it "should suceed if request was executed and block evaluated to true" do
|
@@ -1232,14 +1229,14 @@ shared_examples_for "WebMock" do
|
|
1232
1229
|
lambda {
|
1233
1230
|
http_request(:post, "http://www.example.com/", :body => "abc")
|
1234
1231
|
a_request(:post, "www.example.com").with { |req| req.body == "wadus" }.should have_been_made
|
1235
|
-
}.should fail_with(
|
1232
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
|
1236
1233
|
end
|
1237
1234
|
|
1238
1235
|
it "should fail if request was not expected but it executed and block matched request" do
|
1239
1236
|
lambda {
|
1240
1237
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
1241
1238
|
a_request(:post, "www.example.com").with { |req| req.body == "wadus" }.should_not have_been_made
|
1242
|
-
}.should fail_with(
|
1239
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 0 times but it executed 1 time))
|
1243
1240
|
end
|
1244
1241
|
|
1245
1242
|
describe "with authentication" do
|
@@ -1259,21 +1256,21 @@ shared_examples_for "WebMock" do
|
|
1259
1256
|
lambda {
|
1260
1257
|
http_request(:get, "http://user:pass@www.example.com/")
|
1261
1258
|
a_request(:get, "http://user:pazz@www.example.com").should have_been_made.once
|
1262
|
-
}.should fail_with(
|
1259
|
+
}.should fail_with(%r(The request GET http://user:pazz@www.example.com/ was expected to execute 1 time but it executed 0 times))
|
1263
1260
|
end
|
1264
1261
|
|
1265
1262
|
it "should fail if request was executed without credentials but credentials were expected" do
|
1266
1263
|
lambda {
|
1267
1264
|
http_request(:get, "http://www.example.com/")
|
1268
1265
|
a_request(:get, "http://user:pass@www.example.com").should have_been_made.once
|
1269
|
-
}.should fail_with(
|
1266
|
+
}.should fail_with(%r(The request GET http://user:pass@www.example.com/ was expected to execute 1 time but it executed 0 times))
|
1270
1267
|
end
|
1271
1268
|
|
1272
1269
|
it "should fail if request was executed with credentials but expected without" do
|
1273
1270
|
lambda {
|
1274
1271
|
http_request(:get, "http://user:pass@www.example.com/")
|
1275
1272
|
a_request(:get, "http://www.example.com").should have_been_made.once
|
1276
|
-
}.should fail_with(
|
1273
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times))
|
1277
1274
|
end
|
1278
1275
|
|
1279
1276
|
it "should be order insensitive" do
|
@@ -1306,7 +1303,7 @@ shared_examples_for "WebMock" do
|
|
1306
1303
|
lambda {
|
1307
1304
|
http_request(:get, "http://www.example.com/")
|
1308
1305
|
WebMock.should_not have_requested(:get, "http://www.example.com")
|
1309
|
-
}.should fail_with(
|
1306
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time))
|
1310
1307
|
end
|
1311
1308
|
|
1312
1309
|
it "should succeed if request was executed and block evaluated to true" do
|
@@ -1320,14 +1317,14 @@ shared_examples_for "WebMock" do
|
|
1320
1317
|
lambda {
|
1321
1318
|
http_request(:post, "http://www.example.com/", :body => "abc")
|
1322
1319
|
WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
|
1323
|
-
}.should fail_with(
|
1320
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
|
1324
1321
|
end
|
1325
1322
|
|
1326
1323
|
it "should fail if request was not expected but executed and block matched request" do
|
1327
1324
|
lambda {
|
1328
1325
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
1329
1326
|
WebMock.should_not have_requested(:post, "www.example.com").with { |req| req.body == "wadus" }
|
1330
|
-
}.should fail_with(
|
1327
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 0 times but it executed 1 time))
|
1331
1328
|
end
|
1332
1329
|
end
|
1333
1330
|
|
@@ -1354,14 +1351,14 @@ shared_examples_for "WebMock" do
|
|
1354
1351
|
lambda {
|
1355
1352
|
http_request(:get, "http://www.example.com/")
|
1356
1353
|
assert_not_requested(:get, "http://www.example.com")
|
1357
|
-
}.should fail_with(
|
1354
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time))
|
1358
1355
|
end
|
1359
1356
|
|
1360
1357
|
it "should verify if non expected request executed and block evaluated to true" do
|
1361
1358
|
lambda {
|
1362
1359
|
http_request(:post, "http://www.example.com/", :body => "wadus")
|
1363
1360
|
assert_not_requested(:post, "www.example.com") { |req| req.body == "wadus" }
|
1364
|
-
}.should fail_with(
|
1361
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 0 times but it executed 1 time))
|
1365
1362
|
end
|
1366
1363
|
|
1367
1364
|
it "should verify if request was executed and block evaluated to true" do
|
@@ -1375,7 +1372,7 @@ shared_examples_for "WebMock" do
|
|
1375
1372
|
lambda {
|
1376
1373
|
http_request(:post, "http://www.example.com/", :body => "abc")
|
1377
1374
|
assert_requested(:post, "www.example.com") { |req| req.body == "wadus" }
|
1378
|
-
}.should fail_with(
|
1375
|
+
}.should fail_with(%r(The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times))
|
1379
1376
|
end
|
1380
1377
|
end
|
1381
1378
|
end
|
@@ -1398,7 +1395,7 @@ shared_examples_for "WebMock" do
|
|
1398
1395
|
lambda {
|
1399
1396
|
http_request(:get, "http://www.example.com/")
|
1400
1397
|
a_request(:get, "http://www.example.com").should_not have_been_made
|
1401
|
-
}.should fail_with(
|
1398
|
+
}.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time))
|
1402
1399
|
end
|
1403
1400
|
end
|
1404
1401
|
|
@@ -1487,7 +1484,7 @@ shared_examples_for "WebMock" do
|
|
1487
1484
|
|
1488
1485
|
describe "for real requests", :net_connect => true do
|
1489
1486
|
before(:each) do
|
1490
|
-
WebMock.
|
1487
|
+
WebMock.reset!
|
1491
1488
|
WebMock.allow_net_connect!
|
1492
1489
|
WebMock.after_request(:except => [:other_lib]) do |_, response|
|
1493
1490
|
@response = response
|