Skip to content

Commit

Permalink
Better format for Ruby tests (OpenAPITools#1166)
Browse files Browse the repository at this point in the history
* better format for ruby test

* update ruby petstore
  • Loading branch information
wing328 authored Oct 4, 2018
1 parent 3e3b03f commit 06d31cf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void processOpts() {
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)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/petstore_profiling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def call_apis
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
Expand Down
20 changes: 10 additions & 10 deletions samples/client/petstore/ruby/spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
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

Expand All @@ -87,7 +87,7 @@
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
Expand All @@ -114,7 +114,7 @@
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)
Expand All @@ -123,7 +123,7 @@

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)
Expand All @@ -132,16 +132,16 @@

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)
Expand All @@ -153,7 +153,7 @@

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)
Expand All @@ -176,7 +176,7 @@
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
Expand Down
20 changes: 10 additions & 10 deletions samples/client/petstore/ruby/spec/base_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.openapi_types

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
Expand All @@ -44,12 +44,12 @@ def self.openapi_types
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"],
}
Expand All @@ -68,7 +68,7 @@ def self.openapi_types
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']
Expand Down Expand Up @@ -101,8 +101,8 @@ def self.openapi_types
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
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/ruby/spec/pet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

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,
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -141,7 +141,7 @@ def serialize_json(o)

# 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

0 comments on commit 06d31cf

Please sign in to comment.