forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid_spec.rb
More file actions
43 lines (36 loc) · 1.03 KB
/
Copy pathvalid_spec.rb
File metadata and controls
43 lines (36 loc) · 1.03 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
require 'spec_helper'
require 'json'
require File.join(File.dirname(__FILE__), '../../', 'examples/valid')
describe Valid do
let(:err) { Proc.new { fail "API request failed" } }
it 'returns OK with param' do
with_api(Valid) do
get_request({:query => {:test => 'test'}}, err) do |c|
c.response.should == 'OK'
end
end
end
it 'returns error without param' do
with_api(Valid) do
get_request({}, err) do |c|
c.response.should == '[:error, "Test identifier missing"]'
end
end
end
end
class ValidationErrorInEndpoint < Goliath::API
def response(env)
raise Goliath::Validation::Error.new(420, 'You Must Chill')
end
end
describe ValidationErrorInEndpoint do
let(:err) { Proc.new { fail "API request failed" } }
it 'handles Goliath::Validation::Error correctly' do
with_api(ValidationErrorInEndpoint) do
get_request({}, err) do |c|
c.response.should == '[:error, "You Must Chill"]'
c.response_header.status.should == 420
end
end
end
end