webmock 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,62 +3,75 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
4
  URIS_WITHOUT_PATH_OR_PARAMS =
5
5
  [
6
- "www.google.com",
7
- "www.google.com/",
8
- "www.google.com:80",
9
- "www.google.com:80/",
10
- "http://www.google.com",
11
- "http://www.google.com/",
12
- "http://www.google.com:80",
13
- "http://www.google.com:80/"
6
+ "www.example.com",
7
+ "www.example.com/",
8
+ "www.example.com:80",
9
+ "www.example.com:80/",
10
+ "http://www.example.com",
11
+ "http://www.example.com/",
12
+ "http://www.example.com:80",
13
+ "http://www.example.com:80/"
14
+ ].sort
15
+
16
+ URIS_WITHOUT_PATH_BUT_WITH_PARAMS =
17
+ [
18
+ "www.example.com?a=b",
19
+ "www.example.com/?a=b",
20
+ "www.example.com:80?a=b",
21
+ "www.example.com:80/?a=b",
22
+ "http://www.example.com?a=b",
23
+ "http://www.example.com/?a=b",
24
+ "http://www.example.com:80?a=b",
25
+ "http://www.example.com:80/?a=b"
14
26
  ].sort
15
27
 
16
28
  URIS_WITH_AUTH =
17
29
  [
18
- "a b:pass@www.google.com",
19
- "a b:pass@www.google.com/",
20
- "a b:pass@www.google.com:80",
21
- "a b:pass@www.google.com:80/",
22
- "http://a b:pass@www.google.com",
23
- "http://a b:pass@www.google.com/",
24
- "http://a b:pass@www.google.com:80",
25
- "http://a b:pass@www.google.com:80/",
26
- "a%20b:pass@www.google.com",
27
- "a%20b:pass@www.google.com/",
28
- "a%20b:pass@www.google.com:80",
29
- "a%20b:pass@www.google.com:80/",
30
- "http://a%20b:pass@www.google.com",
31
- "http://a%20b:pass@www.google.com/",
32
- "http://a%20b:pass@www.google.com:80",
33
- "http://a%20b:pass@www.google.com:80/"
30
+ "a b:pass@www.example.com",
31
+ "a b:pass@www.example.com/",
32
+ "a b:pass@www.example.com:80",
33
+ "a b:pass@www.example.com:80/",
34
+ "http://a b:pass@www.example.com",
35
+ "http://a b:pass@www.example.com/",
36
+ "http://a b:pass@www.example.com:80",
37
+ "http://a b:pass@www.example.com:80/",
38
+ "a%20b:pass@www.example.com",
39
+ "a%20b:pass@www.example.com/",
40
+ "a%20b:pass@www.example.com:80",
41
+ "a%20b:pass@www.example.com:80/",
42
+ "http://a%20b:pass@www.example.com",
43
+ "http://a%20b:pass@www.example.com/",
44
+ "http://a%20b:pass@www.example.com:80",
45
+ "http://a%20b:pass@www.example.com:80/"
34
46
  ].sort
35
47
 
36
48
  URIS_WITH_PATH_AND_PARAMS =
37
49
  [
38
- "www.google.com/big image.jpg/?a=big image&b=c",
39
- "www.google.com/big%20image.jpg/?a=big%20image&b=c",
40
- "www.google.com:80/big image.jpg/?a=big image&b=c",
41
- "www.google.com:80/big%20image.jpg/?a=big%20image&b=c",
42
- "http://www.google.com/big image.jpg/?a=big image&b=c",
43
- "http://www.google.com/big%20image.jpg/?a=big%20image&b=c",
44
- "http://www.google.com:80/big image.jpg/?a=big image&b=c",
45
- "http://www.google.com:80/big%20image.jpg/?a=big%20image&b=c",
50
+ "www.example.com/my path/?a=my param&b=c",
51
+ "www.example.com/my%20path/?a=my%20param&b=c",
52
+ "www.example.com:80/my path/?a=my param&b=c",
53
+ "www.example.com:80/my%20path/?a=my%20param&b=c",
54
+ "http://www.example.com/my path/?a=my param&b=c",
55
+ "http://www.example.com/my%20path/?a=my%20param&b=c",
56
+ "http://www.example.com:80/my path/?a=my param&b=c",
57
+ "http://www.example.com:80/my%20path/?a=my%20param&b=c",
46
58
  ].sort
47
59
 
48
60
  URIS_WITH_DIFFERENT_PORT =
49
61
  [
50
- "www.google.com:88",
51
- "www.google.com:88/",
52
- "http://www.google.com:88",
53
- "http://www.google.com:88/"
62
+ "www.example.com:88",
63
+ "www.example.com:88/",
64
+ "http://www.example.com:88",
65
+ "http://www.example.com:88/"
54
66
  ].sort
55
67
 
68
+
56
69
  URIS_FOR_HTTPS =
