Skip to content

Instantly share code, notes, and snippets.

@simi
Created February 22, 2012 17:08
Show Gist options
  • Select an option

  • Save simi/1886111 to your computer and use it in GitHub Desktop.

Select an option

Save simi/1886111 to your computer and use it in GitHub Desktop.
Test API
require 'spec_helper'
require 'rack/test'
describe Api::Server do
include Rack::Test::Methods
def app
::Jimson::Server.new(::Api::Server.new)
end
def post_json(hash)
post '/', hash.to_json, {'Content-Type' => 'application/json'}
end
before(:each) do
@url = "http://localhost:8999"
end
describe "registerUser" do
before(:each) do
@req = {"jsonrpc" => "2.0",
"method" => "registerUser",
"params" => {"user" => {"email" => '[email protected]', "password" => "ryba123"}},
"id" => 1}
end
it "returns user json with access token" do
post_json(@req)
last_response.should be_ok
resp = JSON.parse(last_response.body)
resp["result"]["access_token"].should be
end
it "returns ERRUserAlreadyExists with -32500 code" do
post_json(@req)
post_json(@req)
last_response.should be_ok
resp = JSON.parse(last_response.body)
resp["error"]["code"].should == -32500
resp["error"]["message"].should == "ERRUserAlreadyExists"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment