Fix naming in specs

This commit is contained in:
xhh
2015-06-26 17:16:38 +08:00
parent d8b0cb739f
commit fafddbf040
6 changed files with 64 additions and 64 deletions

View File

@@ -9,9 +9,9 @@ describe "Pet" do
describe "pet methods" do
it "should construct a new pet object" do
tag1 = SwaggerClient::Tag.new({'id' => 1, 'name'=> 'tag1'})
tag2 = SwaggerClient::Tag.new({'id' => 2, 'name'=> 'tag2'})
category1 = SwaggerClient::Category.new({:id => 1, :name => 'category unknown'})
tag1 = Petstore::Tag.new({'id' => 1, 'name'=> 'tag1'})
tag2 = Petstore::Tag.new({'id' => 2, 'name'=> 'tag2'})
category1 = Petstore::Category.new({:id => 1, :name => 'category unknown'})
# initalize using both string and symbol key
pet_hash = {
:id => 10002,
@@ -21,7 +21,7 @@ describe "Pet" do
:category => category1,
:tags => [tag1, tag2]
}
pet = SwaggerClient::Pet.new(pet_hash)
pet = Petstore::Pet.new(pet_hash)
# test new
pet.name.should == "RUBY UNIT TESTING"
pet.status.should == "pending"
@@ -31,7 +31,7 @@ describe "Pet" do
pet.category.name.should == 'category unknown'
# test build_from_hash
pet2 = SwaggerClient::Pet.new
pet2 = Petstore::Pet.new
pet2.build_from_hash(pet.to_hash)
pet.to_hash.should == pet2.to_hash
@@ -42,8 +42,8 @@ describe "Pet" do
end
it "should fetch a pet object" do
pet = SwaggerClient::PetApi.get_pet_by_id(10002)
pet.should be_a(SwaggerClient::Pet)
pet = Petstore::PetApi.get_pet_by_id(10002)
pet.should be_a(Petstore::Pet)
pet.id.should == 10002
pet.name.should == "RUBY UNIT TESTING"
pet.tags[0].name.should == "tag test"
@@ -52,9 +52,9 @@ describe "Pet" do
it "should not find a pet that does not exist" do
begin
SwaggerClient::PetApi.get_pet_by_id(-1)
Petstore::PetApi.get_pet_by_id(-1)
fail 'it should raise error'
rescue SwaggerClient::Swagger::ApiError => e
rescue Petstore::Swagger::ApiError => e
e.code.should == 404
e.message.should == 'Not Found'
e.response_body.should == '{"code":1,"type":"error","message":"Pet not found"}'
@@ -64,21 +64,21 @@ describe "Pet" do
end
it "should find pets by status" do
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'available')
pets = Petstore::PetApi.find_pets_by_status(:status => 'available')
pets.length.should >= 3
pets.each do |pet|
pet.should be_a(SwaggerClient::Pet)
pet.should be_a(Petstore::Pet)
pet.status.should == 'available'
end
end
it "should not find a pet with invalid status" do
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'invalid-status')
pets = Petstore::PetApi.find_pets_by_status(:status => 'invalid-status')
pets.length.should == 0
end
it "should find a pet by status" do
pets = SwaggerClient::PetApi.find_pets_by_status(:status => "available,sold")
pets = Petstore::PetApi.find_pets_by_status(:status => "available,sold")
pets.each do |pet|
if pet.status != 'available' && pet.status != 'sold'
raise "pet status wasn't right"
@@ -87,21 +87,21 @@ describe "Pet" do
end
it "should update a pet" do
pet = SwaggerClient::Pet.new({'id' => 10002, 'status' => 'sold'})
SwaggerClient::PetApi.add_pet(:body => pet)
pet = Petstore::Pet.new({'id' => 10002, 'status' => 'sold'})
Petstore::PetApi.add_pet(:body => pet)
fetched = SwaggerClient::PetApi.get_pet_by_id(10002)
fetched = Petstore::PetApi.get_pet_by_id(10002)
fetched.id.should == 10002
fetched.status.should == 'sold'
end
it "should create a pet" do
pet = SwaggerClient::Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
result = SwaggerClient::PetApi.add_pet(:body => pet)
pet = Petstore::Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
result = Petstore::PetApi.add_pet(:body => pet)
# nothing is returned
result.should be_nil
pet = SwaggerClient::PetApi.get_pet_by_id(10002)
pet = Petstore::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 SwaggerClient::Swagger::Request do
describe Petstore::Swagger::Request do
before(:each) do
SwaggerClient::Swagger.configure do |config|
Petstore::Swagger.configure do |config|
inject_format = true
config.api_key['api_key'] = 'special-key'
config.host = 'petstore.swagger.io'
@@ -15,7 +15,7 @@ describe SwaggerClient::Swagger::Request do
@default_params = {
:params => {:foo => "1", :bar => "2"}
}
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, @default_params)
@request = Petstore::Swagger::Request.new(@default_http_method, @default_path, @default_params)
end
describe "initialization" do
@@ -24,7 +24,7 @@ describe SwaggerClient::Swagger::Request do
end
it "allows params to be nil" do
@request = SwaggerClient::Swagger::Request.new(@default_http_method, @default_path, :params => nil)
@request = Petstore::Swagger::Request.new(@default_http_method, @default_path, :params => nil)
@request.params.should == {}
end
@@ -55,7 +55,7 @@ describe SwaggerClient::Swagger::Request do
describe "path" do
it "accounts for a total absence of format in the path string" do
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
@request = Petstore::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
:format => "xml",
:params => {
}
@@ -64,7 +64,7 @@ describe SwaggerClient::Swagger::Request do
end
it "does string substitution (format) on path params" do
@request = SwaggerClient::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
@request = Petstore::Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({
:format => "xml",
:params => {
}
@@ -73,7 +73,7 @@ describe SwaggerClient::Swagger::Request do
end
it "URI encodes the path" do
@request = SwaggerClient::Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({
@request = Petstore::Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({
:params => {
:word => "bill gates"
}
@@ -85,7 +85,7 @@ describe SwaggerClient::Swagger::Request do
describe "#update_params_for_auth!" do
it "sets header api-key parameter with prefix" do
SwaggerClient::Swagger.configure do |config|
Petstore::Swagger.configure do |config|
inject_format = true
config.api_key_prefix['api_key'] = 'PREFIX'
end
@@ -95,7 +95,7 @@ describe SwaggerClient::Swagger::Request do
end
it "sets header api-key parameter without prefix" do
SwaggerClient::Swagger.configure do |config|
Petstore::Swagger.configure do |config|
inject_format = true
config.api_key_prefix['api_key'] = nil
end

View File

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

View File

@@ -1,6 +1,6 @@
require 'rubygems'
require 'bundler/setup'
require 'swagger_client'
require 'petstore'
require 'vcr'
require 'typhoeus'
require 'json'
@@ -37,7 +37,7 @@ end
#end
def configure_swagger
SwaggerClient::Swagger.configure do |config|
Petstore::Swagger.configure do |config|
config.api_key['api_key'] = 'special-key'
config.host = 'petstore.swagger.io'
config.base_path = '/v2'
@@ -47,25 +47,25 @@ end
# always delete and then re-create the pet object with 10002
def prepare_pet
# remove the pet
SwaggerClient::PetApi.delete_pet(10002)
Petstore::PetApi.delete_pet(10002)
# recreate the pet
category = SwaggerClient::Category.new('id' => 20002, 'name' => 'category test')
tag = SwaggerClient::Tag.new('id' => 30002, 'name' => 'tag test')
pet = SwaggerClient::Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url',
category = Petstore::Category.new('id' => 20002, 'name' => 'category test')
tag = Petstore::Tag.new('id' => 30002, 'name' => 'tag test')
pet = Petstore::Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url',
'category' => category, 'tags' => [tag], 'status' => 'pending')
SwaggerClient::PetApi.add_pet(:'body'=> pet)
Petstore::PetApi.add_pet(:'body'=> pet)
end
# always delete and then re-create the store order
def prepare_store
order = SwaggerClient::Order.new("id" => 10002,
order = Petstore::Order.new("id" => 10002,
"petId" => 10002,
"quantity" => 789,
"shipDate" => "2015-04-06T23:42:01.678Z",
"status" => "placed",
"complete" => false)
SwaggerClient::StoreApi.place_order(:body => order)
Petstore::StoreApi.place_order(:body => order)
end
configure_swagger

View File

@@ -7,12 +7,12 @@ describe "Store" do
end
it "should fetch an order" do
item = SwaggerClient::StoreApi.get_order_by_id(10002)
item = Petstore::StoreApi.get_order_by_id(10002)
item.id.should == 10002
end
it "should featch the inventory" do
result = SwaggerClient::StoreApi.get_inventory
result = Petstore::StoreApi.get_inventory
result.should be_a(Hash)
result.should_not be_empty
result.each do |k, v|

View File

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