57
70
  [
58
- "https://www.google.com",
59
- "https://www.google.com/",
60
- "https://www.google.com:443",
61
- "https://www.google.com:443/"
71
+ "https://www.example.com",
72
+ "https://www.example.com/",
73
+ "https://www.example.com:443",
74
+ "https://www.example.com:443/"
62
75
  ].sort
63
76
 
64
77
 
@@ -72,6 +85,12 @@ describe WebMock::Util::URI do
72
85
  end
73
86
  end
74
87
 
88
+ it "should find all variations of the same uri for all variations of uri with params but without path" do
89
+ URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri|
90
+ WebMock::Util::URI.variations_of_uri_as_strings(uri).sort.should == URIS_WITHOUT_PATH_BUT_WITH_PARAMS
91
+ end
92
+ end
93
+
75
94
  it "should find all variations of the same uri for all variations of uri without params or path" do
76
95
  URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
77
96
  WebMock::Util::URI.variations_of_uri_as_strings(uri).sort.should == URIS_WITHOUT_PATH_OR_PARAMS
@@ -108,6 +127,14 @@ describe WebMock::Util::URI do
108
127
  end
109
128
  end
110
129
 
130
+ it "should successfully compare all variations of the same uri with path but with params" do
131
+ URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_a|
132
+ URIS_WITHOUT_PATH_BUT_WITH_PARAMS.each do |uri_b|
133
+ WebMock::Util::URI.normalize_uri(uri_a).should === WebMock::Util::URI.normalize_uri(uri_b)
134
+ end
135
+ end
136
+ end
137
+
111
138
  it "should successfully compare all variations of the same uri without path or params" do
112
139
  URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_a|
113
140
  URIS_WITHOUT_PATH_OR_PARAMS.each do |uri_b|
data/spec/webmock_spec.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- SAMPLE_HEADERS = { "Content-Length" => "8888" }
4
- ESCAPED_PARAMS = "x=ab%2Bc&z=%27Stop%21%27%20said%20Fred"
5
- NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
3
+ unless defined? SAMPLE_HEADERS
4
+ SAMPLE_HEADERS = { "Content-Length" => "8888" }
5
+ ESCAPED_PARAMS = "x=ab%2Bc&z=%27Stop%21%27%20said%20Fred"
6
+ NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
7
+ end
6
8
 
7
9
  describe "WebMock", :shared => true do
8
10
  before(:each) do
@@ -18,14 +20,20 @@ describe "WebMock", :shared => true do
18
20
  end
19
21
 
20
22
  it "should make a real web request if request is not stubbed" do
21
- setup_expectations_for_real_google_request
22
- http_request(:get, "http://www.google.com/").
23
+ setup_expectations_for_real_example_com_request
24
+ http_request(:get, "http://www.example.com/").
25
+ body.should =~ /.*Google fake response.*/
26
+ end
27
+
28
+ it "should make a real https request if request is not stubbed" do
29
+ setup_expectations_for_real_example_com_request(:port => 443)
30
+ http_request(:get, "https://www.example.com/").
23
31
  body.should =~ /.*Google fake response.*/
24
32
  end
25
33
 
26
34
  it "should return stubbed response if request was stubbed" do
27
- stub_http_request(:get, "www.google.com").to_return(:body => "abc")
28
- http_request(:get, "http://www.google.com/").body.should == "abc"
35
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc")
36
+ http_request(:get, "http://www.example.com/").body.should == "abc"
29
37
  end
30
38
  end
31
39
 
@@ -35,15 +43,14 @@ describe "WebMock", :shared => true do
35
43
  end
36
44
 
37
45
  it "should return stubbed response if request was stubbed" do
38
- stub_http_request(:get, "www.google.com").to_return(:body => "abc")
39
- http_request(:get, "http://www.google.com/").body.should == "abc"
46
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc")
47
+ http_request(:get, "http://www.example.com/").body.should == "abc"
40
48
  end
41
49
 
42
50
  it "should raise exception if request was not stubbed" do
43
51
  lambda {
44
- http_request(:get, "http://www.google.com/")
45
- }.should raise_error(WebMock::NetConnectNotAllowedError,
46
- "Real HTTP connections are disabled. Unregistered request: GET http://www.google.com/")
52
+ http_request(:get, "http://www.example.com/")
53
+ }.should fail_with("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/")
47
54
  end
48
55
  end
49
56
 
@@ -54,18 +61,18 @@ describe "WebMock", :shared => true do
54
61
  describe "on uri" do
55
62
 
56
63
  it "should match the request by uri with non escaped params if request have escaped parameters" do
