-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpath_params_spec.rb
50 lines (41 loc) · 1.51 KB
/
path_params_spec.rb
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
require 'spec_helper'
require 'goliath/contrib/path_params'
describe Goliath::Contrib::PathParams do
it 'accepts an app and a url pattern' do
lambda { Goliath::Contrib::PathParams.new('my app', 'url') }.should_not raise_error
end
describe 'with middleware' do
before(:each) do
@app = mock('app').as_null_object
@env = { 'REQUEST_PATH' => '/records/the_fall/hex_enduction_hour' }
@path_params = Goliath::Contrib::PathParams.new(@app, '/records/:artist/:title')
end
it 'returns the app status, headers and body' do
app_headers = {'Content-Type' => 'app'}
app_body = {'b' => 'c'}
@app.should_receive(:call).and_return([201, app_headers, app_body])
status, headers, body = @path_params.call(@env)
status.should == 201
headers.should == app_headers
body.should == app_body
end
context 'a request that matches the url pattern' do
before do
@env = { 'REQUEST_PATH' => '/records/sparks/angst_in_my_pants' }
end
it 'parses the params from the path' do
@path_params.call(@env)
@env['params']['artist'].should == 'sparks'
@env['params']['title'].should == 'angst_in_my_pants'
end
end
context 'a request that does not match the url pattern' do
before do
@env = { 'REQUEST_PATH' => '/animals/cat/noah' }
end
it 'raises a BadRequestError' do
expect{ @path_params.retrieve_params(@env) }.to raise_error(Goliath::Validation::BadRequestError)
end
end
end
end