forked from loafle/openapi-generator-original
fix ruby spec
This commit is contained in:
parent
7f84deaf30
commit
4a0314849e
@ -2,19 +2,16 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe "Pet" do
|
describe "Pet" do
|
||||||
before do
|
before do
|
||||||
Swagger.configure do |config|
|
configure_swagger
|
||||||
config.api_key = 'special-key'
|
prepare_pet
|
||||||
config.host = 'petstore.swagger.io'
|
|
||||||
config.base_path = '/v2'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "pet methods" do
|
describe "pet methods" do
|
||||||
it "should fetch a pet object" do
|
it "should fetch a pet object" do
|
||||||
pet = PetApi.getPetById(5)
|
pet = PetApi.getPetById(10002)
|
||||||
pet.should be_a(Pet)
|
pet.should be_a(Pet)
|
||||||
pet.id.should == 5
|
pet.id.should == 10002
|
||||||
pet.name.should == "panda"
|
pet.name.should == "RUBY UNIT TESTING"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should find pets by status" do
|
it "should find pets by status" do
|
||||||
@ -37,36 +34,21 @@ describe "Pet" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should update a pet" do
|
it "should update a pet" do
|
||||||
pet = Pet.new({'id' => 99, 'name' => 'programmer', 'status' => 'coding'})
|
pet = Pet.new({'id' => 10002, 'status' => 'sold'})
|
||||||
PetApi.addPet(pet)
|
PetApi.addPet(pet)
|
||||||
|
|
||||||
fetched = PetApi.getPetById(99)
|
fetched = PetApi.getPetById(10002)
|
||||||
fetched.id.should == 99
|
fetched.id.should == 10002
|
||||||
|
fetched.status.should == 'sold'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create a pet" do
|
it "should create a pet" do
|
||||||
pet = Pet.new('id' => 100, 'name' => "Gorilla")
|
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
|
||||||
#raise pet.inspect
|
|
||||||
PetApi.addPet(pet)
|
PetApi.addPet(pet)
|
||||||
|
|
||||||
pet = PetApi.getPetById(100)
|
pet = PetApi.getPetById(10002)
|
||||||
pet.id.should == 100
|
pet.id.should == 10002
|
||||||
pet.name.should == "Gorilla"
|
pet.name.should == "RUBY UNIT TESTING"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Store" do
|
|
||||||
before do
|
|
||||||
Swagger.configure do |config|
|
|
||||||
config.api_key = 'special-key'
|
|
||||||
config.host = 'petstore.swagger.io'
|
|
||||||
config.base_path = '/v2'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should fetch an order" do
|
|
||||||
item = StoreApi.getOrderById(5)
|
|
||||||
item.id.should == 5
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
@ -2,10 +2,15 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe Swagger::Response do
|
describe Swagger::Response do
|
||||||
|
|
||||||
|
before do
|
||||||
|
configure_swagger
|
||||||
|
prepare_pet
|
||||||
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
||||||
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
||||||
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/5")
|
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
|
||||||
end
|
end
|
||||||
|
|
||||||
@response = Swagger::Response.new(@raw)
|
@response = Swagger::Response.new(@raw)
|
||||||
@ -35,7 +40,7 @@ describe Swagger::Response do
|
|||||||
|
|
||||||
it "recognizes xml" do
|
it "recognizes xml" do
|
||||||
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
|
||||||
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/5",
|
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002",
|
||||||
:headers => {'Accept'=> "application/xml"})
|
:headers => {'Accept'=> "application/xml"})
|
||||||
end
|
end
|
||||||
@response = Swagger::Response.new(@raw)
|
@response = Swagger::Response.new(@raw)
|
||||||
|
@ -28,24 +28,42 @@ def help
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# no longer reading credentials (not used) from file (20150413)
|
||||||
# Parse ~/.swagger.yml for user credentials
|
# Parse ~/.swagger.yml for user credentials
|
||||||
begin
|
#begin
|
||||||
CREDENTIALS = YAML::load_file(File.join(ENV['HOME'], ".swagger.yml")).symbolize_keys
|
# CREDENTIALS = YAML::load_file(File.join(ENV['HOME'], ".swagger.yml")).symbolize_keys
|
||||||
rescue
|
#rescue
|
||||||
help
|
# help
|
||||||
end
|
#end
|
||||||
|
|
||||||
def configure_swagger
|
def configure_swagger
|
||||||
Swagger.configure do |config|
|
Swagger.configure do |config|
|
||||||
config.api_key = "special-key"
|
config.api_key = 'special-key'
|
||||||
config.username = ""
|
config.host = 'petstore.swagger.io'
|
||||||
config.password = ""
|
config.base_path = '/v2'
|
||||||
|
|
||||||
config.host = 'petstore.swagger.wordnik.com'
|
|
||||||
config.base_path = '/api'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# always delete and then re-create the pet object with 10002
|
||||||
|
def prepare_pet
|
||||||
|
# remove the pet
|
||||||
|
PetApi.deletePet('special-key', 10002)
|
||||||
|
# recreate the pet
|
||||||
|
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
|
||||||
|
PetApi.addPet(pet)
|
||||||
|
end
|
||||||
|
|
||||||
|
# always delete and then re-create the store order
|
||||||
|
def prepare_store
|
||||||
|
order = Order.new("id" => 10002,
|
||||||
|
"petId" => 10002,
|
||||||
|
"quantity" => 789,
|
||||||
|
"shipDate" => "2015-04-06T23:42:01.678Z",
|
||||||
|
"status" => "placed",
|
||||||
|
"complete" => false)
|
||||||
|
StoreApi.placeOrder(order)
|
||||||
|
end
|
||||||
|
|
||||||
configure_swagger
|
configure_swagger
|
||||||
|
|
||||||
# A random string to tack onto stuff to ensure we're not seeing
|
# A random string to tack onto stuff to ensure we're not seeing
|
||||||
|
@ -2,15 +2,12 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe "Store" do
|
describe "Store" do
|
||||||
before do
|
before do
|
||||||
Swagger.configure do |config|
|
configure_swagger
|
||||||
config.api_key = 'special-key'
|
prepare_store
|
||||||
config.host = 'petstore.swagger.io'
|
|
||||||
config.base_path = '/v2'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fetch an order" do
|
it "should fetch an order" do
|
||||||
item = StoreApi.getOrderById(5)
|
item = StoreApi.getOrderById(10002)
|
||||||
item.id.should == 5
|
item.id.should == 10002
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user