webmock 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +23 -0
- data/README.md +17 -20
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/lib/webmock.rb +5 -0
- data/lib/webmock/adapters/rspec.rb +12 -9
- data/lib/webmock/adapters/test_unit.rb +1 -6
- data/lib/webmock/api.rb +32 -0
- data/lib/webmock/assertion_failure.rb +13 -0
- data/lib/webmock/deprecation.rb +9 -0
- data/lib/webmock/http_lib_adapters/curb.rb +260 -0
- data/lib/webmock/http_lib_adapters/em_http_request.rb +2 -2
- data/lib/webmock/http_lib_adapters/httpclient.rb +4 -3
- data/lib/webmock/http_lib_adapters/net_http.rb +2 -2
- data/lib/webmock/http_lib_adapters/net_http_response.rb +9 -27
- data/lib/webmock/http_lib_adapters/patron.rb +2 -2
- data/lib/webmock/util/uri.rb +5 -0
- data/lib/webmock/webmock.rb +47 -41
- data/spec/curb_spec.rb +173 -0
- data/spec/curb_spec_helper.rb +137 -0
- data/spec/request_execution_verifier_spec.rb +9 -9
- data/spec/request_pattern_spec.rb +115 -115
- data/spec/request_registry_spec.rb +44 -42
- data/spec/request_signature_spec.rb +6 -6
- data/spec/request_stub_spec.rb +5 -5
- data/spec/response_spec.rb +33 -33
- data/spec/spec_helper.rb +2 -3
- data/spec/util/hash_counter_spec.rb +4 -4
- data/spec/util/headers_spec.rb +4 -4
- data/spec/webmock_spec.rb +67 -54
- data/test/test_helper.rb +2 -2
- data/webmock.gemspec +25 -14
- metadata +34 -29
@@ -1,30 +1,30 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe RequestRegistry do
|
3
|
+
describe WebMock::RequestRegistry do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
RequestRegistry.instance.reset_webmock
|
7
|
-
@request_pattern = RequestPattern.new(:get, "www.example.com")
|
8
|
-
@request_signature = RequestSignature.new(:get, "www.example.com")
|
9
|
-
@request_stub = RequestStub.new(:get, "www.example.com")
|
6
|
+
WebMock::RequestRegistry.instance.reset_webmock
|
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
10
|
end
|
11
11
|
|
12
12
|
describe "reset_webmock" do
|
13
13
|
before(:each) do
|
14
|
-
RequestRegistry.instance.register_request_stub(@request_stub)
|
15
|
-
RequestRegistry.instance.requested_signatures.put(@request_signature)
|
14
|
+
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
15
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(@request_signature)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should clean request stubs" do
|
19
|
-
RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
20
|
-
RequestRegistry.instance.reset_webmock
|
21
|
-
RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
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
22
|
end
|
23
23
|
|
24
24
|
it "should clean list of executed requests" do
|
25
|
-
RequestRegistry.instance.times_executed(@request_pattern).should == 1
|
26
|
-
RequestRegistry.instance.reset_webmock
|
27
|
-
RequestRegistry.instance.times_executed(@request_pattern).should == 0
|
25
|
+
WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 1
|
26
|
+
WebMock::RequestRegistry.instance.reset_webmock
|
27
|
+
WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 0
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -32,16 +32,16 @@ describe RequestRegistry do
|
|
32
32
|
describe "registering and reporting registered requests" do
|
33
33
|
|
34
34
|
it "should return registered stub" do
|
35
|
-
RequestRegistry.instance.register_request_stub(@request_stub).should == @request_stub
|
35
|
+
WebMock::RequestRegistry.instance.register_request_stub(@request_stub).should == @request_stub
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should report if request stub is not registered" do
|
39
|
-
RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
39
|
+
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should register and report registered stib" do
|
43
|
-
RequestRegistry.instance.register_request_stub(@request_stub)
|
44
|
-
RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
43
|
+
WebMock::RequestRegistry.instance.register_request_stub(@request_stub)
|
44
|
+
WebMock::RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
45
45
|
end
|
46
46
|
|
47
47
|
|
@@ -51,40 +51,42 @@ describe RequestRegistry do
|
|
51
51
|
|
52
52
|
it "should report registered evaluated response for request pattern" do
|
53
53
|
@request_stub.to_return(:body => "abc")
|
54
|
-
RequestRegistry.instance.register_request_stub(@request_stub)
|
55
|
-
RequestRegistry.instance.response_for_request(@request_signature).
|
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")
|
56
57
|
end
|
57
58
|
|
58
59
|
it "should report evaluated response" do
|
59
60
|
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
60
|
-
RequestRegistry.instance.register_request_stub(@request_stub)
|
61
|
-
response1 = RequestRegistry.instance.response_for_request(@request_signature)
|
62
|
-
response1.should == Response.new(:body => "get")
|
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")
|
63
64
|
end
|
64
65
|
|
65
66
|
it "should report clone of theresponse" do
|
66
67
|
@request_stub.to_return {|request| {:body => request.method.to_s} }
|
67
|
-
RequestRegistry.instance.register_request_stub(@request_stub)
|
68
|
-
response1 = RequestRegistry.instance.response_for_request(@request_signature)
|
69
|
-
response2 = RequestRegistry.instance.response_for_request(@request_signature)
|
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)
|
70
71
|
response1.should_not be(response2)
|
71
72
|
end
|
72
73
|
|
73
74
|
it "should report nothing if no response for request is registered" do
|
74
|
-
RequestRegistry.instance.response_for_request(@request_signature).should == nil
|
75
|
+
WebMock::RequestRegistry.instance.response_for_request(@request_signature).should == nil
|
75
76
|
end
|
76
77
|
|
77
78
|
it "should always return last registered matching response" do
|
78
|
-
@request_stub1 = RequestStub.new(:get, "www.example.com")
|
79
|
+
@request_stub1 = WebMock::RequestStub.new(:get, "www.example.com")
|
79
80
|
@request_stub1.to_return(:body => "abc")
|
80
|
-
@request_stub2 = RequestStub.new(:get, "www.example.com")
|
81
|
+
@request_stub2 = WebMock::RequestStub.new(:get, "www.example.com")
|
81
82
|
@request_stub2.to_return(:body => "def")
|
82
|
-
@request_stub3 = RequestStub.new(:get, "www.example.org")
|
83
|
+
@request_stub3 = WebMock::RequestStub.new(:get, "www.example.org")
|
83
84
|
@request_stub3.to_return(:body => "ghj")
|
84
|
-
RequestRegistry.instance.register_request_stub(@request_stub1)
|
85
|
-
RequestRegistry.instance.register_request_stub(@request_stub2)
|
86
|
-
RequestRegistry.instance.register_request_stub(@request_stub3)
|
87
|
-
RequestRegistry.instance.response_for_request(@request_signature).
|
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")
|
88
90
|
end
|
89
91
|
|
90
92
|
end
|
@@ -98,24 +100,24 @@ describe RequestRegistry do
|
|
98
100
|
end
|
99
101
|
|
100
102
|
before(:each) do
|
101
|
-
@request_stub1 = RequestStub.new(:get, "www.example.com")
|
102
|
-
@request_stub2 = RequestStub.new(:get, "www.example.net")
|
103
|
-
@request_stub3 = RequestStub.new(:get, "www.example.org")
|
104
|
-
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.example.com"))
|
105
|
-
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.example.com"))
|
106
|
-
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.example.org"))
|
103
|
+
@request_stub1 = WebMock::RequestStub.new(:get, "www.example.com")
|
104
|
+
@request_stub2 = WebMock::RequestStub.new(:get, "www.example.net")
|
105
|
+
@request_stub3 = WebMock::RequestStub.new(:get, "www.example.org")
|
106
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
|
107
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
|
108
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.org"))
|
107
109
|
end
|
108
110
|
|
109
111
|
it "should report 0 if no request matching pattern was requested" do
|
110
|
-
RequestRegistry.instance.times_executed(RequestPattern.new(:get, "www.example.net")).should == 0
|
112
|
+
WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.net")).should == 0
|
111
113
|
end
|
112
114
|
|
113
115
|
it "should report number of times matching pattern was requested" do
|
114
|
-
RequestRegistry.instance.times_executed(RequestPattern.new(:get, "www.example.com")).should == 2
|
116
|
+
WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.com")).should == 2
|
115
117
|
end
|
116
118
|
|
117
119
|
it "should report number of times all matching pattern were requested" do
|
118
|
-
|
120
|
+
WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, /.*example.*/)).should == 3
|
119
121
|
end
|
120
122
|
|
121
123
|
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe RequestSignature do
|
3
|
+
describe WebMock::RequestSignature do
|
4
4
|
|
5
5
|
describe "initialization" do
|
6
6
|
|
7
7
|
it "should have assigned normalized uri" do
|
8
8
|
WebMock::Util::URI.should_receive(:normalize_uri).and_return("www.example.kom")
|
9
|
-
signature = RequestSignature.new(:get, "www.example.com")
|
9
|
+
signature = WebMock::RequestSignature.new(:get, "www.example.com")
|
10
10
|
signature.uri.should == "www.example.kom"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should have assigned uri without normalization if uri is URI" do
|
14
14
|
WebMock::Util::URI.should_not_receive(:normalize_uri)
|
15
15
|
uri = Addressable::URI.parse("www.example.com")
|
16
|
-
signature = RequestSignature.new(:get, uri)
|
16
|
+
signature = WebMock::RequestSignature.new(:get, uri)
|
17
17
|
signature.uri.should == uri
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should have assigned normalized headers" do
|
21
21
|
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
|
22
|
-
RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}).headers.should == {'B' => 'b'}
|
22
|
+
WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}).headers.should == {'B' => 'b'}
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should have assigned body" do
|
26
|
-
RequestSignature.new(:get, "www.example.com", :body => "abc").body.should == "abc"
|
26
|
+
WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc").body.should == "abc"
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should report string describing itself" do
|
32
|
-
RequestSignature.new(:get, "www.example.com",
|
32
|
+
WebMock::RequestSignature.new(:get, "www.example.com",
|
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
|
data/spec/request_stub_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe RequestStub do
|
3
|
+
describe WebMock::RequestStub do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@request_stub = RequestStub.new(:get, "www.example.com")
|
6
|
+
@request_stub = WebMock::RequestStub.new(:get, "www.example.com")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should have request pattern with method and uri" do
|
@@ -18,18 +18,18 @@ describe RequestStub do
|
|
18
18
|
|
19
19
|
it "should assign body to request pattern" do
|
20
20
|
@request_stub.with(:body => "abc")
|
21
|
-
@request_stub.request_pattern.to_s.should == RequestPattern.new(:get, "www.example.com", :body => "abc").to_s
|
21
|
+
@request_stub.request_pattern.to_s.should == WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").to_s
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should assign normalized headers to request pattern" do
|
25
25
|
@request_stub.with(:headers => {'A' => 'a'})
|
26
26
|
@request_stub.request_pattern.to_s.should ==
|
27
|
-
RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
|
27
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should assign given block to request profile" do
|
31
31
|
@request_stub.with { |req| req.body == "abc" }
|
32
|
-
@request_stub.request_pattern.matches?(RequestSignature.new(:get, "www.example.com", :body => "abc")).should be_true
|
32
|
+
@request_stub.request_pattern.matches?(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")).should be_true
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe ResponseFactory do
|
3
|
+
describe WebMock::ResponseFactory do
|
4
4
|
|
5
5
|
describe "response_for" do
|
6
6
|
|
7
7
|
it "should create response with options passed as arguments" do
|
8
8
|
options = {:body => "abc", :headers => {:a => :b}}
|
9
|
-
Response.should_receive(:new).with(options).and_return(@response = mock(Response))
|
10
|
-
ResponseFactory.response_for(options).should == @response
|
9
|
+
WebMock::Response.should_receive(:new).with(options).and_return(@response = mock(WebMock::Response))
|
10
|
+
WebMock::ResponseFactory.response_for(options).should == @response
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
14
|
it "should create dynamic response for argument responding to call" do
|
15
15
|
callable = mock(:call => {:body => "abc"})
|
16
|
-
DynamicResponse.should_receive(:new).with(callable).and_return(@response = mock(Response))
|
17
|
-
ResponseFactory.response_for(callable).should == @response
|
16
|
+
WebMock::DynamicResponse.should_receive(:new).with(callable).and_return(@response = mock(WebMock::Response))
|
17
|
+
WebMock::ResponseFactory.response_for(callable).should == @response
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
-
describe Response do
|
24
|
+
describe WebMock::Response do
|
25
25
|
before(:each) do
|
26
|
-
@response = Response.new(:headers => {'A' => 'a'})
|
26
|
+
@response = WebMock::Response.new(:headers => {'A' => 'a'})
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should report normalized headers" do
|
30
|
-
Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
|
31
|
-
@response = Response.new(:headers => {'A' => 'a'})
|
30
|
+
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
|
31
|
+
@response = WebMock::Response.new(:headers => {'A' => 'a'})
|
32
32
|
@response.headers.should == {'B' => 'b'}
|
33
33
|
end
|
34
34
|
|
@@ -39,12 +39,12 @@ describe Response do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should return assigned status" do
|
42
|
-
@response = Response.new(:status => 500)
|
42
|
+
@response = WebMock::Response.new(:status => 500)
|
43
43
|
@response.status.should == [500, ""]
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return assigned message" do
|
47
|
-
@response = Response.new(:status => [500, "Internal Server Error"])
|
47
|
+
@response = WebMock::Response.new(:status => [500, "Internal Server Error"])
|
48
48
|
@response.status.should == [500, "Internal Server Error"]
|
49
49
|
end
|
50
50
|
|
@@ -53,21 +53,21 @@ describe Response do
|
|
53
53
|
describe "raising error" do
|
54
54
|
|
55
55
|
it "should raise error if any assigned" do
|
56
|
-
@response = Response.new(:exception => ArgumentError)
|
56
|
+
@response = WebMock::Response.new(:exception => ArgumentError)
|
57
57
|
lambda {
|
58
58
|
@response.raise_error_if_any
|
59
59
|
}.should raise_error(ArgumentError, "Exception from WebMock")
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should raise error if any assigned as instance" do
|
63
|
-
@response = Response.new(:exception => ArgumentError.new("hello world"))
|
63
|
+
@response = WebMock::Response.new(:exception => ArgumentError.new("hello world"))
|
64
64
|
lambda {
|
65
65
|
@response.raise_error_if_any
|
66
66
|
}.should raise_error(ArgumentError, "hello world")
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should raise error if any assigned as string" do
|
70
|
-
@response = Response.new(:exception => "hello world")
|
70
|
+
@response = WebMock::Response.new(:exception => "hello world")
|
71
71
|
lambda {
|
72
72
|
@response.raise_error_if_any
|
73
73
|
}.should raise_error("hello world")
|
@@ -82,12 +82,12 @@ describe Response do
|
|
82
82
|
describe "timeout" do
|
83
83
|
|
84
84
|
it "should know if it should timeout" do
|
85
|
-
@response = Response.new(:should_timeout => true)
|
85
|
+
@response = WebMock::Response.new(:should_timeout => true)
|
86
86
|
@response.should_timeout.should be_true
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should not timeout by default" do
|
90
|
-
@response = Response.new
|
90
|
+
@response = WebMock::Response.new
|
91
91
|
@response.should_timeout.should be_false
|
92
92
|
end
|
93
93
|
|
@@ -100,22 +100,22 @@ describe Response do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should report body if assigned" do
|
103
|
-
@response = Response.new(:body => "abc")
|
103
|
+
@response = WebMock::Response.new(:body => "abc")
|
104
104
|
@response.body.should == "abc"
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should report string even if existing file path was provided" do
|
108
|
-
@response = Response.new(:body => __FILE__)
|
108
|
+
@response = WebMock::Response.new(:body => __FILE__)
|
109
109
|
@response.body.should == __FILE__
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should report content of a IO object if provided" do
|
113
|
-
@response = Response.new(:body => File.new(__FILE__))
|
113
|
+
@response = WebMock::Response.new(:body => File.new(__FILE__))
|
114
114
|
@response.body.should == File.new(__FILE__).read
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should report many times content of a IO object if provided" do
|
118
|
-
@response = Response.new(:body => File.new(__FILE__))
|
118
|
+
@response = WebMock::Response.new(:body => File.new(__FILE__))
|
119
119
|
@response.body.should == File.new(__FILE__).read
|
120
120
|
@response.body.should == File.new(__FILE__).read
|
121
121
|
end
|
@@ -127,7 +127,7 @@ describe Response do
|
|
127
127
|
describe "when input is IO" do
|
128
128
|
before(:each) do
|
129
129
|
@file = File.new(File.expand_path(File.dirname(__FILE__)) + "/example_curl_output.txt")
|
130
|
-
@response = Response.new(@file)
|
130
|
+
@response = WebMock::Response.new(@file)
|
131
131
|
end
|
132
132
|
|
133
133
|
|
@@ -158,7 +158,7 @@ describe Response do
|
|
158
158
|
describe "when input is String" do
|
159
159
|
before(:each) do
|
160
160
|
@input = File.new(File.expand_path(File.dirname(__FILE__)) + "/example_curl_output.txt").read
|
161
|
-
@response = Response.new(@input)
|
161
|
+
@response = WebMock::Response.new(@input)
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should read status" do
|
@@ -181,7 +181,7 @@ describe Response do
|
|
181
181
|
|
182
182
|
it "should work with transfer-encoding set to chunked" do
|
183
183
|
@input.gsub!("Content-Length: 438", "Transfer-Encoding: chunked")
|
184
|
-
@response = Response.new(@input)
|
184
|
+
@response = WebMock::Response.new(@input)
|
185
185
|
@response.body.size.should == 438
|
186
186
|
end
|
187
187
|
|
@@ -190,21 +190,21 @@ describe Response do
|
|
190
190
|
describe "with dynamically evaluated options" do
|
191
191
|
|
192
192
|
before(:each) do
|
193
|
-
@request_signature = RequestSignature.new(:post, "www.example.com", :body => "abc", :headers => {'A' => 'a'})
|
193
|
+
@request_signature = WebMock::RequestSignature.new(:post, "www.example.com", :body => "abc", :headers => {'A' => 'a'})
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should have evaluated body" do
|
197
|
-
@response = Response.new(:body => lambda {|request| request.body})
|
197
|
+
@response = WebMock::Response.new(:body => lambda {|request| request.body})
|
198
198
|
@response.evaluate!(@request_signature).body.should == "abc"
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should have evaluated headers" do
|
202
|
-
@response = Response.new(:headers => lambda {|request| request.headers})
|
202
|
+
@response = WebMock::Response.new(:headers => lambda {|request| request.headers})
|
203
203
|
@response.evaluate!(@request_signature).headers.should == {'A' => 'a'}
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should have evaluated status" do
|
207
|
-
@response = Response.new(:status => lambda {|request| 302})
|
207
|
+
@response = WebMock::Response.new(:status => lambda {|request| 302})
|
208
208
|
@response.evaluate!(@request_signature).status.should == [302, ""]
|
209
209
|
end
|
210
210
|
|
@@ -212,13 +212,13 @@ describe Response do
|
|
212
212
|
|
213
213
|
end
|
214
214
|
|
215
|
-
describe DynamicResponse do
|
215
|
+
describe WebMock::DynamicResponse do
|
216
216
|
|
217
217
|
describe "evaluating response options" do
|
218
218
|
|
219
219
|
it "should have evaluated options" do
|
220
|
-
request_signature = RequestSignature.new(:post, "www.example.com", :body => "abc", :headers => {'A' => 'a'})
|
221
|
-
response = DynamicResponse.new(lambda {|request|
|
220
|
+
request_signature = WebMock::RequestSignature.new(:post, "www.example.com", :body => "abc", :headers => {'A' => 'a'})
|
221
|
+
response = WebMock::DynamicResponse.new(lambda {|request|
|
222
222
|
{
|
223
223
|
:body => request.body,
|
224
224
|
:headers => request.headers,
|
@@ -232,10 +232,10 @@ describe Response do
|
|
232
232
|
end
|
233
233
|
|
234
234
|
it "should be equal to static response after evaluation" do
|
235
|
-
request_signature = RequestSignature.new(:post, "www.example.com", :body => "abc")
|
236
|
-
response = DynamicResponse.new(lambda {|request| {:body => request.body}})
|
235
|
+
request_signature = WebMock::RequestSignature.new(:post, "www.example.com", :body => "abc")
|
236
|
+
response = WebMock::DynamicResponse.new(lambda {|request| {:body => request.body}})
|
237
237
|
response.evaluate!(request_signature)
|
238
|
-
response.should == Response.new(:body => "abc")
|
238
|
+
response.should == WebMock::Response.new(:body => "abc")
|
239
239
|
end
|
240
240
|
|
241
241
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'httpclient'
|
3
3
|
unless RUBY_PLATFORM =~ /java/
|
4
|
+
require 'curb'
|
4
5
|
require 'patron'
|
5
6
|
require 'em-http'
|
6
7
|
end
|
@@ -14,10 +15,8 @@ require 'webmock/rspec'
|
|
14
15
|
|
15
16
|
require 'json'
|
16
17
|
|
17
|
-
include WebMock
|
18
|
-
|
19
18
|
Spec::Runner.configure do |config|
|
20
|
-
config.include WebMock
|
19
|
+
config.include WebMock::API
|
21
20
|
end
|
22
21
|
|
23
22
|
def fail()
|