Skip to content

Commit c797c9b

Browse files
authored
Better format for Ruby tests (OpenAPITools#1166)
* better format for ruby test * update ruby petstore
1 parent 1a4f6c6 commit c797c9b

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void processOpts() {
8585
super.processOpts();
8686

8787
if (StringUtils.isEmpty(System.getenv("RUBY_POST_PROCESS_FILE"))) {
88-
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)");
88+
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)");
8989
}
9090
}
9191

samples/client/petstore/ruby/petstore_profiling.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def call_apis
2424
pet.status = "available"
2525
pet.photo_urls = ["http://profiler.com"]
2626
# new tag
27-
tag= Petstore::Tag.new
27+
tag = Petstore::Tag.new
2828
tag.id = new_pet_id # use the same id as pet
2929
tag.name = "profile tag 1"
3030
# new category

samples/client/petstore/ruby/spec/api_client_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
header_params = {}
6666
query_params = {}
6767
api_client.update_params_for_auth! header_params, query_params, auth_names
68-
expect(header_params).to eq({'api_key' => 'PREFIX special-key'})
68+
expect(header_params).to eq('api_key' => 'PREFIX special-key')
6969
expect(query_params).to eq({})
7070

7171
header_params = {}
7272
query_params = {}
7373
api_client2.update_params_for_auth! header_params, query_params, auth_names
74-
expect(header_params).to eq({'api_key' => 'PREFIX2 special-key2'})
74+
expect(header_params).to eq('api_key' => 'PREFIX2 special-key2')
7575
expect(query_params).to eq({})
7676
end
7777

@@ -87,7 +87,7 @@
8787
query_params = {}
8888
auth_names = ['api_key', 'unknown']
8989
api_client.update_params_for_auth! header_params, query_params, auth_names
90-
expect(header_params).to eq({'api_key' => 'special-key'})
90+
expect(header_params).to eq('api_key' => 'special-key')
9191
expect(query_params).to eq({})
9292
end
9393
end
@@ -114,7 +114,7 @@
114114
describe "#deserialize" do
115115
it "handles Array<Integer>" do
116116
api_client = Petstore::ApiClient.new
117-
headers = {'Content-Type' => 'application/json'}
117+
headers = { 'Content-Type' => 'application/json' }
118118
response = double('response', headers: headers, body: '[12, 34]')
119119
data = api_client.deserialize(response, 'Array<Integer>')
120120
expect(data).to be_a(Array)
@@ -123,7 +123,7 @@
123123

124124
it "handles Array<Array<Integer>>" do
125125
api_client = Petstore::ApiClient.new
126-
headers = {'Content-Type' => 'application/json'}
126+
headers = { 'Content-Type' => 'application/json' }
127127
response = double('response', headers: headers, body: '[[12, 34], [56]]')
128128
data = api_client.deserialize(response, 'Array<Array<Integer>>')
129129
expect(data).to be_a(Array)
@@ -132,16 +132,16 @@
132132

133133
it "handles Hash<String, String>" do
134134
api_client = Petstore::ApiClient.new
135-
headers = {'Content-Type' => 'application/json'}
135+
headers = { 'Content-Type' => 'application/json' }
136136
response = double('response', headers: headers, body: '{"message": "Hello"}')
137137
data = api_client.deserialize(response, 'Hash<String, String>')
138138
expect(data).to be_a(Hash)
139-
expect(data).to eq({:message => 'Hello'})
139+
expect(data).to eq(:message => 'Hello')
140140
end
141141

142142
it "handles Hash<String, Pet>" do
143143
api_client = Petstore::ApiClient.new
144-
headers = {'Content-Type' => 'application/json'}
144+
headers = { 'Content-Type' => 'application/json' }
145145
response = double('response', headers: headers, body: '{"pet": {"id": 1}}')
146146
data = api_client.deserialize(response, 'Hash<String, Pet>')
147147
expect(data).to be_a(Hash)
@@ -153,7 +153,7 @@
153153

