forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_spec.rb
More file actions
62 lines (54 loc) · 1.64 KB
/
Copy pathecho_spec.rb
File metadata and controls
62 lines (54 loc) · 1.64 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
require 'spec_helper'
require File.join(File.dirname(__FILE__), '../../', 'examples/echo')
require 'multipart_body'
require 'yajl'
describe Echo do
let(:err) { Proc.new { fail "API request failed" } }
it 'returns the echo param' do
with_api(Echo) do
get_request({:query => {:echo => 'test'}}, err) do |c|
b = Yajl::Parser.parse(c.response)
b['response'].should == 'test'
end
end
end
it 'returns error without echo' do
with_api(Echo) do
get_request({}, err) do |c|
b = Yajl::Parser.parse(c.response)
b['error'].should_not be_nil
b['error'].should == 'Echo identifier missing'
end
end
end
it 'echos POST data' do
with_api(Echo) do
post_request({:body => {'echo' => 'test'}}, err) do |c|
b = Yajl::Parser.parse(c.response)
b['response'].should == 'test'
end
end
end
it 'echos POST data that is multipart encoded' do
with_api(Echo) do
body = MultipartBody.new(:echo => 'test')
head = {'content-type' => "multipart/form-data; boundary=#{body.boundary}"}
post_request({:body => body.to_s,
:head => head}, err) do |c|
b = Yajl::Parser.parse(c.response)
b['response'].should == 'test'
end
end
end
it 'echos application/json POST body data' do
with_api(Echo) do
body = Yajl::Encoder.encode({'echo' => 'My Echo'})
head = {'content-type' => 'application/json'}
post_request({:body => body.to_s,
:head => head}, err) do |c|
b = Yajl::Parser.parse(c.response)
b['response'].should == 'My Echo'
end
end
end
end