From 06d31cfedb7ad3bd74ab08b5df129da8fffd0732 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 4 Oct 2018 23:53:46 +0800 Subject: [PATCH] Better format for Ruby tests (#1166) * better format for ruby test * update ruby petstore --- .../languages/AbstractRubyCodegen.java | 2 +- .../petstore/ruby/petstore_profiling.rb | 2 +- .../petstore/ruby/spec/api_client_spec.rb | 20 +++++++++---------- .../petstore/ruby/spec/base_object_spec.rb | 20 +++++++++---------- samples/client/petstore/ruby/spec/pet_spec.rb | 6 +++--- .../client/petstore/ruby/spec/spec_helper.rb | 6 +++--- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java index 2a57b927457b..42f5d8a54ba9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java @@ -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)"); } } diff --git a/samples/client/petstore/ruby/petstore_profiling.rb b/samples/client/petstore/ruby/petstore_profiling.rb index 485bd40c0c76..5a6029fa3bd2 100644 --- a/samples/client/petstore/ruby/petstore_profiling.rb +++ b/samples/client/petstore/ruby/petstore_profiling.rb @@ -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 diff --git a/samples/client/petstore/ruby/spec/api_client_spec.rb b/samples/client/petstore/ruby/spec/api_client_spec.rb index 15468683bc32..ec2939f83933 100644 --- a/samples/client/petstore/ruby/spec/api_client_spec.rb +++ b/samples/client/petstore/ruby/spec/api_client_spec.rb @@ -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 @@ -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 @@ -114,7 +114,7 @@ describe "#deserialize" do it "handles Array" 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') expect(data).to be_a(Array) @@ -123,7 +123,7 @@ it "handles Array>" 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>') expect(data).to be_a(Array) @@ -132,16 +132,16 @@ it "handles Hash" 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') expect(data).to be_a(Hash) - expect(data).to eq({:message => 'Hello'}) + expect(data).to eq(:message => 'Hello') end it "handles Hash" 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') expect(data).to be_a(Hash) @@ -153,7 +153,7 @@ it "handles Hash>" 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>') expect(result).to be_a(Hash) @@ -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 diff --git a/samples/client/petstore/ruby/spec/base_object_spec.rb b/samples/client/petstore/ruby/spec/base_object_spec.rb index ad3b4eb74f7b..4043dcb6b972 100644 --- a/samples/client/petstore/ruby/spec/base_object_spec.rb +++ b/samples/client/petstore/ruby/spec/base_object_spec.rb @@ -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 @@ -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"], } @@ -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'] @@ -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 diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 728d0e5345a1..ec3af401cbe9 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -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, diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index 11794c9ebcfe..953ff788a870 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -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 @@ 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