forked from loafle/openapi-generator-original
Better format for Ruby tests (#1166)
* better format for ruby test * update ruby petstore
This commit is contained in:
parent
3e3b03f93b
commit
06d31cfedb
@ -85,7 +85,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
super.processOpts();
|
||||
|
||||
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)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ class PetstoreProfiling
|
||||
pet.status = "available"
|
||||
pet.photo_urls = ["http://profiler.com"]
|
||||
# new tag
|
||||
tag= Petstore::Tag.new
|
||||
tag = Petstore::Tag.new
|
||||
tag.id = new_pet_id # use the same id as pet
|
||||
tag.name = "profile tag 1"
|
||||
# new category
|
||||
|
@ -65,13 +65,13 @@ describe Petstore::ApiClient do
|
||||
header_params = {}
|
||||
query_params = {}
|
||||
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({})
|
||||
|
||||
header_params = {}
|
||||
query_params = {}
|
||||
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({})
|
||||
end
|
||||
|
||||
@ -87,7 +87,7 @@ describe Petstore::ApiClient do
|
||||
query_params = {}
|
||||
auth_names = ['api_key', 'unknown']
|
||||
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({})
|
||||
end
|
||||
end
|
||||
@ -114,7 +114,7 @@ describe Petstore::ApiClient do
|
||||
describe "#deserialize" do
|
||||
it "handles Array<Integer>" do
|
||||
api_client = Petstore::ApiClient.new
|
||||
headers = {'Content-Type' => 'application/json'}
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '[12, 34]')
|
||||
data = api_client.deserialize(response, 'Array<Integer>')
|
||||
expect(data).to be_a(Array)
|
||||
@ -123,7 +123,7 @@ describe Petstore::ApiClient do
|
||||
|
||||
it "handles Array<Array<Integer>>" do
|
||||
api_client = Petstore::ApiClient.new
|
||||
headers = {'Content-Type' => 'application/json'}
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
||||
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
||||
expect(data).to be_a(Array)
|
||||
@ -132,16 +132,16 @@ describe Petstore::ApiClient do
|
||||
|
||||
it "handles Hash<String, String>" do
|
||||
api_client = Petstore::ApiClient.new
|
||||
headers = {'Content-Type' => 'application/json'}
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
||||
data = api_client.deserialize(response, 'Hash<String, String>')
|
||||
expect(data).to be_a(Hash)
|
||||
expect(data).to eq({:message => 'Hello'})
|
||||
expect(data).to eq(:message => 'Hello')
|
||||
end
|
||||
|
||||
it "handles Hash<String, Pet>" do
|
||||
api_client = Petstore::ApiClient.new
|
||||
headers = {'Content-Type' => 'application/json'}
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '{"pet": {"id": 1}}')
|
||||
data = api_client.deserialize(response, 'Hash<String, Pet>')
|
||||
expect(data).to be_a(Hash)
|
||||
@ -153,7 +153,7 @@ describe Petstore::ApiClient do
|
||||
|
||||
it "handles Hash<String, Hash<String, Pet>>" do
|
||||
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}}}')
|
||||
result = api_client.deserialize(response, 'Hash<String, Hash<String, Pet>>')
|
||||
expect(result).to be_a(Hash)
|
||||
@ -176,7 +176,7 @@ describe Petstore::ApiClient do
|
||||
pet.status = nil
|
||||
pet.photo_urls = nil
|
||||
pet.tags = []
|
||||
expected = {id: 1, name: '', tags: []}
|
||||
expected = { id: 1, name: '', tags: [] }
|
||||
expect(api_client.object_to_hash(pet)).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ end
|
||||
|
||||
describe 'BaseObject' 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
|
||||
expect(obj.declawed).not_to be_nil
|
||||
@ -44,12 +44,12 @@ describe 'BaseObject' do
|
||||
let(:obj) { ArrayMapObject.new }
|
||||
|
||||
let(:data) do
|
||||
{int_arr: [123, 456],
|
||||
pet_arr: [{name: 'Kitty'}],
|
||||
int_map: {'int' => 123},
|
||||
pet_map: {'pet' => {name: 'Kitty'}},
|
||||
int_arr_map: {'int_arr' => [123, 456]},
|
||||
pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]},
|
||||
{ int_arr: [123, 456],
|
||||
pet_arr: [{ name: 'Kitty' }],
|
||||
int_map: { 'int' => 123 },
|
||||
pet_map: { 'pet' => { name: 'Kitty' } },
|
||||
int_arr_map: { 'int_arr' => [123, 456] },
|
||||
pet_arr_map: { 'pet_arr' => [{ name: 'Kitty' }] },
|
||||
boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"],
|
||||
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(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)
|
||||
pet = obj.pet_map['pet']
|
||||
@ -101,8 +101,8 @@ describe 'BaseObject' do
|
||||
it 'works for #to_hash' do
|
||||
obj.build_from_hash(data)
|
||||
expect_data = data.dup
|
||||
expect_data[:boolean_true_arr].map! {true}
|
||||
expect_data[:boolean_false_arr].map! {false}
|
||||
expect_data[:boolean_true_arr].map! { true }
|
||||
expect_data[:boolean_false_arr].map! { false }
|
||||
expect(obj.to_hash).to eq(expect_data)
|
||||
end
|
||||
end
|
||||
|
@ -19,9 +19,9 @@ describe "Pet" do
|
||||
|
||||
describe "pet methods" do
|
||||
it "should construct a new pet object" do
|
||||
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'})
|
||||
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 => @pet_id,
|
||||
|
@ -114,7 +114,7 @@ def prepare_pet(pet_api)
|
||||
pet = Petstore::Pet.new('id' => pet_id, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url',
|
||||
'category' => category, 'tags' => [tag], 'status' => 'pending')
|
||||
pet_api.add_pet(pet)
|
||||
return pet_id
|
||||
pet_id
|
||||
end
|
||||
|
||||
# create a random order, return its id
|
||||
@ -127,7 +127,7 @@ def prepare_store(store_api)
|
||||
"status" => "placed",
|
||||
"complete" => false)
|
||||
store_api.place_order(order)
|
||||
return order_id
|
||||
order_id
|
||||
end
|
||||
|
||||
# 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
|
||||
def deserialize_json(s, type)
|
||||
headers = {'Content-Type' => 'application/json'}
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: s)
|
||||
API_CLIENT.deserialize(response, type)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user