57
- stub_http_request(:get, "www.google.com/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
58
- http_request(:get, "http://www.google.com/?#{ESCAPED_PARAMS}").body.should == "abc"
64
+ stub_http_request(:get, "www.example.com/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
65
+ http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").body.should == "abc"
59
66
  end
60
67
 
61
68
  it "should match the request by uri with escaped parameters even if request has non escaped params" do
62
- stub_http_request(:get, "www.google.com/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
63
- http_request(:get, "http://www.google.com/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
69
+ stub_http_request(:get, "www.example.com/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
70
+ http_request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
64
71
  end
65
72
 
66
73
  it "should match the request by regexp matching non escaped params uri if request params are escaped" do
67
74
  stub_http_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
68
- http_request(:get, "http://www.google.com/?#{ESCAPED_PARAMS}").body.should == "abc"
75
+ http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").body.should == "abc"
69
76
  end
70
77
 
71
78
  end
@@ -73,17 +80,16 @@ describe "WebMock", :shared => true do
73
80
  describe "on method" do
74
81
 
75
82
  it "should match the request by method if registered" do
76
- stub_http_request(:get, "www.google.com")
77
- http_request(:get, "http://www.google.com/").status.should == "200"
83
+ stub_http_request(:get, "www.example.com")
84
+ http_request(:get, "http://www.example.com/").status.should == "200"
78
85
  end
79
86
 
80
87
  it "should not match requests if method is different" do
81
- stub_http_request(:get, "www.google.com")
82
- http_request(:get, "http://www.google.com/").status.should == "200"
88
+ stub_http_request(:get, "www.example.com")
89
+ http_request(:get, "http://www.example.com/").status.should == "200"
83
90
  lambda {
84
- http_request(:post, "http://www.google.com/")
85
- }.should raise_error(WebMock::NetConnectNotAllowedError,
86
- "Real HTTP connections are disabled. Unregistered request: POST http://www.google.com/"
91
+ http_request(:post, "http://www.example.com/")
92
+ }.should fail_with("Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/"
87
93
  )
88
94
  end
89
95
 
@@ -92,26 +98,24 @@ describe "WebMock", :shared => true do
92
98
  describe "on body" do
93
99
 
94
100
  it "should match requests if body is the same" do
95
- stub_http_request(:get, "www.google.com").with(:body => "abc")
101
+ stub_http_request(:get, "www.example.com").with(:body => "abc")
96
102
  http_request(
97
- :get, "http://www.google.com/",
103
+ :get, "http://www.example.com/",
98
104
  :body => "abc").status.should == "200"
99
105
  end
100
106
 
101
107
  it "should match requests if body is not set in the stub" do
102
- stub_http_request(:get, "www.google.com")
108
+ stub_http_request(:get, "www.example.com")
103
109
  http_request(
104
- :get, "http://www.google.com/",
110
+ :get, "http://www.example.com/",
105
111
  :body => "abc").status.should == "200"
106
112
  end
107
113
 
108
114
  it "should not match requests if body is different" do
109
- stub_http_request(:get, "www.google.com").with(:body => "abc")
110
-
115
+ stub_http_request(:get, "www.example.com").with(:body => "abc")
111
116
  lambda {
112
- http_request(:get, "http://www.google.com/", :body => "def")
113
- }.should raise_error(WebMock::NetConnectNotAllowedError,
114
- "Real HTTP connections are disabled. Unregistered request: GET http://www.google.com/ with body 'def'")
117
+ http_request(:get, "http://www.example.com/", :body => "def")
118
+ }.should fail_with("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with body 'def'")
115
119
  end
116
120
 
117
121
  end
@@ -119,61 +123,57 @@ describe "WebMock", :shared => true do
119
123
  describe "on headers" do
120
124
 
121
125
  it "should match requests if headers are the same" do
122
- stub_http_request(:get, "www.google.com").with(:headers => SAMPLE_HEADERS )
126
+ stub_http_request(:get, "www.example.com").with(:headers => SAMPLE_HEADERS )
123
127
  http_request(
124
- :get, "http://www.google.com/",
128
+ :get, "http://www.example.com/",
125
129
  :headers => SAMPLE_HEADERS).status.should == "200"
126
130
  end
127
131
 
128
132
  it "should match requests if request headers are not stubbed" do
129
- stub_http_request(:get, "www.google.com")
133
+ stub_http_request(:get, "www.example.com")
130
134
  http_request(
131
- :get, "http://www.google.com/",
135
+ :get, "http://www.example.com/",
132
136
  :headers => SAMPLE_HEADERS).status.should == "200"
133
137
  end
134
138
 
135
139
 
136
140
  it "should not match requests if headers are different" do
137
- stub_http_request(:get, "www.google.com").with(:headers => SAMPLE_HEADERS)
141
+ stub_http_request(:get, "www.example.com").with(:headers => SAMPLE_HEADERS)
138
142
 
139
143
  lambda {
140
144
  http_request(
141
- :get, "http://www.google.com/",
145
+ :get, "http://www.example.com/",
142
146
  :headers => { 'Content-Length' => '9999'})
143
- }.should raise_error(WebMock::NetConnectNotAllowedError,
144
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.google.com/ with headers {'Content-Length'=>'9999'}))
147
+ }.should fail_with(%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Content-Length'=>'9999'}))
145
148
  end
146
149
  end
147
150
 
148
151
  describe "with basic authentication" do
149
152
 
150
153
  it "should match if credentials are the same" do
151
- stub_http_request(:get, "user:pass@www.google.com")
152
- http_request(:get, "http://user:pass@www.google.com/").status.should == "200"
154
+ stub_http_request(:get, "user:pass@www.example.com")
155
+ http_request(:get, "http://user:pass@www.example.com/").status.should == "200"
153
156
  end
154
157
 
155
158
  it "should not match if credentials are different" do
156
- stub_http_request(:get, "user:pass@www.google.com")
159
+ stub_http_request(:get, "user:pass@www.example.com")
157
160
  lambda {
158
- http_request(:get, "http://user:pazz@www.google.com/").status.should == "200"
159
- }.should raise_error(WebMock::NetConnectNotAllowedError,
160
- %q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.google.com/ with headers {'Authorization'=>'Basic dXNlcjpwYXp6'}))
161
+ http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
162
+ }.should fail_with(%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
161
163
  end
162
164
 
163
165
  it "should not match if credentials are stubbed but not provided in the request" do
164
- stub_http_request(:get, "user:pass@www.google.com")
166
+ stub_http_request(:get, "user:pass@www.example.com")
165
167
  lambda {
166
- http_request(:get, "http://www.google.com/").status.should == "200"
167
- }.should raise_error(WebMock::NetConnectNotAllowedError,
168
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.google.com/))
168
+ http_request(:get, "http://www.example.com/").status.should == "200"
169
+ }.should fail_with(%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
169
170
  end
170
171
 
171
172
  it "should not match if credentials are not stubbed but exist in the request" do
172
- stub_http_request(:get, "www.google.com")
173
+ stub_http_request(:get, "www.example.com")
173
174
  lambda {
174
- http_request(:get, "http://user:pazz@www.google.com/").status.should == "200"
175
- }.should raise_error(WebMock::NetConnectNotAllowedError,
176
- %q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.google.com/ with headers {'Authorization'=>'Basic dXNlcjpwYXp6'}))
175
+ http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
176
+ }.should fail_with(%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
177
177
  end
178
178
 
179
179
  end
@@ -184,9 +184,9 @@ describe "WebMock", :shared => true do
184
184
 
185
185
  it "should raise exception if declared in a stubbed response" do
186
186
  class MyException < StandardError; end;
187
- stub_http_request(:get, "www.google.com").to_raise(MyException)
187
+ stub_http_request(:get, "www.example.com").to_raise(MyException)
188
188
  lambda {
189
- http_request(:get, "http://www.google.com/")
189
+ http_request(:get, "http://www.example.com/")
190
190
  }.should raise_error(MyException, "Exception from WebMock")
191
191
  end
192
192
 
@@ -196,19 +196,34 @@ describe "WebMock", :shared => true do
196
196
  describe "returning stubbed responses" do
197
197
 
198
198
  it "should return declared body" do
199
- stub_http_request(:get, "www.google.com").to_return(:body => "abc")
200
- http_request(:get, "http://www.google.com/").body.should == "abc"
199
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc")
200
+ http_request(:get, "http://www.example.com/").body.should == "abc"
201
201
  end
202
202
 
203
203
  it "should return declared headers" do
204
- stub_http_request(:get, "www.google.com").to_return(:headers => SAMPLE_HEADERS)
205
- response = http_request(:get, "http://www.google.com/")
204
+ stub_http_request(:get, "www.example.com").to_return(:headers => SAMPLE_HEADERS)
205
+ response = http_request(:get, "http://www.example.com/")
206
206
  response.headers["Content-Length"].should == "8888"
207
207
  end
208
208
 
209
209
  it "should return declared status" do
210
- stub_http_request(:get, "www.google.com").to_return(:status => 500)
211
- http_request(:get, "http://www.google.com/").status.should == "500"
210
+ stub_http_request(:get, "www.example.com").to_return(:status => 500)
211
+ http_request(:get, "http://www.example.com/").status.should == "500"
212
+ end
213
+
214
+
215
+ describe "dynamic responses" do
216
+
217
+ it "should return evaluated response body" do
218
+ stub_http_request(:post, "www.example.com").to_return(:body => lambda { |request| request.body })
219
+ http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
220
+ end
221
+
222
+ it "should return evaluated response headers" do
223
+ stub_http_request(:post, "www.example.com").to_return(:headers => lambda { |request| request.headers })
224
+ http_request(:post, "http://www.example.com/", :headers => {'A' => 'B'}).headers['A'].should == 'B'
225
+ end
226
+
212
227
  end
213
228
 
214
229
  end
@@ -217,15 +232,15 @@ describe "WebMock", :shared => true do
217
232
  describe "precedence of stubs" do
218
233
 
219
234
  it "should use the last declared matching request stub" do
220
- stub_http_request(:get, "www.google.com").to_return(:body => "abc")
221
- stub_http_request(:get, "www.google.com").to_return(:body => "def")
222
- http_request(:get, "http://www.google.com/").body.should == "def"
235
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc")
236
+ stub_http_request(:get, "www.example.com").to_return(:body => "def")
237
+ http_request(:get, "http://www.example.com/").body.should == "def"
223
238
  end
224
239
 
225
240
  it "should not be affected by the type of uri or request method" do
226
- stub_http_request(:get, "www.google.com").to_return(:body => "abc")
227
- stub_http_request(:any, /.*google.*/).to_return(:body => "def")
228
- http_request(:get, "http://www.google.com/").body.should == "def"
241
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc")
242
+ stub_http_request(:any, /.*example.*/).to_return(:body => "def")
243
+ http_request(:get, "http://www.example.com/").body.should == "def"
229
244
  end
230
245
 
231
246
  end
@@ -236,83 +251,83 @@ describe "WebMock", :shared => true do
236
251
 
237
252
  before(:each) do
238
253
  WebMock.disable_net_connect!
239
- stub_http_request(:any, "http://www.google.com")
240
- stub_http_request(:any, "https://www.google.com")
254
+ stub_http_request(:any, "http://www.example.com")
255
+ stub_http_request(:any, "https://www.example.com")
241
256
  end
242
257
 
243
258
  it "should pass if request was executed with the same uri and method" do
244
259
  lambda {
245
- http_request(:get, "http://www.google.com/")
246
- request(:get, "http://www.google.com").should have_been_made.once
260
+ http_request(:get, "http://www.example.com/")
261
+ request(:get, "http://www.example.com").should have_been_made.once
247
262
  }.should_not raise_error
248
263
  end
249
264
 
250
265
  it "should pass if request was not expected and not executed" do
251
266
  lambda {
252
- request(:get, "http://www.google.com").should_not have_been_made
267
+ request(:get, "http://www.example.com").should_not have_been_made
253
268
  }.should_not raise_error
254
269
  end
255
270
 
256
271
  it "should fail if request was not expected but executed" do
257
272
  lambda {
258
- http_request(:get, "http://www.google.com/")
259
- request(:get, "http://www.google.com").should_not have_been_made
260
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 0 times but it executed 1 time")
273
+ http_request(:get, "http://www.example.com/")
274
+ request(:get, "http://www.example.com").should_not have_been_made
275
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
261
276
  end
262
277
 
263
278
 
264
279
  it "should fail if request was not executed" do
265
280
  lambda {
266
- request(:get, "http://www.google.com").should have_been_made
267
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 1 time but it executed 0 times")
281
+ request(:get, "http://www.example.com").should have_been_made
282
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
268
283
  end
269
284
 
270
285
  it "should fail if request was executed to different uri" do
271
286
  lambda {
272
- http_request(:get, "http://www.google.com/")
273
- request(:get, "http://www.google.org").should have_been_made
274
- }.should fail_with("The request GET http://www.google.org/ was expected to execute 1 time but it executed 0 times")
287
+ http_request(:get, "http://www.example.com/")
288
+ request(:get, "http://www.example.org").should have_been_made
289
+ }.should fail_with("The request GET http://www.example.org/ was expected to execute 1 time but it executed 0 times")
275
290
  end
276
291
 
277
292
  it "should fail if request was executed with different method" do
278
293
  lambda {
279
- http_request(:post, "http://www.google.com/")
280
- request(:get, "http://www.google.com").should have_been_made
281
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 1 time but it executed 0 times")
294
+ http_request(:post, "http://www.example.com/")
295
+ request(:get, "http://www.example.com").should have_been_made
296
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
282
297
  end
283
298
 
284
299
  it "should pass if request was executed with different form of uri" do
285
300
  lambda {
286
- http_request(:get, "http://www.google.com/")
287
- request(:get, "www.google.com").should have_been_made
301
+ http_request(:get, "http://www.example.com/")
302
+ request(:get, "www.example.com").should have_been_made
288
303
  }.should_not raise_error
289
304
  end
290
305
 
291
306
  it "should pass if request was executed with different form of uri without port " do
292
307
  lambda {
293
- http_request(:get, "http://www.google.com/")
294
- request(:get, "www.google.com:80").should have_been_made
308
+ http_request(:get, "http://www.example.com/")
309
+ request(:get, "www.example.com:80").should have_been_made
295
310
  }.should_not raise_error
296
311
  end
297
312
 
298
313
  it "should pass if request was executed with different form of uri with port" do
299
314
  lambda {
300
- http_request(:get, "http://www.google.com/")
301
- request(:get, "www.google.com:80").should have_been_made
315
+ http_request(:get, "http://www.example.com/")
316
+ request(:get, "www.example.com:80").should have_been_made
302
317
  }.should_not raise_error
303
318
  end
304
319
 
305
320
  it "should fail if request was executed with different port" do
306
321
  lambda {
307
- http_request(:get, "http://www.google.com:80/")
308
- request(:get, "www.google.com:90").should have_been_made
309
- }.should fail_with("The request GET http://www.google.com:90/ was expected to execute 1 time but it executed 0 times")
322
+ http_request(:get, "http://www.example.com:80/")
323
+ request(:get, "www.example.com:90").should have_been_made
324
+ }.should fail_with("The request GET http://www.example.com:90/ was expected to execute 1 time but it executed 0 times")
310
325
  end
311
326
 
312
327
  it "should pass if request was executed with different form of uri with https port" do
313
328
  lambda {
314
- http_request(:get, "https://www.google.com/")
315
- request(:get, "https://www.google.com:443/").should have_been_made
329
+ http_request(:get, "https://www.example.com/")
330
+ request(:get, "https://www.example.com:443/").should have_been_made
316
331
  }.should_not raise_error
317
332
  end
318
333
 
@@ -320,145 +335,145 @@ describe "WebMock", :shared => true do
320
335
 
321
336
  before(:each) do
322
337
  WebMock.disable_net_connect!
323
- stub_http_request(:any, "http://www.google.com/?#{NOT_ESCAPED_PARAMS}")
338
+ stub_http_request(:any, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}")
324
339
  end
325
340
 
326
341
  it "should pass if request was executed with escaped params" do
327
342
  lambda {
328
- http_request(:get, "http://www.google.com/?#{ESCAPED_PARAMS}")
329
- request(:get, "http://www.google.com/?#{NOT_ESCAPED_PARAMS}").should have_been_made
343
+ http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}")
344
+ request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}").should have_been_made
330
345
  }.should_not raise_error
