From 4a0314849e91ba9231f7a8e9ac294a01faf80e23 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 13 Apr 2015 22:23:52 +0800 Subject: [PATCH] fix ruby spec --- samples/client/petstore/ruby/spec/pet_spec.rb | 44 ++++++------------- .../petstore/ruby/spec/response_spec.rb | 11 +++-- .../client/petstore/ruby/spec/spec_helper.rb | 40 ++++++++++++----- .../client/petstore/ruby/spec/store_spec.rb | 11 ++--- 4 files changed, 54 insertions(+), 52 deletions(-) diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 0ea0a5dcd32..4f55247dbb5 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -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 diff --git a/samples/client/petstore/ruby/spec/response_spec.rb b/samples/client/petstore/ruby/spec/response_spec.rb index 6987ca773e8..c0542005cb0 100644 --- a/samples/client/petstore/ruby/spec/response_spec.rb +++ b/samples/client/petstore/ruby/spec/response_spec.rb @@ -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 \ No newline at end of file +end diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index f5ea626e9b8..baa0470bef1 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -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 diff --git a/samples/client/petstore/ruby/spec/store_spec.rb b/samples/client/petstore/ruby/spec/store_spec.rb index 0d3233ee558..961aac05f06 100644 --- a/samples/client/petstore/ruby/spec/store_spec.rb +++ b/samples/client/petstore/ruby/spec/store_spec.rb @@ -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