forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrack_routes_spec.rb
More file actions
91 lines (80 loc) · 2.63 KB
/
Copy pathrack_routes_spec.rb
File metadata and controls
91 lines (80 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# encoding: utf-8
require 'spec_helper'
require File.join(File.dirname(__FILE__), '../../', 'examples/rack_routes')
describe RackRoutes do
let(:err) { Proc.new { fail "API request failed" } }
context "when using maps" do
it "ignores #response" do
expect {
with_api(RackRoutes) do
get_request({:path => '/'}, err) {}
end
}.to_not raise_error
end
it 'fallback not found to /' do
with_api(RackRoutes) do
get_request({:path => '/donkey'}, err) do |cb|
cb.response_header.status.should == 404
cb.response.should == 'Try /version /hello_world, /bonjour, or /hola'
end
end
end
it 'routes to the correct API' do
with_api(RackRoutes) do
get_request({:path => '/bonjour'}, err) do |c|
c.response_header.status.should == 200
c.response.should == 'bonjour!'
end
end
end
it 'routes to the correct API using regex filters' do
with_api(RackRoutes) do
get_request({:path => '/123123'}, err) do |c|
c.response_header.status.should == 200
c.response.should == 'number 123123!'
end
end
end
it 'should allow sinatra style route definition' do
with_api(RackRoutes) do
post_request({:path => '/hello_world'}, err) do |c|
c.response_header.status.should == 200
c.response.should == 'hello post world!'
end
end
end
context "defined in blocks" do
it 'uses middleware defined in the block' do
with_api(RackRoutes) do
post_request({:path => '/hola'}, err) do |c|
# the /hola route only supports GET requests
c.response_header.status.should == 405
c.response.should == '[:error, "Invalid request method"]'
c.response_header['ALLOW'].should == 'GET'
end
end
end
it "doesn't use middleware defined in the API" do
with_api(RackRoutes) do
get_request({:path => '/hola'}, err) do |cb|
# it doesn't raise required param error
cb.response_header.status.should == 200
cb.response.should == "hola!"
end
end
end
end
context "defined in classes" do
it 'uses API middleware' do
with_api(RackRoutes) do
post_request({:path => '/aloha'}, err) do |c|
# the /hola route only supports GET requests
c.response_header.status.should == 405
c.response.should == '[:error, "Invalid request method"]'
c.response_header['ALLOW'].should == 'GET'
end
end
end
end
end
end