331
346
  end
332
347
 
333
348
  it "should pass if request was executed with non escaped params but escaped expected" do
334
349
  lambda {
335
- http_request(:get, "http://www.google.com/?#{NOT_ESCAPED_PARAMS}")
336
- request(:get, "http://www.google.com/?#{ESCAPED_PARAMS}").should have_been_made
350
+ http_request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}")
351
+ request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").should have_been_made
337
352
  }.should_not raise_error
338
353
  end
339
354
 
340
355
  it "should pass if request was executed with escaped params but uri matichg regexp expected" do
341
356
  lambda {
342
- http_request(:get, "http://www.google.com/?#{ESCAPED_PARAMS}")
343
- request(:get, /.*google.*/).should have_been_made
357
+ http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}")
358
+ request(:get, /.*example.*/).should have_been_made
344
359
  }.should_not raise_error
345
360
  end
346
361
  end
347
362
 
348
363
  it "should fail if requested more times than expected" do
349
364
  lambda {
350
- http_request(:get, "http://www.google.com/")
351
- http_request(:get, "http://www.google.com/")
352
- request(:get, "http://www.google.com").should have_been_made
353
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 1 time but it executed 2 times")
365
+ http_request(:get, "http://www.example.com/")
366
+ http_request(:get, "http://www.example.com/")
367
+ request(:get, "http://www.example.com").should have_been_made
368
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 2 times")
354
369
  end
355
370
 
356
371
  it "should fail if requested less times than expected" do
357
372
  lambda {
358
- http_request(:get, "http://www.google.com/")
359
- request(:get, "http://www.google.com").should have_been_made.twice
360
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 2 times but it executed 1 time")
373
+ http_request(:get, "http://www.example.com/")
374
+ request(:get, "http://www.example.com").should have_been_made.twice
375
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 2 times but it executed 1 time")
361
376
  end
362
377
 
363
378
  it "should fail if requested less times than expected when 3 times expected" do
364
379
  lambda {
365
- http_request(:get, "http://www.google.com/")
366
- request(:get, "http://www.google.com").should have_been_made.times(3)
367
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 3 times but it executed 1 time")
380
+ http_request(:get, "http://www.example.com/")
381
+ request(:get, "http://www.example.com").should have_been_made.times(3)
382
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 3 times but it executed 1 time")
368
383
  end
369
384
 
370
385
  it "should succeed if request was executed with the same body" do
371
386
  lambda {
372
- http_request(:get, "http://www.google.com/", :body => "abc")
373
- request(:get, "www.google.com").with(:body => "abc").should have_been_made
387
+ http_request(:get, "http://www.example.com/", :body => "abc")
388
+ request(:get, "www.example.com").with(:body => "abc").should have_been_made
374
389
  }.should_not raise_error
375
390
  end
376
391
 
377
392
  it "should fail if request was executed with different body" do
378
393
  lambda {
379
- http_request(:get, "http://www.google.com/", :body => "abc")
380
- request(:get, "www.google.com").
394
+ http_request(:get, "http://www.example.com/", :body => "abc")
395
+ request(:get, "www.example.com").
381
396
  with(:body => "def").should have_been_made
382
- }.should fail_with("The request GET http://www.google.com/ with body 'def' was expected to execute 1 time but it executed 0 times")
397
+ }.should fail_with("The request GET http://www.example.com/ with body 'def' was expected to execute 1 time but it executed 0 times")
383
398
  end
384
399
 
385
400
  it "should succeed if request was executed with the same headers" do
386
401
  lambda {
387
- http_request(:get, "http://www.google.com/", :headers => SAMPLE_HEADERS)
388
- request(:get, "www.google.com").
402
+ http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
403
+ request(:get, "www.example.com").
389
404
  with(:headers => SAMPLE_HEADERS).should have_been_made
390
405
  }.should_not raise_error
391
406
  end
392
407
 
393
408
  it "should fail if request was executed with different headers" do
394
409
  lambda {
395
- http_request(:get, "http://www.google.com/", :headers => SAMPLE_HEADERS)
396
- request(:get, "www.google.com").
410
+ http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
411
+ request(:get, "www.example.com").
397
412
  with(:headers => { 'Content-Length' => '9999'}).should have_been_made
398
- }.should fail_with("The request GET http://www.google.com/ with headers {'Content-Length'=>'9999'} was expected to execute 1 time but it executed 0 times")
413
+ }.should fail_with("The request GET http://www.example.com/ with headers {'Content-Length'=>'9999'} was expected to execute 1 time but it executed 0 times")
399
414
  end
400
415
 
401
416
  it "should fail if request was executed with less headers" do
402
417
  lambda {
403
- http_request(:get, "http://www.google.com/", :headers => {'A' => 'a'})
404
- request(:get, "www.google.com").
418
+ http_request(:get, "http://www.example.com/", :headers => {'A' => 'a'})
419
+ request(:get, "www.example.com").
405
420
  with(:headers => {'A' => 'a', 'B' => 'b'}).should have_been_made
406
- }.should fail_with("The request GET http://www.google.com/ with headers {'A'=>'a', 'B'=>'b'} was expected to execute 1 time but it executed 0 times")
421
+ }.should fail_with("The request GET http://www.example.com/ with headers {'A'=>'a', 'B'=>'b'} was expected to execute 1 time but it executed 0 times")
407
422
  end
