fix ruby spec

This commit is contained in:
wing328 2015-04-13 22:23:52 +08:00
parent 7f84deaf30
commit 4a0314849e
4 changed files with 54 additions and 52 deletions

View File

@ -2,19 +2,16 @@ require 'spec_helper'
describe "Pet" do
before do
Swagger.configure do |config|
config.api_key = 'special-key'
config.host = 'petstore.swagger.io'
config.base_path = '/v2'
end
configure_swagger
prepare_pet
end
describe "pet methods" do
it "should fetch a pet object" do
pet = PetApi.getPetById(5)
pet = PetApi.getPetById(10002)
pet.should be_a(Pet)
pet.id.should == 5
pet.name.should == "panda"
pet.id.should == 10002
pet.name.should == "RUBY UNIT TESTING"
end
it "should find pets by status" do
@ -37,36 +34,21 @@ describe "Pet" do
end
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)
fetched = PetApi.getPetById(99)
fetched.id.should == 99
fetched = PetApi.getPetById(10002)
fetched.id.should == 10002
fetched.status.should == 'sold'
end
it "should create a pet" do
pet = Pet.new('id' => 100, 'name' => "Gorilla")
#raise pet.inspect
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
PetApi.addPet(pet)
pet = PetApi.getPetById(100)
pet.id.should == 100
pet.name.should == "Gorilla"
pet = PetApi.getPetById(10002)
pet.id.should == 10002
pet.name.should == "RUBY UNIT TESTING"
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

View File

@ -2,10 +2,15 @@ require 'spec_helper'
describe Swagger::Response do
before do
configure_swagger
prepare_pet
end
before(:each) 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
@response = Swagger::Response.new(@raw)
@ -35,7 +40,7 @@ describe Swagger::Response do
it "recognizes xml" 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"})
end
@response = Swagger::Response.new(@raw)
@ -57,4 +62,4 @@ describe Swagger::Response do
end
end
end

View File

@ -28,24 +28,42 @@ def help
exit
end
# no longer reading credentials (not used) from file (20150413)
# Parse ~/.swagger.yml for user credentials
begin
CREDENTIALS = YAML::load_file(File.join(ENV['HOME'], ".swagger.yml")).symbolize_keys
rescue
help
end
#begin
# CREDENTIALS = YAML::load_file(File.join(ENV['HOME'], ".swagger.yml")).symbolize_keys
#rescue
# help
#end
def configure_swagger
Swagger.configure do |config|
config.api_key = "special-key"
config.username = ""
config.password = ""
config.host = 'petstore.swagger.wordnik.com'
config.base_path = '/api'
config.api_key = 'special-key'
config.host = 'petstore.swagger.io'
config.base_path = '/v2'
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
# A random string to tack onto stuff to ensure we're not seeing

View File

@ -2,15 +2,12 @@ require 'spec_helper'
describe "Store" do
before do
Swagger.configure do |config|
config.api_key = 'special-key'
config.host = 'petstore.swagger.io'
config.base_path = '/v2'
end
configure_swagger
prepare_store
end
it "should fetch an order" do
item = StoreApi.getOrderById(5)
item.id.should == 5
item = StoreApi.getOrderById(10002)
item.id.should == 10002
end
end