gin 1.1.2 → 1.2.0
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.
- data/History.rdoc +22 -1
- data/Manifest.txt +7 -0
- data/TODO.rdoc +45 -0
- data/bin/gin +105 -35
- data/lib/gin.rb +7 -1
- data/lib/gin/app.rb +328 -59
- data/lib/gin/asset_manifest.rb +178 -0
- data/lib/gin/asset_pipeline.rb +235 -0
- data/lib/gin/cache.rb +36 -0
- data/lib/gin/config.rb +3 -1
- data/lib/gin/constants.rb +6 -1
- data/lib/gin/controller.rb +180 -17
- data/lib/gin/core_ext/float.rb +10 -0
- data/lib/gin/core_ext/time.rb +41 -0
- data/lib/gin/filterable.rb +5 -5
- data/lib/gin/mountable.rb +100 -0
- data/lib/gin/request.rb +4 -12
- data/lib/gin/response.rb +4 -2
- data/lib/gin/router.rb +110 -37
- data/lib/gin/strict_hash.rb +33 -0
- data/lib/gin/test.rb +8 -4
- data/lib/gin/worker.rb +49 -0
- data/test/mock_app.rb +7 -7
- data/test/test_app.rb +266 -17
- data/test/test_cache.rb +73 -5
- data/test/test_config.rb +4 -4
- data/test/test_controller.rb +158 -32
- data/test/test_filterable.rb +16 -1
- data/test/test_gin.rb +7 -6
- data/test/test_request.rb +6 -1
- data/test/test_response.rb +1 -1
- data/test/test_router.rb +156 -34
- data/test/test_test.rb +51 -45
- metadata +42 -14
- checksums.yaml +0 -7
data/test/test_gin.rb
CHANGED
@@ -23,9 +23,9 @@ class GinTest < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
|
25
25
|
def test_build_query
|
26
|
-
hash = {a
|
27
|
-
expected =
|
28
|
-
assert_equal expected, Gin.build_query(hash)
|
26
|
+
hash = {:a => "bob", :b => [1,2.2,-3,{:ba =>"test"}], :c =>true, :d =>false}
|
27
|
+
expected = %w{a=bob b[]=1 b[]=2.2 b[]=-3 b[][ba]=test c=true d=false}
|
28
|
+
assert_equal expected.sort, Gin.build_query(hash).split("&").sort
|
29
29
|
end
|
30
30
|
|
31
31
|
|
@@ -39,9 +39,10 @@ class GinTest < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
|
41
41
|
def test_find_loadpath
|
42
|
-
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
42
|
+
curr_file = File.expand_path(__FILE__)
|
43
|
+
assert_equal curr_file, Gin.find_loadpath("test/test_gin")
|
44
|
+
assert_equal curr_file, Gin.find_loadpath("test/test_gin.rb")
|
45
|
+
assert_equal curr_file, Gin.find_loadpath(__FILE__)
|
45
46
|
assert_nil Gin.find_loadpath("FUUUUU")
|
46
47
|
end
|
47
48
|
|
data/test/test_request.rb
CHANGED
@@ -6,7 +6,8 @@ class RequestTest < Test::Unit::TestCase
|
|
6
6
|
@env = {
|
7
7
|
'HTTP_HOST' => 'example.com',
|
8
8
|
'rack.input' => '',
|
9
|
-
'QUERY_STRING' =>
|
9
|
+
'QUERY_STRING' =>
|
10
|
+
'id=456&foo=bar&bar=5&bool=true&zip=01234&nflt=01.123&neg=-12&negf=-2.1',
|
10
11
|
'gin.path_query_hash' => {'id' => 123},
|
11
12
|
}
|
12
13
|
@req = Gin::Request.new @env
|
@@ -17,6 +18,10 @@ class RequestTest < Test::Unit::TestCase
|
|
17
18
|
assert_equal 123, @req.params['id']
|
18
19
|
assert_equal 'bar', @req.params['foo']
|
19
20
|
assert_equal 5, @req.params['bar']
|
21
|
+
assert_equal '01234', @req.params['zip']
|
22
|
+
assert_equal '01.123', @req.params['nflt']
|
23
|
+
assert_equal -12, @req.params['neg']
|
24
|
+
assert_equal -2.1, @req.params['negf']
|
20
25
|
end
|
21
26
|
|
22
27
|
|
data/test/test_response.rb
CHANGED
data/test/test_router.rb
CHANGED
@@ -23,16 +23,16 @@ class RouterTest < Test::Unit::TestCase
|
|
23
23
|
any :thing
|
24
24
|
end
|
25
25
|
|
26
|
-
assert_equal [MyCtrl, :bar, {}],
|
26
|
+
assert_equal [[MyCtrl, :bar], {}],
|
27
27
|
@router.resources_for("GET", "/my_ctrl/bar")
|
28
28
|
|
29
|
-
assert_equal [MyCtrl, :foo, {}],
|
29
|
+
assert_equal [[MyCtrl, :foo], {}],
|
30
30
|
@router.resources_for("post", "/my_ctrl/foo")
|
31
31
|
|
32
32
|
assert_nil @router.resources_for("post", "/my_ctrl")
|
33
33
|
|
34
34
|
%w{get post put delete head options trace}.each do |verb|
|
35
|
-
assert_equal [MyCtrl, :thing, {}],
|
35
|
+
assert_equal [[MyCtrl, :thing], {}],
|
36
36
|
@router.resources_for(verb, "/my_ctrl/thing")
|
37
37
|
end
|
38
38
|
end
|
@@ -43,7 +43,7 @@ class RouterTest < Test::Unit::TestCase
|
|
43
43
|
get :bar, "/bar/:id"
|
44
44
|
end
|
45
45
|
|
46
|
-
assert_equal [MyCtrl, :bar, {'id' => '123 456'}],
|
46
|
+
assert_equal [[MyCtrl, :bar], {'id' => '123 456'}],
|
47
47
|
@router.resources_for("GET", "/my_ctrl/bar/123+456")
|
48
48
|
end
|
49
49
|
|
@@ -53,7 +53,7 @@ class RouterTest < Test::Unit::TestCase
|
|
53
53
|
get :bar, "/bar/:type/:id.:format"
|
54
54
|
end
|
55
55
|
|
56
|
-
assert_equal [MyCtrl, :bar, {"type"=>"[I]", "id"=>"123 456", "format"=>"json"}],
|
56
|
+
assert_equal [[MyCtrl, :bar], {"type"=>"[I]", "id"=>"123 456", "format"=>"json"}],
|
57
57
|
@router.resources_for("GET", "/my_ctrl/bar/%5BI%5D/123+456.json")
|
58
58
|
end
|
59
59
|
|
@@ -65,11 +65,11 @@ class RouterTest < Test::Unit::TestCase
|
|
65
65
|
post :create
|
66
66
|
end
|
67
67
|
|
68
|
-
assert_equal [FooController, :bar, {}],
|
68
|
+
assert_equal [[FooController, :bar], {}],
|
69
69
|
@router.resources_for("GET", "/foo/bar")
|
70
70
|
|
71
71
|
assert_equal "/foo/bar", @router.path_to(:my_bar)
|
72
|
-
assert_equal "/foo
|
72
|
+
assert_equal "/foo", @router.path_to(:create_foo)
|
73
73
|
assert_equal "/foo", @router.path_to(:all_foo)
|
74
74
|
end
|
75
75
|
|
@@ -82,10 +82,10 @@ class RouterTest < Test::Unit::TestCase
|
|
82
82
|
|
83
83
|
assert_nil @router.resources_for("post", "/my_ctrl")
|
84
84
|
|
85
|
-
assert_equal [MyCtrl, :bar, {'str' => 'item'}],
|
85
|
+
assert_equal [[MyCtrl, :bar], {'str' => 'item'}],
|
86
86
|
@router.resources_for("GET", "/my_ctrl/item/bar")
|
87
87
|
|
88
|
-
assert_equal [MyCtrl, :foo, {'str' => 'item'}],
|
88
|
+
assert_equal [[MyCtrl, :foo], {'str' => 'item'}],
|
89
89
|
@router.resources_for("post", "/my_ctrl/item")
|
90
90
|
end
|
91
91
|
|
@@ -96,17 +96,121 @@ class RouterTest < Test::Unit::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
expected_params = {'type' => 'sub', 'id' => '123', 'format' => 'json'}
|
99
|
-
assert_equal [MyCtrl, :bar, expected_params],
|
99
|
+
assert_equal [[MyCtrl, :bar], expected_params],
|
100
100
|
@router.resources_for("GET", "/bar/sub/123.json")
|
101
101
|
end
|
102
102
|
|
103
103
|
|
104
|
+
def test_add_and_retrieve_lambda
|
105
|
+
ctrl = lambda{ "foo" }
|
106
|
+
@router.add ctrl, "/foo"
|
107
|
+
|
108
|
+
assert_equal [[ctrl, :call],{}], @router.resources_for("GET", "/foo")
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def test_add_and_retrieve_lambda_block
|
113
|
+
ctrl = lambda{ "foo" }
|
114
|
+
@router.add ctrl, "/foo" do
|
115
|
+
get :thing, "/thing"
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal [[ctrl, :thing],{}], @router.resources_for("GET", "/foo/thing")
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def test_add_lambda_no_path
|
123
|
+
ctrl = lambda{ "foo" }
|
124
|
+
|
125
|
+
assert_raises ArgumentError do
|
126
|
+
@router.add ctrl
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def test_add_lambda_defaults
|
132
|
+
ctrl = lambda{ "foo" }
|
133
|
+
|
134
|
+
assert_raises TypeError do
|
135
|
+
@router.add ctrl, "/foo" do
|
136
|
+
get :thing, "/thing"
|
137
|
+
defaults
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
class MockCustomMount
|
144
|
+
def self.call env
|
145
|
+
[200, {}, ["OK"]]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_add_and_retrieve_custom_mount
|
150
|
+
@router.add MockCustomMount
|
151
|
+
|
152
|
+
assert_equal [[MockCustomMount, :call],{}],
|
153
|
+
@router.resources_for("GET", "/router_test/mock_custom_mount")
|
154
|
+
|
155
|
+
assert_equal [MockCustomMount, :call],
|
156
|
+
@router.route_to(MockCustomMount, :call).target
|
157
|
+
|
158
|
+
assert_equal [MockCustomMount, :call],
|
159
|
+
@router.route_to(:call_mock_custom_mount).target
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def test_add_and_retrieve_custom_mount_block
|
164
|
+
@router.add MockCustomMount do
|
165
|
+
post :foo
|
166
|
+
get [:foo, 1, 2], "/ary"
|
167
|
+
end
|
168
|
+
|
169
|
+
assert_equal [[MockCustomMount, :foo],{}],
|
170
|
+
@router.resources_for("POST", "/router_test/mock_custom_mount/foo")
|
171
|
+
|
172
|
+
assert_equal [[MockCustomMount, [:foo, 1, 2]],{}],
|
173
|
+
@router.resources_for("GET", "/router_test/mock_custom_mount/ary")
|
174
|
+
|
175
|
+
assert_equal [MockCustomMount, :foo],
|
176
|
+
@router.route_to(:foo_mock_custom_mount).target
|
177
|
+
|
178
|
+
assert_nil @router.route_to(MockCustomMount, [:foo, 1, 2]).name
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_add_custom_mount_action
|
183
|
+
assert_raises ArgumentError do
|
184
|
+
@router.add MockCustomMount do
|
185
|
+
post [:foo, 1, 2]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
def test_add_custom_mount_defaults
|
192
|
+
assert_raises TypeError do
|
193
|
+
@router.add MockCustomMount, "/foo" do
|
194
|
+
get :thing, "/thing"
|
195
|
+
defaults
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def test_add_and_retrieve_custom_mount_invalid
|
202
|
+
assert_raises ArgumentError do
|
203
|
+
@router.add TypeError
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
104
208
|
def test_add_omit_base_path
|
105
209
|
@router.add MyCtrl do
|
106
210
|
get :bar
|
107
211
|
end
|
108
212
|
|
109
|
-
assert_equal [MyCtrl, :bar, {}],
|
213
|
+
assert_equal [[MyCtrl, :bar], {}],
|
110
214
|
@router.resources_for("GET", "/my_ctrl/bar")
|
111
215
|
end
|
112
216
|
|
@@ -116,7 +220,7 @@ class RouterTest < Test::Unit::TestCase
|
|
116
220
|
get :index, '/'
|
117
221
|
end
|
118
222
|
|
119
|
-
assert_equal [FooController, :index, {}],
|
223
|
+
assert_equal [[FooController, :index], {}],
|
120
224
|
@router.resources_for("GET", "/foo")
|
121
225
|
end
|
122
226
|
|
@@ -126,7 +230,7 @@ class RouterTest < Test::Unit::TestCase
|
|
126
230
|
get :bar, "/"
|
127
231
|
end
|
128
232
|
|
129
|
-
assert_equal [MyCtrl, :bar, {}],
|
233
|
+
assert_equal [[MyCtrl, :bar], {}],
|
130
234
|
@router.resources_for("GET", "/")
|
131
235
|
|
132
236
|
assert !@router.has_route?(MyCtrl, :show)
|
@@ -155,33 +259,16 @@ class RouterTest < Test::Unit::TestCase
|
|
155
259
|
end
|
156
260
|
|
157
261
|
|
158
|
-
def test_add_all_with_default_verb
|
159
|
-
@router.add MyCtrl, "/" do
|
160
|
-
get :show, "/:id"
|
161
|
-
defaults :post
|
162
|
-
end
|
163
|
-
|
164
|
-
assert_equal [MyCtrl, :index, {}],
|
165
|
-
@router.resources_for("GET", "/")
|
166
|
-
|
167
|
-
assert_equal [MyCtrl, :show, {'id' => '123'}],
|
168
|
-
@router.resources_for("GET", "/123")
|
169
|
-
|
170
|
-
assert_equal [MyCtrl, :unmounted_action, {}],
|
171
|
-
@router.resources_for("POST", "/unmounted_action")
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
262
|
def test_add_all
|
176
263
|
@router.add MyCtrl, "/"
|
177
264
|
|
178
|
-
assert_equal [MyCtrl, :index, {}],
|
265
|
+
assert_equal [[MyCtrl, :index], {}],
|
179
266
|
@router.resources_for("GET", "/")
|
180
267
|
|
181
|
-
assert_equal [MyCtrl, :show, {'id' => '123'}],
|
268
|
+
assert_equal [[MyCtrl, :show], {'id' => '123'}],
|
182
269
|
@router.resources_for("GET", "/123")
|
183
270
|
|
184
|
-
assert_equal [MyCtrl, :unmounted_action, {}],
|
271
|
+
assert_equal [[MyCtrl, :unmounted_action], {}],
|
185
272
|
@router.resources_for("GET", "/unmounted_action")
|
186
273
|
end
|
187
274
|
|
@@ -212,7 +299,7 @@ class RouterTest < Test::Unit::TestCase
|
|
212
299
|
get :bar, "/bar"
|
213
300
|
end
|
214
301
|
|
215
|
-
assert_raises Gin::
|
302
|
+
assert_raises Gin::RouterError do
|
216
303
|
@router.path_to(MyCtrl, :foo)
|
217
304
|
end
|
218
305
|
end
|
@@ -271,4 +358,39 @@ class RouterTest < Test::Unit::TestCase
|
|
271
358
|
assert_equal "/bar/sub%2Fthing/123%264.json?more=hi+there",
|
272
359
|
@router.path_to(MyCtrl, :bar, params)
|
273
360
|
end
|
361
|
+
|
362
|
+
|
363
|
+
def test_route_to
|
364
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
365
|
+
get :show, "/:id"
|
366
|
+
end
|
367
|
+
|
368
|
+
route = @router.route_to(MyCtrl, :show)
|
369
|
+
assert_equal [MyCtrl, :show], route.target
|
370
|
+
assert_equal '/my_ctrl/123', route.to_path(:id => 123)
|
371
|
+
|
372
|
+
named_route = @router.route_to(:show_my_ctrl)
|
373
|
+
assert_equal route, named_route
|
374
|
+
end
|
375
|
+
|
376
|
+
|
377
|
+
def test_route_to_env
|
378
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
379
|
+
post :update, "/:id"
|
380
|
+
end
|
381
|
+
|
382
|
+
route = @router.route_to(MyCtrl, :update)
|
383
|
+
expected_env = {'rack.input' => '', 'PATH_INFO' => '/my_ctrl/123',
|
384
|
+
'REQUEST_METHOD' => 'POST', 'QUERY_STRING' => 'blah=456'}
|
385
|
+
|
386
|
+
assert_equal expected_env, route.to_env(:id => 123, :blah => 456)
|
387
|
+
|
388
|
+
assert_raises Gin::Router::PathArgumentError do
|
389
|
+
route.to_env(:blah => 456)
|
390
|
+
end
|
391
|
+
|
392
|
+
expected_env['rack.input'] = 'foo=bar'
|
393
|
+
assert_equal expected_env,
|
394
|
+
route.to_env({:id => 123, :blah => 456}, {'rack.input' => 'foo=bar'})
|
395
|
+
end
|
274
396
|
end
|
data/test/test_test.rb
CHANGED
@@ -53,32 +53,37 @@ class TestTest < Test::Unit::TestCase
|
|
53
53
|
|
54
54
|
def test_path_to
|
55
55
|
assert_nil @tests.default_controller
|
56
|
-
assert_equal "/bar/123", @tests.path_to(:show_bar, id
|
57
|
-
assert_equal "/bar/123", @tests.path_to(MockApp::BarController, :show, id
|
58
|
-
assert_equal "/bar?id=123", @tests.path_to("/bar", id
|
56
|
+
assert_equal "/bar/123", @tests.path_to(:show_bar, :id => 123)
|
57
|
+
assert_equal "/bar/123", @tests.path_to(MockApp::BarController, :show, :id => 123)
|
58
|
+
assert_equal "/bar?id=123", @tests.path_to("/bar", :id => 123)
|
59
59
|
end
|
60
60
|
|
61
61
|
|
62
62
|
def test_path_to_default_ctrl
|
63
63
|
@tests.default_controller MockApp::BarController
|
64
|
-
assert_equal "/bar/123", @tests.path_to(:show_bar, id
|
65
|
-
assert_equal "/bar/123", @tests.path_to(:show, id
|
64
|
+
assert_equal "/bar/123", @tests.path_to(:show_bar, :id => 123)
|
65
|
+
assert_equal "/bar/123", @tests.path_to(:show, :id => 123)
|
66
66
|
end
|
67
67
|
|
68
68
|
|
69
69
|
def test_path_to_no_ctrl
|
70
70
|
assert_nil @tests.default_controller
|
71
|
-
assert_raises(Gin::
|
72
|
-
@tests.path_to(:show, id
|
71
|
+
assert_raises(Gin::RouterError) do
|
72
|
+
@tests.path_to(:show, :id => 123)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
|
77
77
|
def test_make_request
|
78
|
+
@tests.app.options[:host] = {:name => 'example.com:443'}
|
78
79
|
resp = @tests.make_request :get, :show_bar,
|
79
|
-
{id
|
80
|
+
{:id => 123, :foo => "BAR", :bar => "BAZ Foo"},'REMOTE_ADDR' => '127.0.0.1'
|
80
81
|
|
81
|
-
assert_equal "
|
82
|
+
assert_equal "example.com", @tests.req_env['SERVER_NAME']
|
83
|
+
assert_equal "443", @tests.req_env['SERVER_PORT']
|
84
|
+
assert_equal "example.com:443", resp[1]['Host']
|
85
|
+
|
86
|
+
assert_equal %w{bar=BAZ+Foo foo=BAR}, @tests.req_env['QUERY_STRING'].split('&').sort
|
82
87
|
assert_equal "/bar/123", @tests.req_env['PATH_INFO']
|
83
88
|
assert_equal "127.0.0.1", @tests.req_env['REMOTE_ADDR']
|
84
89
|
assert_equal "127.0.0.1", @tests.request.ip
|
@@ -119,12 +124,13 @@ class TestTest < Test::Unit::TestCase
|
|
119
124
|
resp[1]["Set-Cookie"]
|
120
125
|
|
121
126
|
time = Time.parse "2100-01-01 00:00:00 UTC"
|
122
|
-
cookie = {name
|
127
|
+
cookie = {:name => "foo_session", :value => "12345", :expires_at => time}
|
123
128
|
assert_equal cookie, @tests.cookies["foo_session"]
|
124
129
|
|
125
130
|
@tests.set_cookie "bar", 5678
|
126
|
-
resp = @tests.make_request :get, :show_bar, id
|
127
|
-
assert_equal
|
131
|
+
resp = @tests.make_request :get, :show_bar, :id => 123
|
132
|
+
assert_equal %w{bar=5678 foo_session=12345},
|
133
|
+
@tests.req_env['HTTP_COOKIE'].split('; ').sort
|
128
134
|
end
|
129
135
|
|
130
136
|
|
@@ -136,18 +142,18 @@ class TestTest < Test::Unit::TestCase
|
|
136
142
|
|
137
143
|
time = Time.parse "2100-01-01 00:00:00 UTC"
|
138
144
|
|
139
|
-
expected = {name
|
145
|
+
expected = {:name => "foo_session", :value => "12345", :expires_at => time}
|
140
146
|
assert_equal expected, @tests.cookies['foo_session']
|
141
147
|
|
142
|
-
expected = {name
|
143
|
-
path
|
148
|
+
expected = {:name => "supercookie", :value => "SUPER!", :domain => "mockapp.com",
|
149
|
+
:path => "/", :expires_at => time, :secure => true, :http_only => true}
|
144
150
|
assert_equal expected, @tests.cookies['supercookie']
|
145
151
|
end
|
146
152
|
|
147
153
|
|
148
154
|
def test_make_request_verb_methods
|
149
155
|
%w{get post put patch delete head options}.each do |verb|
|
150
|
-
resp = @tests.send verb, :show_bar, id
|
156
|
+
resp = @tests.send verb, :show_bar, :id => 123
|
151
157
|
assert_equal verb.upcase, @tests.req_env['REQUEST_METHOD']
|
152
158
|
if verb == 'get'
|
153
159
|
assert_equal MockApp::BarController,
|
@@ -326,50 +332,50 @@ class TestTest < Test::Unit::TestCase
|
|
326
332
|
def test_assert_data_json
|
327
333
|
@tests.rack_response[1]['Content-Type'] = 'application/json'
|
328
334
|
@tests.rack_response[2] =
|
329
|
-
[{name
|
335
|
+
[{:name =>"bob",:addresses =>[{:street =>"123 bob st"},{:street =>"321 foo st"}]}.to_json]
|
330
336
|
|
331
337
|
assert @tests.assert_data("name=bob")
|
332
|
-
assert @tests.assert_data("name", value
|
333
|
-
assert @tests.assert_data("addresses/*/street", count
|
338
|
+
assert @tests.assert_data("name", :value => "bob", :count => 1)
|
339
|
+
assert @tests.assert_data("addresses/*/street", :count => 2)
|
334
340
|
end
|
335
341
|
|
336
342
|
|
337
343
|
def test_assert_data_bson
|
338
344
|
@tests.rack_response[1]['Content-Type'] = 'application/bson'
|
339
345
|
@tests.rack_response[2] =
|
340
|
-
[BSON.serialize({name
|
346
|
+
[BSON.serialize({:name =>"bob",:addresses =>[{:street =>"123 bob st"},{:street =>"321 foo st"}]}).to_s]
|
341
347
|
|
342
348
|
assert @tests.assert_data("name=bob")
|
343
|
-
assert @tests.assert_data("name", value
|
344
|
-
assert @tests.assert_data("addresses/*/street", count
|
349
|
+
assert @tests.assert_data("name", :value => "bob", :count => 1)
|
350
|
+
assert @tests.assert_data("addresses/*/street", :count => 2)
|
345
351
|
end
|
346
352
|
|
347
353
|
|
348
354
|
def test_assert_data_plist
|
349
355
|
@tests.rack_response[1]['Content-Type'] = 'application/plist'
|
350
356
|
@tests.rack_response[2] =
|
351
|
-
[{name
|
357
|
+
[{:name =>"bob",:addresses =>[{:street =>"123 bob st"},{:street =>"321 foo st"}]}.to_plist]
|
352
358
|
|
353
359
|
assert @tests.assert_data("name=bob")
|
354
|
-
assert @tests.assert_data("name", value
|
355
|
-
assert @tests.assert_data("addresses/*/street", count
|
360
|
+
assert @tests.assert_data("name", :value => "bob", :count => 1)
|
361
|
+
assert @tests.assert_data("addresses/*/street", :count => 2)
|
356
362
|
end
|
357
363
|
|
358
364
|
|
359
365
|
def test_assert_xpath
|
360
|
-
data = Nokogiri::XML::Builder.new do
|
361
|
-
root{
|
362
|
-
name "bob"
|
363
|
-
address{ street "123 bob st" }
|
364
|
-
address{ street "321 foo st" }
|
366
|
+
data = Nokogiri::XML::Builder.new do |xml|
|
367
|
+
xml.root{
|
368
|
+
xml.name "bob"
|
369
|
+
xml.address{ xml.street "123 bob st" }
|
370
|
+
xml.address{ xml.street "321 foo st" }
|
365
371
|
}
|
366
372
|
end.to_xml
|
367
373
|
|
368
374
|
@tests.rack_response[1]['Content-Type'] = 'application/xml'
|
369
375
|
@tests.rack_response[2] = [data]
|
370
376
|
|
371
|
-
assert @tests.assert_xpath("/root/name", value
|
372
|
-
assert @tests.assert_xpath(".//street", count
|
377
|
+
assert @tests.assert_xpath("/root/name", :value => "bob", :count => 1)
|
378
|
+
assert @tests.assert_xpath(".//street", :count => 2)
|
373
379
|
end
|
374
380
|
|
375
381
|
|
@@ -388,8 +394,8 @@ class TestTest < Test::Unit::TestCase
|
|
388
394
|
@tests.rack_response[1]['Content-Type'] = 'application/html'
|
389
395
|
@tests.rack_response[2] = [html]
|
390
396
|
|
391
|
-
assert @tests.assert_css(".name", value
|
392
|
-
assert @tests.assert_css(".address>.street", count
|
397
|
+
assert @tests.assert_css(".name", :value => "bob", :count => 1)
|
398
|
+
assert @tests.assert_css(".address>.street", :count => 2)
|
393
399
|
end
|
394
400
|
|
395
401
|
|
@@ -397,7 +403,7 @@ class TestTest < Test::Unit::TestCase
|
|
397
403
|
@tests.rack_response[1]['Content-Type'] = 'application/json'
|
398
404
|
@tests.rack_response[2] = ['{"foo":123}']
|
399
405
|
assert_raises(RuntimeError) do
|
400
|
-
@tests.assert_select(".name", selector
|
406
|
+
@tests.assert_select(".name", :selector => :foo)
|
401
407
|
end
|
402
408
|
end
|
403
409
|
|
@@ -413,13 +419,13 @@ class TestTest < Test::Unit::TestCase
|
|
413
419
|
@tests.last_message
|
414
420
|
|
415
421
|
assert_raises(MockAssertionError) do
|
416
|
-
@tests.assert_select "/foo", count
|
422
|
+
@tests.assert_select "/foo", :count => 2
|
417
423
|
end
|
418
424
|
assert_equal "Expected 2 items matching '/foo' but found 1",
|
419
425
|
@tests.last_message
|
420
426
|
|
421
427
|
assert_raises(MockAssertionError) do
|
422
|
-
@tests.assert_select "/foo", value
|
428
|
+
@tests.assert_select "/foo", :value => 321
|
423
429
|
end
|
424
430
|
|
425
431
|
assert_equal "Expected at least one item matching '/foo' with value 321 but found none",
|
@@ -431,11 +437,11 @@ class TestTest < Test::Unit::TestCase
|
|
431
437
|
@tests.get :supercookie_foo
|
432
438
|
|
433
439
|
assert @tests.assert_cookie("supercookie")
|
434
|
-
assert @tests.assert_cookie("supercookie", value
|
435
|
-
assert @tests.assert_cookie("supercookie", domain
|
440
|
+
assert @tests.assert_cookie("supercookie", :value => "SUPER!")
|
441
|
+
assert @tests.assert_cookie("supercookie", :domain => "mockapp.com")
|
436
442
|
|
437
|
-
attribs = {domain
|
438
|
-
http_only
|
443
|
+
attribs = {:domain => "mockapp.com", :value => "SUPER!", :path => "/", :secure => true,
|
444
|
+
:http_only => true, :expires_at => Time.parse("Fri, 01 Jan 2100 00:00:00 -0000")}
|
439
445
|
assert @tests.assert_cookie("supercookie", attribs)
|
440
446
|
end
|
441
447
|
|
@@ -469,7 +475,7 @@ class TestTest < Test::Unit::TestCase
|
|
469
475
|
@tests.get :supercookie_foo
|
470
476
|
|
471
477
|
assert_raises(MockAssertionError) do
|
472
|
-
@tests.assert_cookie "supercookie", value
|
478
|
+
@tests.assert_cookie "supercookie", :value => "BLAH"
|
473
479
|
end
|
474
480
|
assert_equal "Expected cookie value to be \"BLAH\" but was \"SUPER!\"",
|
475
481
|
@tests.last_message
|
@@ -586,9 +592,9 @@ got MockApp::FooController#index", @tests.last_message
|
|
586
592
|
Assertion = MockAssertionError unless const_defined?(:Assertion)
|
587
593
|
end
|
588
594
|
|
589
|
-
def raise
|
590
|
-
|
591
|
-
|
595
|
+
def raise *args
|
596
|
+
@last_message = String === args.last && args.last ||
|
597
|
+
args.last.respond_to?(:message) && args.last.message
|
592
598
|
super
|
593
599
|
end
|
594
600
|
end
|