55describe RackRoutes do
66let ( :err ) { Proc . new { fail "API request failed" } }
77
8- it 'routes to the correct API' do
9- with_api ( RackRoutes ) do
10- get_request ( { :path => '/bonjour' } , err ) do |c |
11- c . response_header . status . should == 200
12- c . response . should == 'bonjour!'
8+ context "when using maps" do
9+
10+ it "ignores #response" do
11+ expect {
12+ with_api ( RackRoutes ) do
13+ get_request ( { :path => '/' } , err ) { }
14+ end
15+ } . to_not raise_error
16+ end
17+
18+ it 'fallback not found to /' do
19+ with_api ( RackRoutes ) do
20+ get_request ( { :path => '/donkey' } , err ) do |cb |
21+ cb . response_header . status . should == 404
22+ cb . response . should == 'Try /version /hello_world, /bonjour, or /hola'
23+ end
1324end
1425end
15- end
1626
17- it 'routes to the default' do
18- with_api ( RackRoutes ) do
19- get_request ( { :path => '/donkey' } , err ) do |c |
20- c . response_header . status . should == 404
21- c . response . should == 'Try /version /hello_world, /bonjour, or /hola'
27+ it 'routes to the correct API' do
28+ with_api ( RackRoutes ) do
29+ get_request ( { :path => '/bonjour' } , err ) do |c |
30+ c . response_header . status . should == 200
31+ c . response . should == 'bonjour!'
32+ end
2233end
2334end
24- end
2535
26- it 'uses API middleware' do
27- with_api ( RackRoutes ) do
28- post_request ( { :path => '/hola' } , err ) do |c |
29- # the /hola route only supports GET requests
30- c . response_header . status . should == 400
31- c . response . should == '[:error, "Invalid request method"]'
36+ context "defined in blocks" do
37+ it 'uses middleware defined in the block' do
38+ with_api ( RackRoutes ) do
39+ post_request ( { :path => '/hola' } , err ) do |c |
40+ # the /hola route only supports GET requests
41+ c . response_header . status . should == 400
42+ c . response . should == '[:error, "Invalid request method"]'
43+ end
44+ end
45+ end
46+
47+ it "doesn't use middleware defined in the API" do
48+ with_api ( RackRoutes ) do
49+ get_request ( { :path => '/hola' } , err ) do |cb |
50+ # it doesn't raise required param error
51+ cb . response_header . status . should == 200
52+ cb . response . should == "hola!"
53+ end
54+ end
3255end
3356end
34- end
3557
36- it 'uses API middleware' do
37- with_api ( RackRoutes ) do
38- post_request ( { :path => '/aloha' } , err ) do |c |
39- # the /hola route only supports GET requests
40- c . response_header . status . should == 400
41- c . response . should == '[:error, "Invalid request method"]'
58+ context "defined in classes" do
59+ it 'uses API middleware' do
60+ with_api ( RackRoutes ) do
61+ post_request ( { :path => '/aloha' } , err ) do |c |
62+ # the /hola route only supports GET requests
63+ c . response_header . status . should == 400
64+ c . response . should == '[:error, "Invalid request method"]'
65+ end
66+ end
4267end
4368end
69+
4470end
45- end
71+ end
0 commit comments