Created
August 13, 2013 03:24
-
-
Save jakeonrails/6217628 to your computer and use it in GitHub Desktop.
JSON API test DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'POST api/v1/sessions' do | |
def self.request(options) | |
let(:api_response) { | |
send( | |
options[:method].downcase, | |
options[:path], | |
options[:json], | |
) | |
last_response | |
} | |
end | |
def self.response(options) | |
it "should have status #{options[:status]}" do | |
expect(api_response.status).to eq options[:status] | |
end | |
it "should respond with #{options[:json]}" do | |
expect(JSON.parse(api_response.body)).to eq options[:json] | |
end | |
end | |
context "with bad location_id" do | |
before do | |
any_instance_of(FacebookProfileCreator) do |fpc| | |
stub(fpc).create_or_update | |
end | |
end | |
request({ | |
method: "POST", | |
path: "api/v1/sessions", | |
json: | |
{ | |
facebook_token: 'valid token', | |
location_id: 'bad location id', | |
}, | |
}) | |
response({ | |
status: 200, | |
json: | |
{ | |
"code" => 10060, | |
"error" => "Bad Location", | |
}, | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment