Skip to content

Instantly share code, notes, and snippets.

@jakeonrails
Created August 13, 2013 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeonrails/6217628 to your computer and use it in GitHub Desktop.
Save jakeonrails/6217628 to your computer and use it in GitHub Desktop.
JSON API test DSL
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