408
423
 
409
424
  it "should succeed if request was executed with more headers" do
410
425
  lambda {
411
- http_request(:get, "http://www.google.com/",
426
+ http_request(:get, "http://www.example.com/",
412
427
  :headers => {'A' => 'a', 'B' => 'b'}
413
428
  )
414
- request(:get, "www.google.com").
429
+ request(:get, "www.example.com").
415
430
  with(:headers => {'A' => 'a'}).should have_been_made
416
431
  }.should_not raise_error
417
432
  end
418
433
 
419
434
  it "should succeed if request was executed with body and headers but they were not specified in expectantion" do
420
435
  lambda {
421
- http_request(:get, "http://www.google.com/",
436
+ http_request(:get, "http://www.example.com/",
422
437
  :body => "abc",
423
438
  :headers => SAMPLE_HEADERS
424
439
  )
425
- request(:get, "www.google.com").should have_been_made
440
+ request(:get, "www.example.com").should have_been_made
426
441
  }.should_not raise_error
427
442
  end
428
443
 
429
444
 
430
445
  describe "with authentication" do
431
446
  before(:each) do
432
- stub_http_request(:any, "http://user:pass@www.google.com")
433
- stub_http_request(:any, "http://user:pazz@www.google.com")
447
+ stub_http_request(:any, "http://user:pass@www.example.com")
448
+ stub_http_request(:any, "http://user:pazz@www.example.com")
434
449
  end
435
450
 
436
451
  it "should succeed if succeed if request was executed with expected credentials" do
437
452
  lambda {
438
- http_request(:get, "http://user:pass@www.google.com/")
439
- request(:get, "http://user:pass@www.google.com").should have_been_made.once
453
+ http_request(:get, "http://user:pass@www.example.com/")
454
+ request(:get, "http://user:pass@www.example.com").should have_been_made.once
440
455
  }.should_not raise_error
441
456
  end
442
457
 
443
458
  it "should fail if request was executed with different credentials than expected" do
444
459
  lambda {
445
- http_request(:get, "http://user:pass@www.google.com/")
446
- request(:get, "http://user:pazz@www.google.com").should have_been_made.once
447
- }.should fail_with("The request GET http://user:pazz@www.google.com/ was expected to execute 1 time but it executed 0 times")
460
+ http_request(:get, "http://user:pass@www.example.com/")
461
+ request(:get, "http://user:pazz@www.example.com").should have_been_made.once
462
+ }.should fail_with("The request GET http://user:pazz@www.example.com/ was expected to execute 1 time but it executed 0 times")
448
463
  end
449
464
 
450
465
  it "should fail if request was executed without credentials but credentials were expected" do
451
466
  lambda {
452
- http_request(:get, "http://www.google.com/")
453
- request(:get, "http://user:pass@www.google.com").should have_been_made.once
454
- }.should fail_with("The request GET http://user:pass@www.google.com/ was expected to execute 1 time but it executed 0 times")
467
+ http_request(:get, "http://www.example.com/")
468
+ request(:get, "http://user:pass@www.example.com").should have_been_made.once
469
+ }.should fail_with("The request GET http://user:pass@www.example.com/ was expected to execute 1 time but it executed 0 times")
455
470
  end
