Make petstore tests pass

This commit is contained in:
xhh 2015-04-19 00:42:55 +08:00
parent 8dd7d3aacd
commit 194e9e6f05
6 changed files with 59 additions and 59 deletions

View File

@ -37,8 +37,8 @@ describe "Pet" do
end
it "should fetch a pet object" do
pet = PetApi.get_pet_by_id(10002)
pet.should be_a(Pet)
pet = SwaggerClient::PetApi.get_pet_by_id(10002)
pet.should be_a(SwaggerClient::Pet)
pet.id.should == 10002
pet.name.should == "RUBY UNIT TESTING"
pet.tags[0].name.should == "tag test"
@ -46,17 +46,17 @@ describe "Pet" do
end
it "should find pets by status" do
pets = PetApi.find_pets_by_status(:status => 'available')
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'available')
pets.length.should >= 3
end
it "should not find a pet with invalid status" do
pets = PetApi.find_pets_by_status(:status => 'invalid-status')
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'invalid-status')
pets.length.should == 0
end
it "should find a pet by status" do
pets = PetApi.find_pets_by_status(:status => "available,sold")
pets = SwaggerClient::PetApi.find_pets_by_status(:status => "available,sold")
pets.map {|pet|
if(pet.status != 'available' && pet.status != 'sold')
raise "pet status wasn't right"
@ -65,19 +65,19 @@ describe "Pet" do
end
it "should update a pet" do
pet = Pet.new({'id' => 10002, 'status' => 'sold'})
PetApi.add_pet(:body => pet)
pet = SwaggerClient::Pet.new({'id' => 10002, 'status' => 'sold'})
SwaggerClient::PetApi.add_pet(:body => pet)
fetched = PetApi.get_pet_by_id(10002)
fetched = SwaggerClient::PetApi.get_pet_by_id(10002)
fetched.id.should == 10002
fetched.status.should == 'sold'
end
it "should create a pet" do
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
PetApi.add_pet(:body => pet)
pet = SwaggerClient::Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
SwaggerClient::PetApi.add_pet(:body => pet)
pet = PetApi.get_pet_by_id(10002)
pet = SwaggerClient::PetApi.get_pet_by_id(10002)
pet.id.should == 10002
pet.name.should == "RUBY UNIT TESTING"
end

View File

@ -1,9 +1,9 @@
require 'spec_helper'
describe Swagger::Request do
describe SwaggerClient::Swagger::Request do
before(:each) do
Swagger.configure do |config|
SwaggerClient::Swagger.configure do |config|
inject_format = true
config.api_key = 'special-key'
config.host = 'petstore.swagger.io'
@ -15,7 +15,7 @@ describe Swagger::Request do
@default_params = {
:params => {:foo => "1", :bar => "2"}
}
@request = Swagger::Request.new(@default_http_method, @default_path, @default_params)
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, @default_params)
end
describe "initialization" do
@ -24,7 +24,7 @@ describe Swagger::Request do
end
it "allows params to be nil" do
@request = Swagger::Request.new(@default_http_method, @default_path, :params => nil)
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, :params => nil)
@request.query_string.should == ""
end
@ -59,7 +59,7 @@ describe Swagger::Request do
describe "body" do
it "camelCases parameters" do
@request = Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
:body => {
:bad_dog => 'bud',
:goodDog => "dud"
@ -73,7 +73,7 @@ describe Swagger::Request do
describe "path" do
it "accounts for a total absence of format in the path string" do
@request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
:format => "xml",
:params => {
}
@ -82,7 +82,7 @@ describe Swagger::Request do
end
it "does string substitution (format) on path params" do
@request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
:format => "xml",
:params => {
}
@ -91,7 +91,7 @@ describe Swagger::Request do
end
it "leaves path-bound params out of the query string" do
@request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
:params => {
:word => "cat",
:limit => 20
@ -101,7 +101,7 @@ describe Swagger::Request do
end
it "returns a question-mark free (blank) query string if no query params are present" do
@request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
:params => {
:word => "cat",
}
@ -110,7 +110,7 @@ describe Swagger::Request do
end
it "removes blank params" do
@request = Swagger::Request.new(:get, "words/fancy", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "words/fancy", @default_params.merge({
:params => {
:word => "dog",
:limit => "",
@ -121,7 +121,7 @@ describe Swagger::Request do
end
it "URI encodes the path" do
@request = Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({
:params => {
:word => "bill gates"
}
@ -130,7 +130,7 @@ describe Swagger::Request do
end
it "converts numeric params to strings" do
@request = Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
:params => {
:limit => 100
}
@ -142,7 +142,7 @@ describe Swagger::Request do
end
it "camelCases parameters" do
@request = Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, @default_params.merge({
:params => {
:bad_dog => 'bud',
:goodDog => "dud"
@ -153,7 +153,7 @@ describe Swagger::Request do
it "converts boolean values to their string representation" do
params = {:stringy => "fish", :truthy => true, :falsey => false}
@request = Swagger::Request.new(:get, 'fakeMethod', :params => params)
@request = SwaggerClient::Swagger::Request.new(:get, 'fakeMethod', :params => params)
@request.query_string.should == "?falsey=false&stringy=fish&truthy=true"
end
@ -162,12 +162,12 @@ describe Swagger::Request do
describe "API key" do
it "is inferred from the Swagger base configuration by default" do
Swagger.configure {|c| c.api_key = "xyz" }
Swagger::Request.new(:get, "word/json").headers[:api_key].should == "xyz"
SwaggerClient::Swagger.configure {|c| c.api_key = "xyz" }
SwaggerClient::Swagger::Request.new(:get, "word/json").headers[:api_key].should == "xyz"
end
it "can be obfuscated for public display" do
@request = Swagger::Request.new(:get, "words/fancy", @default_params.merge({
@request = SwaggerClient::Swagger::Request.new(:get, "words/fancy", @default_params.merge({
:params => {
:word => "dog",
:api_key => "123456"
@ -179,21 +179,21 @@ describe Swagger::Request do
end
it "allows a key in the params to override the configuration-level key, even if it's blank" do
Swagger.configure {|c| c.api_key = "abc" }
@request_with_key = Swagger::Request.new(:get, "word/json", :params => {:api_key => "jkl"})
SwaggerClient::Swagger.configure {|c| c.api_key = "abc" }
@request_with_key = SwaggerClient::Swagger::Request.new(:get, "word/json", :params => {:api_key => "jkl"})
@request_with_key.headers[:api_key].should be_nil
@request_with_key.params[:api_key].should == "jkl"
@request_without_key = Swagger::Request.new(:get, "word/json", :params => {:api_key => nil})
@request_without_key = SwaggerClient::Swagger::Request.new(:get, "word/json", :params => {:api_key => nil})
@request_without_key.headers[:api_key].should be_nil
@request_without_key.params[:api_key].should be_nil
end
it "allows a key in the headers to override the configuration-level key, even if it's blank" do
Swagger.configure {|c| c.api_key = "hij" }
Swagger::Request.new(:get, "word/json").headers[:api_key].should == "hij"
Swagger::Request.new(:get, "word/json", :headers => {:api_key => "jkl"}).headers[:api_key].should == "jkl"
Swagger::Request.new(:get, "word/json", :headers => {:api_key => nil}).headers[:api_key].should be_nil
SwaggerClient::Swagger.configure {|c| c.api_key = "hij" }
SwaggerClient::Swagger::Request.new(:get, "word/json").headers[:api_key].should == "hij"
SwaggerClient::Swagger::Request.new(:get, "word/json", :headers => {:api_key => "jkl"}).headers[:api_key].should == "jkl"
SwaggerClient::Swagger::Request.new(:get, "word/json", :headers => {:api_key => nil}).headers[:api_key].should be_nil
end
end

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe Swagger::Response do
describe SwaggerClient::Swagger::Response do
before do
configure_swagger
@ -13,7 +13,7 @@ describe Swagger::Response do
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
end
@response = Swagger::Response.new(@raw)
@response = SwaggerClient::Swagger::Response.new(@raw)
end
describe "initialization" do
@ -43,7 +43,7 @@ describe Swagger::Response do
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002",
:headers => {'Accept'=> "application/xml"})
end
@response = Swagger::Response.new(@raw)
@response = SwaggerClient::Swagger::Response.new(@raw)
@response.format.should == 'xml'
@response.xml?.should == true
end

View File

@ -37,7 +37,7 @@ end
#end
def configure_swagger
Swagger.configure do |config|
SwaggerClient::Swagger.configure do |config|
config.api_key = 'special-key'
config.host = 'petstore.swagger.io'
config.base_path = '/v2'
@ -47,7 +47,7 @@ end
# always delete and then re-create the pet object with 10002
def prepare_pet
# remove the pet
PetApi.delete_pet(10002)
SwaggerClient::PetApi.delete_pet(10002)
# recreate the pet
category = Category.new('id' => 20002, 'name' => 'category test')
tag = Tag.new('id' => 30002, 'name' => 'tag test')
@ -59,13 +59,13 @@ end
# always delete and then re-create the store order
def prepare_store
order = Order.new("id" => 10002,
order = SwaggerClient::Order.new("id" => 10002,
"petId" => 10002,
"quantity" => 789,
"shipDate" => "2015-04-06T23:42:01.678Z",
"status" => "placed",
"complete" => false)
StoreApi.place_order(:body => order)
SwaggerClient::StoreApi.place_order(:body => order)
end
configure_swagger

View File

@ -7,7 +7,7 @@ describe "Store" do
end
it "should fetch an order" do
item = StoreApi.get_order_by_id(10002)
item = SwaggerClient::StoreApi.get_order_by_id(10002)
item.id.should == 10002
end
end

View File

@ -1,7 +1,7 @@
# require 'spec_helper'
require File.dirname(__FILE__) + '/spec_helper'
describe Swagger do
describe SwaggerClient::Swagger do
before(:each) do
configure_swagger
@ -16,35 +16,35 @@ describe Swagger do
context 'host' do
it 'removes http from host' do
Swagger.configure {|c| c.host = 'http://example.com' }
Swagger.configuration.host.should == 'example.com'
SwaggerClient::Swagger.configure {|c| c.host = 'http://example.com' }
SwaggerClient::Swagger.configuration.host.should == 'example.com'
end
it 'removes https from host' do
Swagger.configure {|c| c.host = 'https://wookiee.com' }
Swagger.configuration.host.should == 'wookiee.com'
SwaggerClient::Swagger.configure {|c| c.host = 'https://wookiee.com' }
SwaggerClient::Swagger.configuration.host.should == 'wookiee.com'
end
it 'removes trailing path from host' do
Swagger.configure {|c| c.host = 'hobo.com/v4' }
Swagger.configuration.host.should == 'hobo.com'
SwaggerClient::Swagger.configure {|c| c.host = 'hobo.com/v4' }
SwaggerClient::Swagger.configuration.host.should == 'hobo.com'
end
end
context 'base_path' do
it "prepends a slash to base_path" do
Swagger.configure {|c| c.base_path = 'v4/dog' }
Swagger.configuration.base_path.should == '/v4/dog'
SwaggerClient::Swagger.configure {|c| c.base_path = 'v4/dog' }
SwaggerClient::Swagger.configuration.base_path.should == '/v4/dog'
end
it "doesn't prepend a slash if one is already there" do
Swagger.configure {|c| c.base_path = '/v4/dog' }
Swagger.configuration.base_path.should == '/v4/dog'
SwaggerClient::Swagger.configure {|c| c.base_path = '/v4/dog' }
SwaggerClient::Swagger.configuration.base_path.should == '/v4/dog'
end
it "ends up as a blank string if nil" do
Swagger.configure {|c| c.base_path = nil }
Swagger.configuration.base_path.should == ''
SwaggerClient::Swagger.configure {|c| c.base_path = nil }
SwaggerClient::Swagger.configuration.base_path.should == ''
end
end