Better format for Ruby tests (#1166)

* better format for ruby test

* update ruby petstore
This commit is contained in:
William Cheng 2018-10-04 23:53:46 +08:00 committed by GitHub
parent 3e3b03f93b
commit 06d31cfedb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions

View File

@ -85,7 +85,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
super.processOpts(); super.processOpts();
if (StringUtils.isEmpty(System.getenv("RUBY_POST_PROCESS_FILE"))) { if (StringUtils.isEmpty(System.getenv("RUBY_POST_PROCESS_FILE"))) {
LOGGER.info("Hint: Environment variable 'RUBY_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export RUBY_POST_PROCESS_FILE=/usr/local/bin/rubocop -a' (Linux/Mac)"); LOGGER.info("Hint: Environment variable 'RUBY_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export RUBY_POST_PROCESS_FILE=\"/usr/local/bin/rubocop -a\"' (Linux/Mac)");
} }
} }

View File

@ -24,7 +24,7 @@ class PetstoreProfiling
pet.status = "available" pet.status = "available"
pet.photo_urls = ["http://profiler.com"] pet.photo_urls = ["http://profiler.com"]
# new tag # new tag
tag= Petstore::Tag.new tag = Petstore::Tag.new
tag.id = new_pet_id # use the same id as pet tag.id = new_pet_id # use the same id as pet
tag.name = "profile tag 1" tag.name = "profile tag 1"
# new category # new category

View File

@ -65,13 +65,13 @@ describe Petstore::ApiClient do
header_params = {} header_params = {}
query_params = {} query_params = {}
api_client.update_params_for_auth! header_params, query_params, auth_names api_client.update_params_for_auth! header_params, query_params, auth_names
expect(header_params).to eq({'api_key' => 'PREFIX special-key'}) expect(header_params).to eq('api_key' => 'PREFIX special-key')
expect(query_params).to eq({}) expect(query_params).to eq({})
header_params = {} header_params = {}
query_params = {} query_params = {}
api_client2.update_params_for_auth! header_params, query_params, auth_names api_client2.update_params_for_auth! header_params, query_params, auth_names
expect(header_params).to eq({'api_key' => 'PREFIX2 special-key2'}) expect(header_params).to eq('api_key' => 'PREFIX2 special-key2')
expect(query_params).to eq({}) expect(query_params).to eq({})
end end
@ -87,7 +87,7 @@ describe Petstore::ApiClient do
query_params = {} query_params = {}
auth_names = ['api_key', 'unknown'] auth_names = ['api_key', 'unknown']
api_client.update_params_for_auth! header_params, query_params, auth_names api_client.update_params_for_auth! header_params, query_params, auth_names
expect(header_params).to eq({'api_key' => 'special-key'}) expect(header_params).to eq('api_key' => 'special-key')
expect(query_params).to eq({}) expect(query_params).to eq({})
end end
end end
@ -114,7 +114,7 @@ describe Petstore::ApiClient do
describe "#deserialize" do describe "#deserialize" do
it "handles Array<Integer>" do it "handles Array<Integer>" do
api_client = Petstore::ApiClient.new api_client = Petstore::ApiClient.new
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '[12, 34]') response = double('response', headers: headers, body: '[12, 34]')
data = api_client.deserialize(response, 'Array<Integer>') data = api_client.deserialize(response, 'Array<Integer>')
expect(data).to be_a(Array) expect(data).to be_a(Array)
@ -123,7 +123,7 @@ describe Petstore::ApiClient do
it "handles Array<Array<Integer>>" do it "handles Array<Array<Integer>>" do
api_client = Petstore::ApiClient.new api_client = Petstore::ApiClient.new
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '[[12, 34], [56]]') response = double('response', headers: headers, body: '[[12, 34], [56]]')
data = api_client.deserialize(response, 'Array<Array<Integer>>') data = api_client.deserialize(response, 'Array<Array<Integer>>')
expect(data).to be_a(Array) expect(data).to be_a(Array)
@ -132,16 +132,16 @@ describe Petstore::ApiClient do
it "handles Hash<String, String>" do it "handles Hash<String, String>" do
api_client = Petstore::ApiClient.new api_client = Petstore::ApiClient.new
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '{"message": "Hello"}') response = double('response', headers: headers, body: '{"message": "Hello"}')
data = api_client.deserialize(response, 'Hash<String, String>') data = api_client.deserialize(response, 'Hash<String, String>')
expect(data).to be_a(Hash) expect(data).to be_a(Hash)
expect(data).to eq({:message => 'Hello'}) expect(data).to eq(:message => 'Hello')
end end
it "handles Hash<String, Pet>" do it "handles Hash<String, Pet>" do
api_client = Petstore::ApiClient.new api_client = Petstore::ApiClient.new
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '{"pet": {"id": 1}}') response = double('response', headers: headers, body: '{"pet": {"id": 1}}')
data = api_client.deserialize(response, 'Hash<String, Pet>') data = api_client.deserialize(response, 'Hash<String, Pet>')
expect(data).to be_a(Hash) expect(data).to be_a(Hash)
@ -153,7 +153,7 @@ describe Petstore::ApiClient do
it "handles Hash<String, Hash<String, Pet>>" do it "handles Hash<String, Hash<String, Pet>>" do
api_client = Petstore::ApiClient.new api_client = Petstore::ApiClient.new
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '{"data": {"pet": {"id": 1}}}') response = double('response', headers: headers, body: '{"data": {"pet": {"id": 1}}}')
result = api_client.deserialize(response, 'Hash<String, Hash<String, Pet>>') result = api_client.deserialize(response, 'Hash<String, Hash<String, Pet>>')
expect(result).to be_a(Hash) expect(result).to be_a(Hash)
@ -176,7 +176,7 @@ describe Petstore::ApiClient do
pet.status = nil pet.status = nil
pet.photo_urls = nil pet.photo_urls = nil
pet.tags = [] pet.tags = []
expected = {id: 1, name: '', tags: []} expected = { id: 1, name: '', tags: [] }
expect(api_client.object_to_hash(pet)).to eq(expected) expect(api_client.object_to_hash(pet)).to eq(expected)
end end
end end

