webmock 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/README.md +169 -76
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/webmock.rb +12 -9
- data/lib/webmock/adapters/rspec.rb +20 -22
- data/lib/webmock/adapters/rspec/matchers.rb +4 -4
- data/lib/webmock/adapters/rspec/webmock_matcher.rb +2 -2
- data/lib/webmock/adapters/test_unit.rb +20 -21
- data/lib/webmock/http_lib_adapters/net_http.rb +51 -15
- data/lib/webmock/request_profile.rb +5 -44
- data/lib/webmock/request_registry.rb +10 -11
- data/lib/webmock/request_signature.rb +44 -0
- data/lib/webmock/request_stub.rb +3 -3
- data/lib/webmock/response.rb +1 -1
- data/lib/webmock/rspec.rb +1 -0
- data/lib/webmock/test_unit.rb +1 -0
- data/lib/webmock/util/hash_counter.rb +16 -8
- data/lib/webmock/util/headers.rb +23 -0
- data/lib/webmock/util/uri.rb +81 -0
- data/lib/webmock/webmock.rb +16 -19
- data/spec/net_http_spec.rb +10 -9
- data/spec/other_net_http_libs_spec.rb +3 -1
- data/spec/request_profile_spec.rb +6 -116
- data/spec/request_registry_spec.rb +12 -17
- data/spec/request_signature_spec.rb +155 -0
- data/spec/request_stub_spec.rb +2 -2
- data/spec/response_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- data/spec/util/hash_counter_spec.rb +4 -4
- data/spec/util/headers_spec.rb +11 -0
- data/spec/util/uri_spec.rb +213 -0
- data/spec/vendor/addressable/lib/addressable/uri.rb +8 -0
- data/spec/vendor/addressable/lib/uri.rb +0 -0
- data/spec/webmock_spec.rb +58 -10
- data/test/test_helper.rb +5 -1
- data/test/test_webmock.rb +11 -6
- data/webmock.gemspec +21 -6
- metadata +28 -6
- data/lib/webmock/url.rb +0 -46
- data/lib/webmock/utility.rb +0 -65
- data/spec/utility_spec.rb +0 -70
data/lib/webmock/webmock.rb
CHANGED
@@ -1,50 +1,47 @@
|
|
1
|
-
WebMock::Utility.record_loaded_net_http_replacement_libs
|
2
|
-
WebMock::Utility.puts_warning_for_net_http_around_advice_libs_if_needed
|
3
|
-
|
4
|
-
|
5
1
|
module WebMock
|
2
|
+
extend self
|
6
3
|
|
7
|
-
def stub_request(method,
|
8
|
-
RequestRegistry.instance.register_request_stub(RequestStub.new(method,
|
4
|
+
def stub_request(method, uri)
|
5
|
+
RequestRegistry.instance.register_request_stub(RequestStub.new(method, uri))
|
9
6
|
end
|
10
7
|
|
11
8
|
alias_method :stub_http_request, :stub_request
|
12
9
|
|
13
|
-
def request(method,
|
14
|
-
RequestProfile.new(method,
|
10
|
+
def request(method, uri)
|
11
|
+
RequestProfile.new(method, uri)
|
15
12
|
end
|
16
13
|
|
17
|
-
def assert_requested(method,
|
14
|
+
def assert_requested(method, uri, options = {})
|
18
15
|
expected_times_executed = options.delete(:times) || 1
|
19
|
-
request = RequestProfile.new(method,
|
16
|
+
request = RequestProfile.new(method, uri, options[:body], options[:headers])
|
20
17
|
verifier = RequestExecutionVerifier.new(request, expected_times_executed)
|
21
18
|
assertion_failure(verifier.failure_message) unless verifier.matches?
|
22
19
|
end
|
23
20
|
|
24
|
-
def assert_not_requested(method,
|
25
|
-
request = RequestProfile.new(method,
|
21
|
+
def assert_not_requested(method, uri, options = {})
|
22
|
+
request = RequestProfile.new(method, uri, options[:body], options[:headers])
|
26
23
|
verifier = RequestExecutionVerifier.new(request, options.delete(:times))
|
27
24
|
assertion_failure(verifier.negative_failure_message) unless verifier.does_not_match?
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
27
|
+
def allow_net_connect!
|
31
28
|
Config.instance.allow_net_connect = true
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
31
|
+
def disable_net_connect!
|
35
32
|
Config.instance.allow_net_connect = false
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
35
|
+
def net_connect_allowed?
|
39
36
|
Config.instance.allow_net_connect
|
40
37
|
end
|
41
38
|
|
42
|
-
def
|
43
|
-
RequestRegistry.instance.registered_request?(
|
39
|
+
def registered_request?(request_signature)
|
40
|
+
RequestRegistry.instance.registered_request?(request_signature)
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
RequestRegistry.instance.response_for_request(
|
43
|
+
def response_for_request(request_signature, &block)
|
44
|
+
RequestRegistry.instance.response_for_request(request_signature, &block)
|
48
45
|
end
|
49
46
|
|
50
47
|
def reset_webmock
|
data/spec/net_http_spec.rb
CHANGED
@@ -2,16 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require 'webmock_spec'
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def http_request(method, uri, options = {})
|
6
|
+
begin
|
7
|
+
uri = URI.parse(uri)
|
8
|
+
rescue
|
9
|
+
uri = Addressable::URI.heuristic_parse(uri)
|
10
|
+
end
|
9
11
|
response = nil
|
10
12
|
clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
|
11
|
-
req = clazz.new(
|
12
|
-
req.basic_auth
|
13
|
-
http = Net::HTTP.new(
|
14
|
-
http.use_ssl = true if
|
13
|
+
req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers])
|
14
|
+
req.basic_auth uri.user, uri.password if uri.user
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
http.use_ssl = true if uri.scheme == "https"
|
15
17
|
response = http.start {|http|
|
16
18
|
http.request(req, options[:body])
|
17
19
|
}
|
@@ -21,7 +23,6 @@ def http_request(method, url, options = {})
|
|
21
23
|
:status => response.code })
|
22
24
|
end
|
23
25
|
|
24
|
-
|
25
26
|
describe "Webmock with Net:HTTP" do
|
26
27
|
|
27
28
|
it_should_behave_like "WebMock"
|
@@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "loading other Net::HTTP based libraries" do
|
4
4
|
|
5
5
|
def capture_output_from_requiring(libs, additional_code = "")
|
6
|
-
requires = libs.map { |lib| "require '#{lib}'" }
|
6
|
+
requires = libs.map { |lib| "require '#{lib}'" }
|
7
|
+
requires << " require 'addressable/uri'"
|
8
|
+
requires = requires.join("; ")
|
7
9
|
webmock_dir = "#{File.dirname(__FILE__)}/../lib"
|
8
10
|
vendor_dirs = Dir["#{File.dirname(__FILE__)}/vendor/*/lib"]
|
9
11
|
load_path_opts = vendor_dirs.unshift(webmock_dir).map { |dir| "-I#{dir}" }.join(" ")
|
@@ -1,26 +1,24 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
include WebMock
|
4
|
-
|
5
3
|
describe RequestProfile do
|
6
4
|
|
7
5
|
describe "initialization" do
|
8
6
|
|
9
7
|
it "should have assigned normalized uri" do
|
10
|
-
|
8
|
+
WebMock::Util::URI.should_receive(:normalize_uri).and_return("www.google.kom")
|
11
9
|
profile = RequestProfile.new(:get, "www.google.com")
|
12
10
|
profile.uri.should == "www.google.kom"
|
13
11
|
end
|
14
12
|
|
15
13
|
it "should have assigned uri without normalization if uri is URI" do
|
16
|
-
|
17
|
-
uri = URI.parse("www.google.com")
|
14
|
+
WebMock::Util::URI.should_not_receive(:normalize_uri)
|
15
|
+
uri = Addressable::URI.parse("www.google.com")
|
18
16
|
profile = RequestProfile.new(:get, uri)
|
19
17
|
profile.uri.should == uri
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should have assigned normalized headers" do
|
23
|
-
|
21
|
+
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
|
24
22
|
RequestProfile.new(:get, "www.google.com", nil, 'A' => 'a').headers.should == {'B' => 'b'}
|
25
23
|
end
|
26
24
|
|
@@ -30,7 +28,7 @@ describe RequestProfile do
|
|
30
28
|
|
31
29
|
end
|
32
30
|
|
33
|
-
it "should report string" do
|
31
|
+
it "should report string describing itself" do
|
34
32
|
RequestProfile.new(:get, "www.google.com", "abc", {'A' => 'a', 'B' => 'b'}).to_s.should ==
|
35
33
|
"GET http://www.google.com/ with body 'abc' with headers {'A'=>'a', 'B'=>'b'}"
|
36
34
|
end
|
@@ -47,120 +45,12 @@ describe RequestProfile do
|
|
47
45
|
end
|
48
46
|
|
49
47
|
it "should assign normalized headers to request profile" do
|
50
|
-
|
48
|
+
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
|
51
49
|
@request_profile.with(:headers => {'A' => 'a'})
|
52
50
|
@request_profile.headers.should == {'B' => 'b'}
|
53
51
|
end
|
54
52
|
|
55
53
|
end
|
56
54
|
|
57
|
-
describe "when matching" do
|
58
|
-
|
59
|
-
it "should match if url matches and method matches" do
|
60
|
-
RequestProfile.new(:get, "www.google.com").
|
61
|
-
should match(RequestProfile.new(:get, "www.google.com"))
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should match if url matches and method is any" do
|
65
|
-
RequestProfile.new(:get, "www.google.com").
|
66
|
-
should match(RequestProfile.new(:any, "www.google.com"))
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should not match if other request profile has different method" do
|
70
|
-
RequestProfile.new(:get, "www.google.com").
|
71
|
-
should_not match(RequestProfile.new(:post, "www.google.com"))
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should match if uri matches other uri" do
|
75
|
-
RequestProfile.new(:get, "www.google.com").
|
76
|
-
should match(RequestProfile.new(:get, "www.google.com"))
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should match if uri matches other regex uri" do
|
80
|
-
RequestProfile.new(:get, "www.google.com").
|
81
|
-
should match(RequestProfile.new(:get, /.*google.*/))
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should match for uris with same parameters" do
|
85
|
-
RequestProfile.new(:get, "www.google.com?a=1&b=2").
|
86
|
-
should match(RequestProfile.new(:get, "www.google.com?a=1&b=2"))
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should not match for uris with different parameters" do
|
90
|
-
RequestProfile.new(:get, "www.google.com?a=2&b=1").
|
91
|
-
should_not match(RequestProfile.new(:get, "www.google.com?a=1&b=2"))
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should match for parameters in different order" do
|
95
|
-
RequestProfile.new(:get, "www.google.com?a=1&b=2").
|
96
|
-
should match(RequestProfile.new(:get, "www.google.com?b=2&a=1"))
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should match for same bodies" do
|
100
|
-
RequestProfile.new(:get, "www.google.com", "abc").
|
101
|
-
should match(RequestProfile.new(:get, "www.google.com", "abc"))
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not match for different bodies" do
|
105
|
-
RequestProfile.new(:get, "www.google.com", "abc").
|
106
|
-
should_not match(RequestProfile.new(:get, "www.google.com", "def"))
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should match is other has nil body" do
|
110
|
-
RequestProfile.new(:get, "www.google.com", "abc").
|
111
|
-
should match(RequestProfile.new(:get, "www.google.com", nil))
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should not match if other has empty body" do
|
115
|
-
RequestProfile.new(:get, "www.google.com", "abc").
|
116
|
-
should_not match(RequestProfile.new(:get, "www.google.com", ""))
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should match for same headers" do
|
120
|
-
RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
121
|
-
should match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg'))
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should not match for different values of the same header" do
|
125
|
-
RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
126
|
-
should_not match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/png'))
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should match if request has more headers than other" do
|
130
|
-
RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg', 'Content-Length' => '8888').
|
131
|
-
should match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg'))
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should not match if request has less headers that the other and all match" do
|
135
|
-
RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
136
|
-
should_not match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'))
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should match even is header keys or values are in different format" do
|
140
|
-
RequestProfile.new(:get, "www.google.com", nil, :ContentLength => 8888, 'content_type' => 'image/png').
|
141
|
-
should match(RequestProfile.new(:get, "www.google.com", nil, 'ContentLength' => '8888', 'Content-type' => 'image/png'))
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should match is other has nil headers" do
|
145
|
-
RequestProfile.new(:get, "www.google.com", nil, 'A' => 'a').
|
146
|
-
should match(RequestProfile.new(:get, "www.google.com", nil, nil))
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should not match if other has empty headers" do
|
150
|
-
RequestProfile.new(:get, "www.google.com", nil, 'A' => 'a').
|
151
|
-
should_not match(RequestProfile.new(:get, "www.google.com", nil, {}))
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should not match if profile has no headers but other has headers" do
|
155
|
-
RequestProfile.new(:get, "www.google.com", nil, nil).
|
156
|
-
should_not match(RequestProfile.new(:get, "www.google.com", nil, {'A'=>'a'}))
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should not match if profile has empty headers but other has headers" do
|
160
|
-
RequestProfile.new(:get, "www.google.com", nil, {}).
|
161
|
-
should_not match(RequestProfile.new(:get, "www.google.com", nil, {'A'=>'a'}))
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
55
|
|
166
56
|
end
|
@@ -5,19 +5,20 @@ describe RequestRegistry do
|
|
5
5
|
before(:each) do
|
6
6
|
RequestRegistry.instance.reset_webmock
|
7
7
|
@request_profile = RequestProfile.new(:get, "www.google.com")
|
8
|
+
@request_signature = RequestSignature.new(:get, "www.google.com")
|
8
9
|
@request_stub = RequestStub.new(:get, "www.google.com")
|
9
10
|
end
|
10
11
|
|
11
12
|
describe "reset_webmock" do
|
12
13
|
before(:each) do
|
13
14
|
RequestRegistry.instance.register_request_stub(@request_stub)
|
14
|
-
RequestRegistry.instance.
|
15
|
+
RequestRegistry.instance.requested_signatures.put(@request_signature)
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should clean request stubs" do
|
18
|
-
RequestRegistry.instance.registered_request?(@
|
19
|
+
RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
19
20
|
RequestRegistry.instance.reset_webmock
|
20
|
-
RequestRegistry.instance.registered_request?(@
|
21
|
+
RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should clean list of executed requests" do
|
@@ -35,12 +36,12 @@ describe RequestRegistry do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should report if request stub is not registered" do
|
38
|
-
RequestRegistry.instance.registered_request?(@
|
39
|
+
RequestRegistry.instance.registered_request?(@request_signature).should == nil
|
39
40
|
end
|
40
41
|
|
41
42
|
it "should register and report registered stib" do
|
42
43
|
RequestRegistry.instance.register_request_stub(@request_stub)
|
43
|
-
RequestRegistry.instance.registered_request?(@
|
44
|
+
RequestRegistry.instance.registered_request?(@request_signature).should == @request_stub
|
44
45
|
end
|
45
46
|
|
46
47
|
|
@@ -51,17 +52,11 @@ describe RequestRegistry do
|
|
51
52
|
it "should registered response for request profile" do
|
52
53
|
@request_stub.response = @response = Response.new
|
53
54
|
RequestRegistry.instance.register_request_stub(@request_stub)
|
54
|
-
RequestRegistry.instance.response_for_request(@
|
55
|
+
RequestRegistry.instance.response_for_request(@request_signature).should == @response
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should report nothing if no response for request is registered" do
|
58
|
-
RequestRegistry.instance.response_for_request(@
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should increase number of times request was executed" do
|
62
|
-
RequestRegistry.instance.times_executed(@request_profile).should == 0
|
63
|
-
RequestRegistry.instance.response_for_request(@request_profile)
|
64
|
-
RequestRegistry.instance.times_executed(@request_profile).should == 1
|
59
|
+
RequestRegistry.instance.response_for_request(@request_signature).should == nil
|
65
60
|
end
|
66
61
|
|
67
62
|
it "should always return last registered matching response" do
|
@@ -74,7 +69,7 @@ describe RequestRegistry do
|
|
74
69
|
RequestRegistry.instance.register_request_stub(@request_stub1)
|
75
70
|
RequestRegistry.instance.register_request_stub(@request_stub2)
|
76
71
|
RequestRegistry.instance.register_request_stub(@request_stub3)
|
77
|
-
RequestRegistry.instance.response_for_request(@
|
72
|
+
RequestRegistry.instance.response_for_request(@request_signature).should == @response2
|
78
73
|
end
|
79
74
|
|
80
75
|
end
|
@@ -91,9 +86,9 @@ describe RequestRegistry do
|
|
91
86
|
@request_stub1 = RequestStub.new(:get, "www.google.com")
|
92
87
|
@request_stub2 = RequestStub.new(:get, "www.google.net")
|
93
88
|
@request_stub3 = RequestStub.new(:get, "www.google.org")
|
94
|
-
RequestRegistry.instance.
|
95
|
-
RequestRegistry.instance.
|
96
|
-
RequestRegistry.instance.
|
89
|
+
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.google.com"))
|
90
|
+
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.google.com"))
|
91
|
+
RequestRegistry.instance.requested_signatures.put(RequestSignature.new(:get, "www.google.org"))
|
97
92
|
end
|
98
93
|
|
99
94
|
it "should report 0 if no request matching profile was requested" do
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe RequestSignature do
|
4
|
+
|
5
|
+
describe "when matching" do
|
6
|
+
|
7
|
+
it "should match if uri matches and method matches" do
|
8
|
+
RequestSignature.new(:get, "www.google.com").
|
9
|
+
should match(RequestProfile.new(:get, "www.google.com"))
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should match if uri matches and method is any" do
|
13
|
+
RequestSignature.new(:get, "www.google.com").
|
14
|
+
should match(RequestProfile.new(:any, "www.google.com"))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not match if other request profile has different method" do
|
18
|
+
RequestSignature.new(:get, "www.google.com").
|
19
|
+
should_not match(RequestProfile.new(:post, "www.google.com"))
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should match if uri matches other uri" do
|
23
|
+
RequestSignature.new(:get, "www.google.com").
|
24
|
+
should match(RequestProfile.new(:get, "www.google.com"))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should match if uri matches other escaped using uri" do
|
28
|
+
RequestSignature.new(:get, "www.google.com/big image.jpg").
|
29
|
+
should match(RequestProfile.new(:get, "www.google.com/big%20image.jpg"))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should match if unescaped uri matches other uri" do
|
33
|
+
RequestSignature.new(:get, "www.google.com/big%20image.jpg").
|
34
|
+
should match(RequestProfile.new(:get, "www.google.com/big image.jpg"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should match if unescaped uri matches other regexp uri" do
|
38
|
+
RequestSignature.new(:get, "www.google.com/big%20image.jpg").
|
39
|
+
should match(RequestProfile.new(:get, /.*big image.jpg.*/))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should match if uri matches other regex uri" do
|
43
|
+
RequestSignature.new(:get, "www.google.com").
|
44
|
+
should match(RequestProfile.new(:get, /.*google.*/))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should match for uris with same parameters" do
|
48
|
+
RequestSignature.new(:get, "www.google.com?a=1&b=2").
|
49
|
+
should match(RequestProfile.new(:get, "www.google.com?a=1&b=2"))
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not match for uris with different parameters" do
|
53
|
+
RequestSignature.new(:get, "www.google.com?a=2&b=1").
|
54
|
+
should_not match(RequestProfile.new(:get, "www.google.com?a=1&b=2"))
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should match for parameters in different order" do
|
58
|
+
RequestSignature.new(:get, "www.google.com?a=1&b=2").
|
59
|
+
should match(RequestProfile.new(:get, "www.google.com?b=2&a=1"))
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "when parameters are escaped" do
|
63
|
+
|
64
|
+
it "should match if uri with non escaped parameters is the same as other uri with escaped parameters" do
|
65
|
+
RequestSignature.new(:get, "www.google.com/?a=a b").
|
66
|
+
should match(RequestProfile.new(:get, "www.google.com/?a=a%20b"))
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should match if uri with escaped parameters is the same as other uri with non escaped parameters" do
|
70
|
+
RequestSignature.new(:get, "www.google.com/?a=a%20b").
|
71
|
+
should match(RequestProfile.new(:get, "www.google.com/?a=a b"))
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should match if other regexp is for non escaped parameters but uri has escaped parameters" do
|
75
|
+
RequestSignature.new(:get, "www.google.com/?a=a%20b").
|
76
|
+
should match(RequestProfile.new(:get, /.*a=a b.*/))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should match if other regexp is for escaped parameters but uri has non escaped parameters" do
|
80
|
+
RequestSignature.new(:get, "www.google.com/?a=a b").
|
81
|
+
should match(RequestProfile.new(:get, /.*a=a%20b.*/))
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
it "should match for same bodies" do
|
89
|
+
RequestSignature.new(:get, "www.google.com", "abc").
|
90
|
+
should match(RequestProfile.new(:get, "www.google.com", "abc"))
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not match for different bodies" do
|
94
|
+
RequestSignature.new(:get, "www.google.com", "abc").
|
95
|
+
should_not match(RequestProfile.new(:get, "www.google.com", "def"))
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should match is other has nil body" do
|
99
|
+
RequestSignature.new(:get, "www.google.com", "abc").
|
100
|
+
should match(RequestProfile.new(:get, "www.google.com", nil))
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not match if other has empty body" do
|
104
|
+
RequestSignature.new(:get, "www.google.com", "abc").
|
105
|
+
should_not match(RequestProfile.new(:get, "www.google.com", ""))
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should match for same headers" do
|
109
|
+
RequestSignature.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
110
|
+
should match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg'))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not match for different values of the same header" do
|
114
|
+
RequestSignature.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
115
|
+
should_not match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/png'))
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should match if request has more headers than other" do
|
119
|
+
RequestSignature.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg', 'Content-Length' => '8888').
|
120
|
+
should match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg'))
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not match if request has less headers that the other and all match" do
|
124
|
+
RequestSignature.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg').
|
125
|
+
should_not match(RequestProfile.new(:get, "www.google.com", nil, 'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'))
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should match even is header keys or values are in different format" do
|
129
|
+
RequestSignature.new(:get, "www.google.com", nil, :ContentLength => 8888, 'content_type' => 'image/png').
|
130
|
+
should match(RequestProfile.new(:get, "www.google.com", nil, 'ContentLength' => '8888', 'Content-type' => 'image/png'))
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should match is other has nil headers" do
|
134
|
+
RequestSignature.new(:get, "www.google.com", nil, 'A' => 'a').
|
135
|
+
should match(RequestProfile.new(:get, "www.google.com", nil, nil))
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not match if other has empty headers" do
|
139
|
+
RequestSignature.new(:get, "www.google.com", nil, 'A' => 'a').
|
140
|
+
should_not match(RequestProfile.new(:get, "www.google.com", nil, {}))
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not match if profile has no headers but other has headers" do
|
144
|
+
RequestSignature.new(:get, "www.google.com", nil, nil).
|
145
|
+
should_not match(RequestProfile.new(:get, "www.google.com", nil, {'A'=>'a'}))
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not match if profile has empty headers but other has headers" do
|
149
|
+
RequestSignature.new(:get, "www.google.com", nil, {}).
|
150
|
+
should_not match(RequestProfile.new(:get, "www.google.com", nil, {'A'=>'a'}))
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|