154154
it "handles Hash<String, Hash<String, Pet>>" do
155155
api_client = Petstore::ApiClient.new
156-
headers = {'Content-Type' => 'application/json'}
156+
headers = { 'Content-Type' => 'application/json' }
157157
response = double('response', headers: headers, body: '{"data": {"pet": {"id": 1}}}')
158158
result = api_client.deserialize(response, 'Hash<String, Hash<String, Pet>>')
159159
expect(result).to be_a(Hash)
@@ -176,7 +176,7 @@
176176
pet.status = nil
177177
pet.photo_urls = nil
178178
pet.tags = []
179-
expected = {id: 1, name: '', tags: []}
179+
expected = { id: 1, name: '', tags: [] }
180180
expect(api_client.object_to_hash(pet)).to eq(expected)
181181
end
182182
end

samples/client/petstore/ruby/spec/base_object_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def self.openapi_types
3232

3333
describe 'BaseObject' do
3434
describe 'boolean values' do
35-
let(:obj) { Petstore::Cat.new({declawed: false}) }
35+
let(:obj) { Petstore::Cat.new(declawed: false) }
3636

3737
it 'should have values set' do
3838
expect(obj.declawed).not_to be_nil
@@ -44,12 +44,12 @@ def self.openapi_types
4444
let(:obj) { ArrayMapObject.new }
4545

4646
let(:data) do
47-
{int_arr: [123, 456],
48-
pet_arr: [{name: 'Kitty'}],
49-
int_map: {'int' => 123},
50-
pet_map: {'pet' => {name: 'Kitty'}},
51-
int_arr_map: {'int_arr' => [123, 456]},
52-
pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]},
47+
{ int_arr: [123, 456],
48+
pet_arr: [{ name: 'Kitty' }],
49+
int_map: { 'int' => 123 },
50+
pet_map: { 'pet' => { name: 'Kitty' } },
51+
int_arr_map: { 'int_arr' => [123, 456] },
52+
pet_arr_map: { 'pet_arr' => [{ name: 'Kitty' }] },
5353
boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"],
5454
boolean_false_arr: [false, "", 0, "0", "f", nil, "null", "\ntrue\n"],
5555
}
@@ -68,7 +68,7 @@ def self.openapi_types
6868
expect(pet.name).to eq('Kitty')
6969

7070
expect(obj.int_map).to be_instance_of(Hash)
71-
expect(obj.int_map).to eq({'int' => 123})
71+
expect(obj.int_map).to eq('int' => 123)
7272

7373
expect(obj.pet_map).to be_instance_of(Hash)
7474
pet = obj.pet_map['pet']
@@ -101,8 +101,8 @@ def self.openapi_types
101101
it 'works for #to_hash' do
102102
obj.build_from_hash(data)
103103
expect_data = data.dup
104-
expect_data[:boolean_true_arr].map! {true}
105-
expect_data[:boolean_false_arr].map! {false}
104+
expect_data[:boolean_true_arr].map! { true }
105+
expect_data[:boolean_false_arr].map! { false }
106106
expect(obj.to_hash).to eq(expect_data)
107107
end
108108
end

samples/client/petstore/ruby/spec/pet_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

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

samples/client/petstore/ruby/spec/spec_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def prepare_pet(pet_api)
114114
pet = Petstore::Pet.new('id' => pet_id, 'name' => "RUBY UNIT TESTING", 'photo_urls' => 'photo url',
115115
'category' => category, 'tags' => [tag], 'status' => 'pending')
116116
pet_api.add_pet(pet)
117-
return pet_id
117+
pet_id
118118
end
119119

120120
# create a random order, return its id
@@ -127,7 +127,7 @@ def prepare_store(store_api)
127127
"status" => "placed",
128128
"complete" => false)
129129
store_api.place_order(order)
130-
return order_id
130+
order_id
131131
end
132132

133133
# A random string to tack onto stuff to ensure we're not seeing
@@ -141,7 +141,7 @@ def serialize_json(o)
141141

142142
# helper method to deserialize json string back to object
143143
def deserialize_json(s, type)
144-
headers = {'Content-Type' => 'application/json'}
144+
headers = { 'Content-Type' => 'application/json' }
145145
response = double('response', headers: headers, body: s)
146146
API_CLIENT.deserialize(response, type)
147147
end

0 commit comments

Comments
 (0)