View File

@ -32,7 +32,7 @@ end
describe 'BaseObject' do describe 'BaseObject' do
describe 'boolean values' do describe 'boolean values' do
let(:obj) { Petstore::Cat.new({declawed: false}) } let(:obj) { Petstore::Cat.new(declawed: false) }
it 'should have values set' do it 'should have values set' do
expect(obj.declawed).not_to be_nil expect(obj.declawed).not_to be_nil
@ -44,12 +44,12 @@ describe 'BaseObject' do
let(:obj) { ArrayMapObject.new } let(:obj) { ArrayMapObject.new }
let(:data) do let(:data) do
{int_arr: [123, 456], { int_arr: [123, 456],
pet_arr: [{name: 'Kitty'}], pet_arr: [{ name: 'Kitty' }],
int_map: {'int' => 123}, int_map: { 'int' => 123 },
pet_map: {'pet' => {name: 'Kitty'}}, pet_map: { 'pet' => { name: 'Kitty' } },
int_arr_map: {'int_arr' => [123, 456]}, int_arr_map: { 'int_arr' => [123, 456] },
pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]}, pet_arr_map: { 'pet_arr' => [{ name: 'Kitty' }] },
boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"], boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"],
boolean_false_arr: [false, "", 0, "0", "f", nil, "null", "\ntrue\n"], boolean_false_arr: [false, "", 0, "0", "f", nil, "null", "\ntrue\n"],
} }
@ -68,7 +68,7 @@ describe 'BaseObject' do
expect(pet.name).to eq('Kitty') expect(pet.name).to eq('Kitty')
expect(obj.int_map).to be_instance_of(Hash) expect(obj.int_map).to be_instance_of(Hash)
expect(obj.int_map).to eq({'int' => 123}) expect(obj.int_map).to eq('int' => 123)
expect(obj.pet_map).to be_instance_of(Hash) expect(obj.pet_map).to be_instance_of(Hash)
pet = obj.pet_map['pet'] pet = obj.pet_map['pet']
@ -101,8 +101,8 @@ describe 'BaseObject' do
it 'works for #to_hash' do it 'works for #to_hash' do
obj.build_from_hash(data) obj.build_from_hash(data)
expect_data = data.dup expect_data = data.dup
expect_data[:boolean_true_arr].map! {true} expect_data[:boolean_true_arr].map! { true }
expect_data[:boolean_false_arr].map! {false} expect_data[:boolean_false_arr].map! { false }
expect(obj.to_hash).to eq(expect_data) expect(obj.to_hash).to eq(expect_data)
end end
end end

View File

@ -19,9 +19,9 @@ describe "Pet" do
describe "pet methods" do describe "pet methods" do
it "should construct a new pet object" do it "should construct a new pet object" do
tag1 = Petstore::Tag.new({'id' => 1, 'name'=> 'tag1'}) tag1 = Petstore::Tag.new('id' => 1, 'name' => 'tag1')
tag2 = Petstore::Tag.new({'id' => 2, 'name'=> 'tag2'}) tag2 = Petstore::Tag.new('id' => 2, 'name' => 'tag2')
category1 = Petstore::Category.new({:id => 1, :name => 'category unknown'}) category1 = Petstore::Category.new(:id => 1, :name => 'category unknown')
# initalize using both string and symbol key # initalize using both string and symbol key
pet_hash = { pet_hash = {
:id => @pet_id, :id => @pet_id,

View File

@ -114,7 +114,7 @@ def prepare_pet(pet_api)
pet = Petstore::Pet.new('id' => pet_id, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url', pet = Petstore::Pet.new('id' => pet_id, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url',
'category' => category, 'tags' => [tag], 'status' => 'pending') 'category' => category, 'tags' => [tag], 'status' => 'pending')
pet_api.add_pet(pet) pet_api.add_pet(pet)
return pet_id pet_id
end end
# create a random order, return its id # create a random order, return its id
@ -127,7 +127,7 @@ def prepare_store(store_api)
"status" => "placed", "status" => "placed",
"complete" => false) "complete" => false)
store_api.place_order(order) store_api.place_order(order)
return order_id order_id
end end
# 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
@ -141,7 +141,7 @@ end
# helper method to deserialize json string back to object # helper method to deserialize json string back to object
def deserialize_json(s, type) def deserialize_json(s, type)
headers = {'Content-Type' => 'application/json'} headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: s) response = double('response', headers: headers, body: s)
API_CLIENT.deserialize(response, type) API_CLIENT.deserialize(response, type)
end end