ww 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,16 @@
3
3
  <head>
4
4
  <title>3 requests - Double Web</title>
5
5
  <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js'></script>
6
+ <script type='text/javascript'>
7
+ //<![CDATA[
8
+ $(function(){
9
+ $(".request .headers h3").click(function(){ $(this).next("table").toggle() });
10
+ $(".request .body h3").click(function(){ $(this).next("pre").toggle() });
11
+ $(".request .headers table").hide();
12
+ $(".request .body pre").hide();
13
+ });
14
+ //]]>
15
+ </script>
6
16
  <style type='text/css'>
7
17
  body {
8
18
  width: 80%;
@@ -11,326 +21,310 @@
11
21
  h1 {
12
22
  font-size: 10px; }
13
23
 
14
- div.stump {
24
+ .request {
15
25
  font-size: 10px;
16
26
  border: 1px solid silver;
17
27
  padding: 0 1em; }
18
- div.stump h2 {
28
+ .request h2 {
19
29
  font-size: 10px;
20
30
  color: gray; }
21
- div.stump h2 span.method, div.stump h2 span.path {
31
+ .request h2 span.method, .request h2 span.path {
22
32
  font-size: 16px;
23
33
  font-weight: normal;
24
34
  font-family: 'Courier', monospace; }
25
- div.stump h2 span.method {
35
+ .request h2 span.method {
26
36
  color: #090; }
27
- div.stump h2 span.path {
37
+ .request h2 span.path {
28
38
  color: black; }
29
- div.stump h2 span.time, div.stump h2 span.source {
39
+ .request h2 span.time, .request h2 span.source {
30
40
  color: blue; }
31
- div.stump h3 {
41
+ .request h3 {
32
42
  font-size: small;
33
43
  border-bottom: 1px solid green;
34
44
  background: #cfb;
35
45
  padding: 2px 0 0 2px; }
36
- div.stump h3 span.media_type {
46
+ .request h3 span.media_type {
37
47
  color: blue;
38
48
  font-size: small;
39
49
  font-weight: normal;
40
50
  font-family: 'Courier', monospace; }
41
- div.stump .headers table, div.stump div.body pre {
51
+ .request .headers table, .request .body pre {
42
52
  border: 1px dashed green;
43
53
  margin: 1em;
44
54
  padding: 1em; }
45
- div.stump div.body pre {
55
+ .request .body pre {
46
56
  overflow: auto;
47
57
  font-size: 12px; }
48
58
  </style>
49
59
  </head>
50
60
  <body>
51
61
  <h1>3 requests - Double Web</h1>
52
- <div class='stump' id='13699160'>
62
+ <div class='request' id='13725230'>
53
63
  <h2>
54
64
  <span class='method'>POST</span>
55
65
  <span class='path'>/hello</span>
56
66
  on
57
- <span class='time'>2010-01-16T23:57:01+09:00</span>
67
+ <span class='time'>2010-01-18T18:25:13+09:00</span>
58
68
  from
59
69
  <span class='source'>127.0.0.1</span>
60
70
  </h2>
61
- <div>
62
- <div class='headers'>
63
- <h3>Headers</h3>
64
- <table>
65
- <tr>
66
- <th>HTTP_ACCEPT</th>
67
- <td>*/*</td>
68
- </tr>
69
- <tr>
70
- <th>HTTP_HOST</th>
71
- <td>localhost:8888</td>
72
- </tr>
73
- <tr>
74
- <th>SERVER_NAME</th>
75
- <td>localhost</td>
76
- </tr>
77
- <tr>
78
- <th>CONTENT_LENGTH</th>
79
- <td>28</td>
80
- </tr>
81
- <tr>
82
- <th>HTTP_USER_AGENT</th>
83
- <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
84
- </tr>
85
- <tr>
86
- <th>REQUEST_PATH</th>
87
- <td>/hello</td>
88
- </tr>
89
- <tr>
90
- <th>SERVER_PROTOCOL</th>
91
- <td>HTTP/1.1</td>
92
- </tr>
93
- <tr>
94
- <th>CONTENT_TYPE</th>
95
- <td>application/x-www-form-urlencoded</td>
96
- </tr>
97
- <tr>
98
- <th>REMOTE_ADDR</th>
99
- <td>127.0.0.1</td>
100
- </tr>
101
- <tr>
102
- <th>PATH_INFO</th>
103
- <td>/hello</td>
104
- </tr>
105
- <tr>
106
- <th>SERVER_SOFTWARE</th>
107
- <td>thin 1.2.5 codename This Is Not A Web Server</td>
108
- </tr>
109
- <tr>
110
- <th>SCRIPT_NAME</th>
111
- <td></td>
112
- </tr>
113
- <tr>
114
- <th>HTTP_VERSION</th>
115
- <td>HTTP/1.1</td>
116
- </tr>
117
- <tr>
118
- <th>REQUEST_URI</th>
119
- <td>/hello</td>
120
- </tr>
121
- <tr>
122
- <th>SERVER_PORT</th>
123
- <td>8888</td>
124
- </tr>
125
- <tr>
126
- <th>REQUEST_METHOD</th>
127
- <td>POST</td>
128
- </tr>
129
- <tr>
130
- <th>QUERY_STRING</th>
131
- <td></td>
132
- </tr>
133
- <tr>
134
- <th>GATEWAY_INTERFACE</th>
135
- <td>CGI/1.2</td>
136
- </tr>
137
- </table>
138
- </div>
139
- <div class='body'>
140
- <h3>
141
- Body
142
- <span class='media_type'>application/x-www-form-urlencoded</span>
143
- </h3>
144
- <pre>{&quot;message&quot;=&gt;&quot;How are you?&quot;, &quot;key&quot;=&gt;&quot;2nd&quot;}</pre>
145
- </div>
71
+ <div class='headers'>
72
+ <h3>Headers</h3>
73
+ <table>
74
+ <tr>
75
+ <th>HTTP_ACCEPT</th>
76
+ <td>*/*</td>
77
+ </tr>
78
+ <tr>
79
+ <th>HTTP_HOST</th>
80
+ <td>localhost:8888</td>
81
+ </tr>
82
+ <tr>
83
+ <th>SERVER_NAME</th>
84
+ <td>localhost</td>
85
+ </tr>
86
+ <tr>
87
+ <th>CONTENT_LENGTH</th>
88
+ <td>28</td>
89
+ </tr>
90
+ <tr>
91
+ <th>HTTP_USER_AGENT</th>
92
+ <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
93
+ </tr>
94
+ <tr>
95
+ <th>REQUEST_PATH</th>
96
+ <td>/hello</td>
97
+ </tr>
98
+ <tr>
99
+ <th>SERVER_PROTOCOL</th>
100
+ <td>HTTP/1.1</td>
101
+ </tr>
102
+ <tr>
103
+ <th>CONTENT_TYPE</th>
104
+ <td>application/x-www-form-urlencoded</td>
105
+ </tr>
106
+ <tr>
107
+ <th>REMOTE_ADDR</th>
108
+ <td>127.0.0.1</td>
109
+ </tr>
110
+ <tr>
111
+ <th>PATH_INFO</th>
112
+ <td>/hello</td>
113
+ </tr>
114
+ <tr>
115
+ <th>SERVER_SOFTWARE</th>
116
+ <td>thin 1.2.5 codename This Is Not A Web Server</td>
117
+ </tr>
118
+ <tr>
119
+ <th>SCRIPT_NAME</th>
120
+ <td></td>
121
+ </tr>
122
+ <tr>
123
+ <th>HTTP_VERSION</th>
124
+ <td>HTTP/1.1</td>
125
+ </tr>
126
+ <tr>
127
+ <th>REQUEST_URI</th>
128
+ <td>/hello</td>
129
+ </tr>
130
+ <tr>
131
+ <th>SERVER_PORT</th>
132
+ <td>8888</td>
133
+ </tr>
134
+ <tr>
135
+ <th>REQUEST_METHOD</th>
136
+ <td>POST</td>
137
+ </tr>
138
+ <tr>
139
+ <th>QUERY_STRING</th>
140
+ <td></td>
141
+ </tr>
142
+ <tr>
143
+ <th>GATEWAY_INTERFACE</th>
144
+ <td>CGI/1.2</td>
145
+ </tr>
146
+ </table>
147
+ </div>
148
+ <div class='body'>
149
+ <h3>
150
+ Body
151
+ <span class='media_type'>application/x-www-form-urlencoded</span>
152
+ </h3>
153
+ <pre>{&quot;message&quot;=&gt;&quot;How are you?&quot;, &quot;key&quot;=&gt;&quot;2nd&quot;}</pre>
146
154
  </div>
147
155
  </div>
148
- <div class='stump' id='13730530'>
156
+ <div class='request' id='13756600'>
149
157
  <h2>
150
158
  <span class='method'>POST</span>
151
159
  <span class='path'>/hello</span>
152
160
  on
153
- <span class='time'>2010-01-16T23:57:01+09:00</span>
161
+ <span class='time'>2010-01-18T18:25:08+09:00</span>
154
162
  from
155
163
  <span class='source'>127.0.0.1</span>
156
164
  </h2>
157
- <div>
158
- <div class='headers'>
159
- <h3>Headers</h3>
160
- <table>
161
- <tr>
162
- <th>HTTP_ACCEPT</th>
163
- <td>*/*</td>
164
- </tr>
165
- <tr>
166
- <th>HTTP_HOST</th>
167
- <td>localhost:8888</td>
168
- </tr>
169
- <tr>
170
- <th>SERVER_NAME</th>
171
- <td>localhost</td>
172
- </tr>
173
- <tr>
174
- <th>CONTENT_LENGTH</th>
175
- <td>27</td>
176
- </tr>
177
- <tr>
178
- <th>HTTP_USER_AGENT</th>
179
- <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
180
- </tr>
181
- <tr>
182
- <th>REQUEST_PATH</th>
183
- <td>/hello</td>
184
- </tr>
185
- <tr>
186
- <th>SERVER_PROTOCOL</th>
187
- <td>HTTP/1.1</td>
188
- </tr>
189
- <tr>
190
- <th>CONTENT_TYPE</th>
191
- <td>application/x-www-form-urlencoded</td>
192
- </tr>
193
- <tr>
194
- <th>REMOTE_ADDR</th>
195
- <td>127.0.0.1</td>
196
- </tr>
197
- <tr>
198
- <th>PATH_INFO</th>
199
- <td>/hello</td>
200
- </tr>
201
- <tr>
202
- <th>SERVER_SOFTWARE</th>
203
- <td>thin 1.2.5 codename This Is Not A Web Server</td>
204
- </tr>
205
- <tr>
206
- <th>SCRIPT_NAME</th>
207
- <td></td>
208
- </tr>
209
- <tr>
210
- <th>HTTP_VERSION</th>
211
- <td>HTTP/1.1</td>
212
- </tr>
213
- <tr>
214
- <th>REQUEST_URI</th>
215
- <td>/hello</td>
216
- </tr>
217
- <tr>
218
- <th>SERVER_PORT</th>
219
- <td>8888</td>
220
- </tr>
221
- <tr>
222
- <th>REQUEST_METHOD</th>
223
- <td>POST</td>
224
- </tr>
225
- <tr>
226
- <th>QUERY_STRING</th>
227
- <td></td>
228
- </tr>
229
- <tr>
230
- <th>GATEWAY_INTERFACE</th>
231
- <td>CGI/1.2</td>
232
- </tr>
233
- </table>
234
- </div>
235
- <div class='body'>
236
- <h3>
237
- Body
238
- <span class='media_type'>application/x-www-form-urlencoded</span>
239
- </h3>
240
- <pre>{&quot;message&quot;=&gt;&quot;KON-NICHIWA&quot;, &quot;key&quot;=&gt;&quot;1st&quot;}</pre>
241
- </div>
165
+ <div class='headers'>
166
+ <h3>Headers</h3>
167
+ <table>
168
+ <tr>
169
+ <th>HTTP_ACCEPT</th>
170
+ <td>*/*</td>
171
+ </tr>
172
+ <tr>
173
+ <th>HTTP_HOST</th>
174
+ <td>localhost:8888</td>
175
+ </tr>
176
+ <tr>
177
+ <th>SERVER_NAME</th>
178
+ <td>localhost</td>
179
+ </tr>
180
+ <tr>
181
+ <th>CONTENT_LENGTH</th>
182
+ <td>27</td>
183
+ </tr>
184
+ <tr>
185
+ <th>HTTP_USER_AGENT</th>
186
+ <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
187
+ </tr>
188
+ <tr>
189
+ <th>REQUEST_PATH</th>
190
+ <td>/hello</td>
191
+ </tr>
192
+ <tr>
193
+ <th>SERVER_PROTOCOL</th>
194
+ <td>HTTP/1.1</td>
195
+ </tr>
196
+ <tr>
197
+ <th>CONTENT_TYPE</th>
198
+ <td>application/x-www-form-urlencoded</td>
199
+ </tr>
200
+ <tr>
201
+ <th>REMOTE_ADDR</th>
202
+ <td>127.0.0.1</td>
203
+ </tr>
204
+ <tr>
205
+ <th>PATH_INFO</th>
206
+ <td>/hello</td>
207
+ </tr>
208
+ <tr>
209
+ <th>SERVER_SOFTWARE</th>
210
+ <td>thin 1.2.5 codename This Is Not A Web Server</td>
211
+ </tr>
212
+ <tr>
213
+ <th>SCRIPT_NAME</th>
214
+ <td></td>
215
+ </tr>
216
+ <tr>
217
+ <th>HTTP_VERSION</th>
218
+ <td>HTTP/1.1</td>
219
+ </tr>
220
+ <tr>
221
+ <th>REQUEST_URI</th>
222
+ <td>/hello</td>
223
+ </tr>
224
+ <tr>
225
+ <th>SERVER_PORT</th>
226
+ <td>8888</td>
227
+ </tr>
228
+ <tr>
229
+ <th>REQUEST_METHOD</th>
230
+ <td>POST</td>
231
+ </tr>
232
+ <tr>
233
+ <th>QUERY_STRING</th>
234
+ <td></td>
235
+ </tr>
236
+ <tr>
237
+ <th>GATEWAY_INTERFACE</th>
238
+ <td>CGI/1.2</td>
239
+ </tr>
240
+ </table>
241
+ </div>
242
+ <div class='body'>
243
+ <h3>
244
+ Body
245
+ <span class='media_type'>application/x-www-form-urlencoded</span>
246
+ </h3>
247
+ <pre>{&quot;message&quot;=&gt;&quot;KON-NICHIWA&quot;, &quot;key&quot;=&gt;&quot;1st&quot;}</pre>
242
248
  </div>
243
249
  </div>
244
- <div class='stump' id='13760510'>
250
+ <div class='request' id='13786580'>
245
251
  <h2>
246
252
  <span class='method'>GET</span>
247
253
  <span class='path'>/hello</span>
248
254
  on
249
- <span class='time'>2010-01-16T23:57:01+09:00</span>
255
+ <span class='time'>2010-01-18T18:24:49+09:00</span>
250
256
  from
251
257
  <span class='source'>127.0.0.1</span>
252
258
  </h2>
253
- <div>
254
- <div class='headers'>
255
- <h3>Headers</h3>
256
- <table>
257
- <tr>
258
- <th>HTTP_ACCEPT</th>
259
- <td>*/*</td>
260
- </tr>
261
- <tr>
262
- <th>HTTP_HOST</th>
263
- <td>localhost:8888</td>
264
- </tr>
265
- <tr>
266
- <th>SERVER_NAME</th>
267
- <td>localhost</td>
268
- </tr>
269
- <tr>
270
- <th>HTTP_USER_AGENT</th>
271
- <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
272
- </tr>
273
- <tr>
274
- <th>REQUEST_PATH</th>
275
- <td>/hello</td>
276
- </tr>
277
- <tr>
278
- <th>SERVER_PROTOCOL</th>
279
- <td>HTTP/1.1</td>
280
- </tr>
281
- <tr>
282
- <th>REMOTE_ADDR</th>
283
- <td>127.0.0.1</td>
284
- </tr>
285
- <tr>
286
- <th>PATH_INFO</th>
287
- <td>/hello</td>
288
- </tr>
289
- <tr>
290
- <th>SERVER_SOFTWARE</th>
291
- <td>thin 1.2.5 codename This Is Not A Web Server</td>
292
- </tr>
293
- <tr>
294
- <th>SCRIPT_NAME</th>
295
- <td></td>
296
- </tr>
297
- <tr>
298
- <th>HTTP_VERSION</th>
299
- <td>HTTP/1.1</td>
300
- </tr>
301
- <tr>
302
- <th>REQUEST_URI</th>
303
- <td>/hello</td>
304
- </tr>
305
- <tr>
306
- <th>SERVER_PORT</th>
307
- <td>8888</td>
308
- </tr>
309
- <tr>
310
- <th>REQUEST_METHOD</th>
311
- <td>GET</td>
312
- </tr>
313
- <tr>
314
- <th>QUERY_STRING</th>
315
- <td></td>
316
- </tr>
317
- <tr>
318
- <th>GATEWAY_INTERFACE</th>
319
- <td>CGI/1.2</td>
320
- </tr>
321
- </table>
322
- </div>
259
+ <div class='headers'>
260
+ <h3>Headers</h3>
261
+ <table>
262
+ <tr>
263
+ <th>HTTP_ACCEPT</th>
264
+ <td>*/*</td>
265
+ </tr>
266
+ <tr>
267
+ <th>HTTP_HOST</th>
268
+ <td>localhost:8888</td>
269
+ </tr>
270
+ <tr>
271
+ <th>SERVER_NAME</th>
272
+ <td>localhost</td>
273
+ </tr>
274
+ <tr>
275
+ <th>HTTP_USER_AGENT</th>
276
+ <td>curl/7.19.5 (i386-apple-darwin9.7.0) libcurl/7.19.5 OpenSSL/0.9.8k zlib/1.2.3</td>
277
+ </tr>
278
+ <tr>
279
+ <th>REQUEST_PATH</th>
280
+ <td>/hello</td>
281
+ </tr>
282
+ <tr>
283
+ <th>SERVER_PROTOCOL</th>
284
+ <td>HTTP/1.1</td>
285
+ </tr>
286
+ <tr>
287
+ <th>REMOTE_ADDR</th>
288
+ <td>127.0.0.1</td>
289
+ </tr>
290
+ <tr>
291
+ <th>PATH_INFO</th>
292
+ <td>/hello</td>
293
+ </tr>
294
+ <tr>
295
+ <th>SERVER_SOFTWARE</th>
296
+ <td>thin 1.2.5 codename This Is Not A Web Server</td>
297
+ </tr>
298
+ <tr>
299
+ <th>SCRIPT_NAME</th>
300
+ <td></td>
301
+ </tr>
302
+ <tr>
303
+ <th>HTTP_VERSION</th>
304
+ <td>HTTP/1.1</td>
305
+ </tr>
306
+ <tr>
307
+ <th>REQUEST_URI</th>
308
+ <td>/hello</td>
309
+ </tr>
310
+ <tr>
311
+ <th>SERVER_PORT</th>
312
+ <td>8888</td>
313
+ </tr>
314
+ <tr>
315
+ <th>REQUEST_METHOD</th>
316
+ <td>GET</td>
317
+ </tr>
318
+ <tr>
319
+ <th>QUERY_STRING</th>
320
+ <td></td>
321
+ </tr>
322
+ <tr>
323
+ <th>GATEWAY_INTERFACE</th>
324
+ <td>CGI/1.2</td>
325
+ </tr>
326
+ </table>
323
327
  </div>
324
328
  </div>
325
329
  </body>
326
330
  </html>
327
- <script type='text/javascript'>
328
- //<![CDATA[
329
- jQuery(function(){
330
- $("div.stump .headers h3").click(function(){ $(this).next("table").toggle() });
331
- $("div.stump .body h3").click(function(){ $(this).next("pre").toggle() });
332
- $("div.stump .headers table").hide();
333
- $("div.stump .body pre").hide();
334
- });
335
- //]]>
336
- </script>
@@ -5,17 +5,37 @@ module Ww
5
5
  def executed!; @e = true; end
6
6
  def executed?; !!@e; end
7
7
  attr_reader :identifier
8
- def initialize(verb, path)
8
+
9
+ def initialize(verb, path, verifier = nil)
9
10
  @identifier = "_mock_ #{verb.to_s.upcase} #{path}"
11
+ @verifier = verifier
12
+ end
13
+
14
+ def verify(request, testing_thread = nil)
15
+ return true unless @verifier && testing_thread # no need to verify
16
+ return true if @verifier.call(r = request.dup, r.params)
17
+
18
+ testing_thread.raise MockError
10
19
  end
11
20
  end
12
21
 
13
- def mock(verb, path, &block)
14
- expectations << (expect = Expectation.new(verb, path))
22
+ def testing_thread=(thread)
23
+ @testing_thread = thread
24
+ end
25
+
26
+ def testing_thread
27
+ @testing_thread
28
+ end
29
+
30
+ def mock(verb, path, options = {}, &block)
31
+ expect = Expectation.new(verb, path, options.delete(:verify))
32
+ expectations << expect
15
33
  action = Double.unbound_action(self, expect.identifier, block)
16
34
 
17
35
  stub(verb, path) do |*args|
36
+ expect.verify(request, self.class.testing_thread)
18
37
  expect.executed!
38
+
19
39
  action.bind(self).call(*args)
20
40
  end
21
41
  end