456
471
 
457
472
  it "should fail if request was executed with credentials but expected without" do
458
473
  lambda {
459
- http_request(:get, "http://user:pass@www.google.com/")
460
- request(:get, "http://www.google.com").should have_been_made.once
461
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 1 time but it executed 0 times")
474
+ http_request(:get, "http://user:pass@www.example.com/")
475
+ request(:get, "http://www.example.com").should have_been_made.once
476
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
462
477
  end
463
478
 
464
479
  end
@@ -467,23 +482,23 @@ describe "WebMock", :shared => true do
467
482
 
468
483
  it "should verify expected requests occured" do
469
484
  lambda {
470
- http_request(:get, "http://www.google.com/")
471
- WebMock.should have_requested(:get, "http://www.google.com").once
485
+ http_request(:get, "http://www.example.com/")
486
+ WebMock.should have_requested(:get, "http://www.example.com").once
472
487
  }.should_not raise_error
473
488
  end
474
489
 
475
490
  it "should verify expected requests occured" do
476
491
  lambda {
477
- http_request(:get, "http://www.google.com/", :body => "abc", :headers => {'A' => 'a'})
478
- WebMock.should have_requested(:get, "http://www.google.com").with(:body => "abc", :headers => {'A' => 'a'}).once
492
+ http_request(:get, "http://www.example.com/", :body => "abc", :headers => {'A' => 'a'})
493
+ WebMock.should have_requested(:get, "http://www.example.com").with(:body => "abc", :headers => {'A' => 'a'}).once
479
494
  }.should_not raise_error
480
495
  end
481
496
 
482
497
  it "should verify that non expected requests didn't occur" do
483
498
  lambda {
484
- http_request(:get, "http://www.google.com/")
485
- WebMock.should_not have_requested(:get, "http://www.google.com")
486
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 0 times but it executed 1 time")
499
+ http_request(:get, "http://www.example.com/")
500
+ WebMock.should_not have_requested(:get, "http://www.example.com")
501
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
487
502
  end
488
503
  end
489
504
 
@@ -493,24 +508,24 @@ describe "WebMock", :shared => true do
493
508
 
494
509
  it "should verify expected requests occured" do
495
510
  lambda {
496
- http_request(:get, "http://www.google.com/")
497
- assert_requested(:get, "http://www.google.com", :times => 1)
498
- assert_requested(:get, "http://www.google.com")
511
+ http_request(:get, "http://www.example.com/")
512
+ assert_requested(:get, "http://www.example.com", :times => 1)
513
+ assert_requested(:get, "http://www.example.com")
499
514
  }.should_not raise_error
500
515
  end
501
516
 
502
517
  it "should verify expected requests occured" do
503
518
  lambda {
504
- http_request(:get, "http://www.google.com/", :body => "abc", :headers => {'A' => 'a'})
505
- assert_requested(:get, "http://www.google.com", :body => "abc", :headers => {'A' => 'a'})
519
+ http_request(:get, "http://www.example.com/", :body => "abc", :headers => {'A' => 'a'})
520
+ assert_requested(:get, "http://www.example.com", :body => "abc", :headers => {'A' => 'a'})
506
521
  }.should_not raise_error
507
522
  end
508
523
 
509
524
  it "should verify that non expected requests didn't occur" do
510
525
  lambda {
511
- http_request(:get, "http://www.google.com/")
512
- assert_not_requested(:get, "http://www.google.com")
513
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 0 times but it executed 1 time")
526
+ http_request(:get, "http://www.example.com/")
527
+ assert_not_requested(:get, "http://www.example.com")
528
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
514
529
  end
515
530
  end
516
531
  end
@@ -522,18 +537,18 @@ describe "WebMock", :shared => true do
522
537
  end
523
538
 
524
539
  it "should verify expected requests occured" do
525
- setup_expectations_for_real_google_request
540
+ setup_expectations_for_real_example_com_request
526
541
  lambda {
527
- http_request(:get, "http://www.google.com/")
528
- request(:get, "http://www.google.com").should have_been_made
542
+ http_request(:get, "http://www.example.com/")
543
+ request(:get, "http://www.example.com").should have_been_made
529
544
  }.should_not raise_error
530
545
  end
531
546
 
532
547
  it "should verify that non expected requests didn't occur" do
533
548
  lambda {
534
- http_request(:get, "http://www.google.com/")
535
- request(:get, "http://www.google.com").should_not have_been_made
536
- }.should fail_with("The request GET http://www.google.com/ was expected to execute 0 times but it executed 1 time")
549
+ http_request(:get, "http://www.example.com/")
550
+ request(:get, "http://www.example.com").should_not have_been_made
551
+ }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
537
552
  end
538
553
  end
539
554