From d54877b5d375e8234f010beed871b6ab14614708 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 10 May 2016 14:18:06 +0800 Subject: [PATCH 1/2] add ruby spec for configuration, api client, replace should with expect --- .../io/swagger/codegen/DefaultGenerator.java | 11 +- .../codegen/languages/RubyClientCodegen.java | 9 +- .../resources/ruby/api_client_spec.mustache | 273 ++++++++++++++++++ .../src/main/resources/ruby/api_test.mustache | 8 +- .../ruby/configuration_spec.mustache | 25 ++ .../main/resources/ruby/model_test.mustache | 8 +- .../src/main/resources/ruby/rspec.mustache | 2 + .../main/resources/ruby/spec_helper.mustache | 99 +++++++ samples/client/petstore/ruby/.rspec | 2 + samples/client/petstore/ruby/README.md | 2 +- .../ruby/spec/models/animal_farm_spec.rb | 40 +++ .../ruby/spec/models/enum_class_spec.rb | 40 +++ .../ruby/spec/models/enum_test_spec.rb | 58 ++++ .../petstore/ruby/spec/models/pet_spec.rb | 10 + .../client/petstore/ruby/spec/spec_helper.rb | 158 +++++----- 15 files changed, 660 insertions(+), 85 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache create mode 100644 modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache create mode 100644 modules/swagger-codegen/src/main/resources/ruby/rspec.mustache create mode 100644 modules/swagger-codegen/src/main/resources/ruby/spec_helper.mustache create mode 100644 samples/client/petstore/ruby/.rspec create mode 100644 samples/client/petstore/ruby/spec/models/animal_farm_spec.rb create mode 100644 samples/client/petstore/ruby/spec/models/enum_class_spec.rb create mode 100644 samples/client/petstore/ruby/spec/models/enum_test_spec.rb diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index b5a920004c8..8be354df1ee 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -286,8 +286,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { for (String templateName : config.modelTestTemplateFiles().keySet()) { String suffix = config.modelTestTemplateFiles().get(templateName); String filename = config.modelTestFileFolder() + File.separator + config.toModelTestFilename(name) + suffix; - if (!config.shouldOverwrite(filename)) { - LOGGER.info("Skipped overwriting " + filename); + // do not overwrite test file that already exists + if (new File(filename).exists()) { + LOGGER.info("File exists. Skipped overwriting " + filename); continue; } String templateFile = getFullTemplateFile(config, templateName); @@ -419,11 +420,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { // to generate api test files for (String templateName : config.apiTestTemplateFiles().keySet()) { String filename = config.apiTestFilename(templateName, tag); - if (!config.shouldOverwrite(filename) && new File(filename).exists()) { - LOGGER.info("Skipped overwriting " + filename); + // do not overwrite test file that already exists + if (new File(filename).exists()) { + LOGGER.info("File exists. Skipped overwriting " + filename); continue; } - String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Template tmpl = Mustache.compiler() diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index aeb8e524e9d..14244b5661d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -224,6 +224,10 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); + writeOptional(outputFolder, new SupportingFile("rspec.mustache", "", ".rspec")); + writeOptional(outputFolder, new SupportingFile("spec_helper.mustache", specFolder, "spec_helper.rb")); + writeOptional(outputFolder, new SupportingFile("configuration_spec.mustache", specFolder, "configuration_spec.rb")); + writeOptional(outputFolder, new SupportingFile("api_client_spec.mustache", specFolder, "api_client_spec.rb")); } @Override @@ -644,10 +648,11 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { this.gemAuthorEmail = gemAuthorEmail; } - @Override public boolean shouldOverwrite(String filename) { // skip spec file as the file might have been updated with new test cases - return super.shouldOverwrite(filename) && !filename.endsWith("_spec.rb"); + return !(skipOverwrite && new File(filename).exists()); + // + //return super.shouldOverwrite(filename) && !filename.endsWith("_spec.rb"); } } diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache new file mode 100644 index 00000000000..1ed497da21e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache @@ -0,0 +1,273 @@ +require 'spec_helper' + +describe {{moduleName}}::ApiClient do + context 'initialization' do + context 'URL stuff' do + context 'host' do + it 'removes http from host' do + {{moduleName}}.configure { |c| c.host = 'http://example.com' } + expect({{moduleName}}::Configuration.default.host).to eq('example.com') + end + + it 'removes https from host' do + {{moduleName}}.configure { |c| c.host = 'https://wookiee.com' } + expect({{moduleName}}::ApiClient.default.config.host).to eq('wookiee.com') + end + + it 'removes trailing path from host' do + {{moduleName}}.configure { |c| c.host = 'hobo.com/v4' } + expect({{moduleName}}::Configuration.default.host).to eq('hobo.com') + end + end + + context 'base_path' do + it "prepends a slash to base_path" do + {{moduleName}}.configure { |c| c.base_path = 'v4/dog' } + expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog') + end + + it "doesn't prepend a slash if one is already there" do + {{moduleName}}.configure { |c| c.base_path = '/v4/dog' } + expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog') + end + + it "ends up as a blank string if nil" do + {{moduleName}}.configure { |c| c.base_path = nil } + expect({{moduleName}}::Configuration.default.base_path).to eq('') + end + end + end + end + + describe "#update_params_for_auth!" do + it "sets header api-key parameter with prefix" do + {{moduleName}}.configure do |c| + c.api_key_prefix['api_key'] = 'PREFIX' + c.api_key['api_key'] = 'special-key' + end + + api_client = {{moduleName}}::ApiClient.new + + config2 = {{moduleName}}::Configuration.new do |c| + c.api_key_prefix['api_key'] = 'PREFIX2' + c.api_key['api_key'] = 'special-key2' + end + api_client2 = {{moduleName}}::ApiClient.new(config2) + + auth_names = ['api_key', 'unknown'] + + 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(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(query_params).to eq({}) + end + + it "sets header api-key parameter without prefix" do + {{moduleName}}.configure do |c| + c.api_key_prefix['api_key'] = nil + c.api_key['api_key'] = 'special-key' + end + + api_client = {{moduleName}}::ApiClient.new + + header_params = {} + 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(query_params).to eq({}) + end + end + + describe "timeout in #build_request" do + let(:config) { {{moduleName}}::Configuration.new } + let(:api_client) { {{moduleName}}::ApiClient.new(config) } + + it "defaults to 0" do + expect({{moduleName}}::Configuration.default.timeout).to eq(0) + expect(config.timeout).to eq(0) + + request = api_client.build_request(:get, '/test') + expect(request.options[:timeout]).to eq(0) + end + + it "can be customized" do + config.timeout = 100 + request = api_client.build_request(:get, '/test') + expect(request.options[:timeout]).to eq(100) + end + end + + describe "#deserialize" do + it "handles Array" do + api_client = {{moduleName}}::ApiClient.new + headers = {'Content-Type' => 'application/json'} + response = double('response', headers: headers, body: '[12, 34]') + data = api_client.deserialize(response, 'Array') + expect(data).to be_instance_of(Array) + expect(data).to eq([12, 34]) + end + + it "handles Array>" do + api_client = {{moduleName}}::ApiClient.new + headers = {'Content-Type' => 'application/json'} + response = double('response', headers: headers, body: '[[12, 34], [56]]') + data = api_client.deserialize(response, 'Array>') + expect(data).to be_instance_of(Array) + expect(data).to eq([[12, 34], [56]]) + end + + it "handles Hash" do + api_client = {{moduleName}}::ApiClient.new + headers = {'Content-Type' => 'application/json'} + response = double('response', headers: headers, body: '{"message": "Hello"}') + data = api_client.deserialize(response, 'Hash') + expect(data).to be_instance_of(Hash) + expect(data).to eq({:message => 'Hello'}) + end + + it "handles Hash" do + api_client = {{moduleName}}::ApiClient.new + headers = {'Content-Type' => 'application/json'} + response = double('response', headers: headers, body: '{"pet": {"id": 1}}') + data = api_client.deserialize(response, 'Hash') + expect(data).to be_instance_of(Hash) + expect(data.keys).to eq([:pet]) + + pet = data[:pet] + expect(pet).to be_instance_of({{moduleName}}::Pet) + expect(pet.id).to eq(1) + end + + it "handles Hash>" do + api_client = {{moduleName}}::ApiClient.new + 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_instance_of(Hash) + expect(result.keys).to match_array([:data]) + + data = result[:data] + expect(data).to be_instance_of(Hash) + expect(data.keys).to match_array([:pet]) + + pet = data[:pet] + expect(pet).to be_instance_of({{moduleName}}::Pet) + expect(pet.id).to eq(1) + end + end + + describe "#object_to_hash" do + it "ignores nils and includes empty arrays" do + api_client = {{moduleName}}::ApiClient.new + pet = {{moduleName}}::Pet.new + pet.id = 1 + pet.name = '' + pet.status = nil + pet.photo_urls = nil + pet.tags = [] + expected = {id: 1, name: '', tags: []} + expect(api_client.object_to_hash(pet)).to eq(expected) + end + end + + describe "#build_collection_param" do + let(:param) { ['aa', 'bb', 'cc'] } + let(:api_client) { {{moduleName}}::ApiClient.new } + + it "works for csv" do + expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc') + end + + it "works for ssv" do + expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc') + end + + it "works for tsv" do + expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc") + end + + it "works for pipes" do + expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc') + end + + it "works for multi" do + expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc']) + end + + it "fails for invalid collection format" do + expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID') + end + end + + describe "#json_mime?" do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it "works" do + expect(api_client.json_mime?(nil)).to eq false + expect(api_client.json_mime?('')).to eq false + + expect(api_client.json_mime?('application/json')).to eq true + expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true + expect(api_client.json_mime?('APPLICATION/JSON')).to eq true + + expect(api_client.json_mime?('application/xml')).to eq false + expect(api_client.json_mime?('text/plain')).to eq false + expect(api_client.json_mime?('application/jsonp')).to eq false + end + end + + describe "#select_header_accept" do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it "works" do + expect(api_client.select_header_accept(nil)).to be_nil + expect(api_client.select_header_accept([])).to be_nil + + expect(api_client.select_header_accept(['application/json'])).to eq('application/json') + expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') + expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') + + expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml') + expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml') + end + end + + describe "#select_header_content_type" do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it "works" do + expect(api_client.select_header_content_type(nil)).to eq('application/json') + expect(api_client.select_header_content_type([])).to eq('application/json') + + expect(api_client.select_header_content_type(['application/json'])).to eq('application/json') + expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') + expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') + expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml') + expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain') + end + end + + describe "#sanitize_filename" do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it "works" do + expect(api_client.sanitize_filename('sun')).to eq('sun') + expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif') + end + end +end diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_test.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_test.mustache index 7e95c2d6446..d28f29e0c3a 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_test.mustache @@ -20,7 +20,7 @@ require 'json' describe 'test an instance of {{classname}}' do it 'should create an instact of {{classname}}' do - @instance.should be_a({{moduleName}}::{{classname}}) + expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) end end @@ -34,11 +34,7 @@ require 'json' {{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] describe '{{operationId}} test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache b/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache new file mode 100644 index 00000000000..4c23a067175 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe {{moduleName}}::Configuration do + let(:config) { {{moduleName}}::Configuration.default } + + before(:each) do + {{moduleName}}.configure do |c| + c.host = 'petstore.swagger.io' + c.base_path = 'v2' + end + end + + describe '#base_url' do + it 'should have the default value' do + expect(config.base_url).to eq('http://petstore.swagger.io/v2') + end + + it 'should remove trailing slashes' do + [nil, '', '/', '//'].each do |base_path| + config.base_path = base_path + expect(config.base_url).to eq('http://petstore.swagger.io') + end + end + end +end diff --git a/modules/swagger-codegen/src/main/resources/ruby/model_test.mustache b/modules/swagger-codegen/src/main/resources/ruby/model_test.mustache index f5204447975..305a10d6467 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/model_test.mustache @@ -21,17 +21,13 @@ require 'date' describe 'test an instance of {{classname}}' do it 'should create an instact of {{classname}}' do - @instance.should be_a({{moduleName}}::{{classname}}) + expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) end end {{#vars}} describe 'test attribute "{{{name}}}"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/modules/swagger-codegen/src/main/resources/ruby/rspec.mustache b/modules/swagger-codegen/src/main/resources/ruby/rspec.mustache new file mode 100644 index 00000000000..83e16f80447 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/rspec.mustache @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/modules/swagger-codegen/src/main/resources/ruby/spec_helper.mustache b/modules/swagger-codegen/src/main/resources/ruby/spec_helper.mustache new file mode 100644 index 00000000000..bc4187c3378 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/spec_helper.mustache @@ -0,0 +1,99 @@ +# load the gem +require '{{{gemName}}}' + +# The following was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/samples/client/petstore/ruby/.rspec b/samples/client/petstore/ruby/.rspec new file mode 100644 index 00000000000..83e16f80447 --- /dev/null +++ b/samples/client/petstore/ruby/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md index 4f573b6f04a..58fad311c43 100644 --- a/samples/client/petstore/ruby/README.md +++ b/samples/client/petstore/ruby/README.md @@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/ - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-06T16:33:11.754+08:00 +- Build date: 2016-05-10T14:06:27.504+08:00 - Build package: class io.swagger.codegen.languages.RubyClientCodegen ## Installation diff --git a/samples/client/petstore/ruby/spec/models/animal_farm_spec.rb b/samples/client/petstore/ruby/spec/models/animal_farm_spec.rb new file mode 100644 index 00000000000..016b86fd8af --- /dev/null +++ b/samples/client/petstore/ruby/spec/models/animal_farm_spec.rb @@ -0,0 +1,40 @@ +=begin +Swagger Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. + +OpenAPI spec version: 1.0.0 +Contact: apiteam@swagger.io +Generated by: https://github.com/swagger-api/swagger-codegen.git + +License: Apache 2.0 +http://www.apache.org/licenses/LICENSE-2.0.html + +Terms of Service: http://swagger.io/terms/ + +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for Petstore::AnimalFarm +# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen) +# Please update as you see appropriate +describe 'AnimalFarm' do + before do + # run before each test + @instance = Petstore::AnimalFarm.new + end + + after do + # run after each test + end + + describe 'test an instance of AnimalFarm' do + it 'should create an instact of AnimalFarm' do + expect(@instance).to be_instance_of(Petstore::AnimalFarm) + end + end +end + diff --git a/samples/client/petstore/ruby/spec/models/enum_class_spec.rb b/samples/client/petstore/ruby/spec/models/enum_class_spec.rb new file mode 100644 index 00000000000..b8610d74a1b --- /dev/null +++ b/samples/client/petstore/ruby/spec/models/enum_class_spec.rb @@ -0,0 +1,40 @@ +=begin +Swagger Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. + +OpenAPI spec version: 1.0.0 +Contact: apiteam@swagger.io +Generated by: https://github.com/swagger-api/swagger-codegen.git + +License: Apache 2.0 +http://www.apache.org/licenses/LICENSE-2.0.html + +Terms of Service: http://swagger.io/terms/ + +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for Petstore::EnumClass +# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen) +# Please update as you see appropriate +describe 'EnumClass' do + before do + # run before each test + @instance = Petstore::EnumClass.new + end + + after do + # run after each test + end + + describe 'test an instance of EnumClass' do + it 'should create an instact of EnumClass' do + expect(@instance).to be_instance_of(Petstore::EnumClass) + end + end +end + diff --git a/samples/client/petstore/ruby/spec/models/enum_test_spec.rb b/samples/client/petstore/ruby/spec/models/enum_test_spec.rb new file mode 100644 index 00000000000..91941d8a50d --- /dev/null +++ b/samples/client/petstore/ruby/spec/models/enum_test_spec.rb @@ -0,0 +1,58 @@ +=begin +Swagger Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. + +OpenAPI spec version: 1.0.0 +Contact: apiteam@swagger.io +Generated by: https://github.com/swagger-api/swagger-codegen.git + +License: Apache 2.0 +http://www.apache.org/licenses/LICENSE-2.0.html + +Terms of Service: http://swagger.io/terms/ + +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for Petstore::EnumTest +# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen) +# Please update as you see appropriate +describe 'EnumTest' do + before do + # run before each test + @instance = Petstore::EnumTest.new + end + + after do + # run after each test + end + + describe 'test an instance of EnumTest' do + it 'should create an instact of EnumTest' do + expect(@instance).to be_instance_of(Petstore::EnumTest) + end + end + describe 'test attribute "enum_string"' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + + describe 'test attribute "enum_integer"' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + + describe 'test attribute "enum_number"' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +end + diff --git a/samples/client/petstore/ruby/spec/models/pet_spec.rb b/samples/client/petstore/ruby/spec/models/pet_spec.rb index 96ced2cd366..baf3cdf008d 100644 --- a/samples/client/petstore/ruby/spec/models/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/models/pet_spec.rb @@ -25,10 +25,20 @@ describe 'Pet' do before do # run before each test @instance = Petstore::Pet.new + + @pet_api = Petstore::PetApi.new(API_CLIENT) + @pet_id = prepare_pet(@pet_api) end after do # run after each test + # remove the testing pet + begin + @pet_api.delete_pet(@pet_id) + rescue Petstore::ApiError => e + # ignore ApiError 404 (Not Found) + raise e if e.code != 404 + end end describe 'test an instance of Pet' do diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index 50702c439b7..0bba600ba45 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -1,71 +1,99 @@ -require 'rubygems' -require 'bundler/setup' -require 'petstore' -require 'vcr' -require 'typhoeus' -require 'json' -require 'yaml' -require 'rspec' - +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - # some (optional) config here - config.expect_with :rspec do |c| - c.syntax = :should + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - config.mock_with :rspec do |c| - c.syntax = :should + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end end +require 'SwaggerClient' -WebMock.allow_net_connect! if defined? WebMock - -def help - puts "\nOh noes! You gotta stuff your swagger credentials in ~/.swagger.yml like so:\n\n" - puts "api_key: '12345abcdefg'" - puts "username: 'fumanchu'" - puts "password: 'kalamazoo'\n\n" - exit -end - -# no longer reading credentials (not used) from file (20150413) -# Parse ~/.swagger.yml for user credentials -#begin -# CREDENTIALS = YAML::load_file(File.join(ENV['HOME'], ".swagger.yml")).symbolize_keys -#rescue -# help -#end - -API_CLIENT = Petstore::ApiClient.new(Petstore::Configuration.new) - -def random_id - rand(1000000) + 20000 -end - -# create a random pet, return its id -def prepare_pet(pet_api) - pet_id = random_id - category = Petstore::Category.new('id' => 20002, 'name' => 'category test') - tag = Petstore::Tag.new('id' => 30002, 'name' => 'tag test') - 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 -end - -# create a random order, return its id -def prepare_store(store_api) - order_id = 5 - order = Petstore::Order.new("id" => order_id, - "petId" => 123, - "quantity" => 789, - "shipDate" => "2015-04-06T23:42:01.678Z", - "status" => "placed", - "complete" => false) - store_api.place_order(order) - return order_id -end - -# A random string to tack onto stuff to ensure we're not seeing -# data from a previous test run -RAND = ("a".."z").to_a.sample(8).join From 31daa2b092c2fe025414ae6f755a97a8fd8441c0 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 10 May 2016 14:56:14 +0800 Subject: [PATCH 2/2] update ruby test files --- .../codegen/languages/RubyClientCodegen.java | 2 + .../resources/ruby/base_object_spec.mustache | 109 ++++++++++++++++++ samples/client/petstore/ruby/README.md | 2 +- .../petstore/ruby/spec/api/fake_api_spec.rb | 12 +- .../petstore/ruby/spec/api/pet_api_spec.rb | 50 ++------ .../petstore/ruby/spec/api/store_api_spec.rb | 28 +---- .../petstore/ruby/spec/api/user_api_spec.rb | 52 ++------- .../petstore/ruby/spec/base_object_spec.rb | 49 ++++---- .../petstore/ruby/spec/models/animal_spec.rb | 8 +- .../ruby/spec/models/api_response_spec.rb | 20 +--- .../petstore/ruby/spec/models/cat_spec.rb | 14 +-- .../ruby/spec/models/category_spec.rb | 14 +-- .../petstore/ruby/spec/models/dog_spec.rb | 18 +-- .../ruby/spec/models/format_test_spec.rb | 80 +++---------- .../spec/models/inline_response_200_spec.rb | 100 ---------------- .../spec/models/model_200_response_spec.rb | 8 +- .../ruby/spec/models/model_return_spec.rb | 8 +- .../petstore/ruby/spec/models/name_spec.rb | 20 +--- .../petstore/ruby/spec/models/order_spec.rb | 38 ++---- .../petstore/ruby/spec/models/pet_spec.rb | 48 ++------ .../spec/models/special_model_name_spec.rb | 8 +- .../petstore/ruby/spec/models/tag_spec.rb | 14 +-- .../petstore/ruby/spec/models/user_spec.rb | 50 ++------ samples/client/petstore/ruby/spec/pet_spec.rb | 10 -- samples/client/petstore/ruby/spec/spec.opts | 4 - .../client/petstore/ruby/spec/spec_helper.rb | 52 ++++++++- 26 files changed, 283 insertions(+), 535 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/ruby/base_object_spec.mustache delete mode 100644 samples/client/petstore/ruby/spec/models/inline_response_200_spec.rb delete mode 100644 samples/client/petstore/ruby/spec/spec.opts diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index 14244b5661d..6655a28f1d5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -228,6 +228,8 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { writeOptional(outputFolder, new SupportingFile("spec_helper.mustache", specFolder, "spec_helper.rb")); writeOptional(outputFolder, new SupportingFile("configuration_spec.mustache", specFolder, "configuration_spec.rb")); writeOptional(outputFolder, new SupportingFile("api_client_spec.mustache", specFolder, "api_client_spec.rb")); + // not including base object test as the moment as not all API has model + //writeOptional(outputFolder, new SupportingFile("base_object_spec.mustache", specFolder, "base_object_spec.rb")); } @Override diff --git a/modules/swagger-codegen/src/main/resources/ruby/base_object_spec.mustache b/modules/swagger-codegen/src/main/resources/ruby/base_object_spec.mustache new file mode 100644 index 00000000000..7376cd1e84d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/base_object_spec.mustache @@ -0,0 +1,109 @@ +require 'spec_helper' + +class ArrayMapObject < Petstore::Category + attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map, :boolean_true_arr, :boolean_false_arr + + def self.attribute_map + { + :int_arr => :int_arr, + :pet_arr => :pet_arr, + :int_map => :int_map, + :pet_map => :pet_map, + :int_arr_map => :int_arr_map, + :pet_arr_map => :pet_arr_map, + :boolean_true_arr => :boolean_true_arr, + :boolean_false_arr => :boolean_false_arr, + } + end + + def self.swagger_types + { + :int_arr => :'Array', + :pet_arr => :'Array', + :int_map => :'Hash', + :pet_map => :'Hash', + :int_arr_map => :'Hash>', + :pet_arr_map => :'Hash>', + :boolean_true_arr => :'Array', + :boolean_false_arr => :'Array', + } + end +end + +describe 'BaseObject' do + describe 'boolean values' do + let(:obj) { Petstore::Cat.new({declawed: false}) } + + it 'should have values set' do + expect(obj.declawed).not_to be_nil + expect(obj.declawed).to eq(false) + end + end + + describe 'array and map properties' 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'}]}, + boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"], + boolean_false_arr: [false, "", 0, "0", "f", nil, "null"], + } + end + + it 'works for #build_from_hash' do + obj.build_from_hash(data) + + expect(obj.int_arr).to match_array([123, 456]) + + expect(obj.pet_arr).to be_instance_of(Array) + expect(obj.pet_arr).to be_instance_of(1) + + pet = obj.pet_arr.first + expect(pet).to be_instance_of(Petstore::Pet) + 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.pet_map).to be_instance_of(Hash) + pet = obj.pet_map['pet'] + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') + + expect(obj.int_arr_map).to be_instance_of(Hash) + arr = obj.int_arr_map['int_arr'] + expect(arr).to match_array([123, 456]) + + expect(obj.pet_arr_map).to be_instance_of(Hash) + arr = obj.pet_arr_map['pet_arr'] + expect(arr).to be_instance_of(Array) + expect(arr.size).to eq(1) + pet = arr.first + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') + + expect(obj.boolean_true_arr).to be_instance_of(Array) + obj.boolean_true_arr.each do |b| + expect(b).to eq(true) + end + + expect(obj.boolean_false_arr).to be_instance_of(Array) + obj.boolean_false_arr.each do |b| + expect(b).to eq(false) + end + end + + 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(obj.to_hash).to eq(expect_data) + end + end +end diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md index 58fad311c43..cdecd2e6cca 100644 --- a/samples/client/petstore/ruby/README.md +++ b/samples/client/petstore/ruby/README.md @@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/ - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-10T14:06:27.504+08:00 +- Build date: 2016-05-10T14:47:49.265+08:00 - Build package: class io.swagger.codegen.languages.RubyClientCodegen ## Installation diff --git a/samples/client/petstore/ruby/spec/api/fake_api_spec.rb b/samples/client/petstore/ruby/spec/api/fake_api_spec.rb index 84929b8115c..a30c9d9c7a7 100644 --- a/samples/client/petstore/ruby/spec/api/fake_api_spec.rb +++ b/samples/client/petstore/ruby/spec/api/fake_api_spec.rb @@ -32,13 +32,13 @@ describe 'FakeApi' do describe 'test an instance of FakeApi' do it 'should create an instact of FakeApi' do - @instance.should be_a(Petstore::FakeApi) + expect(@instance).to be_instance_of(Petstore::FakeApi) end end # unit tests for test_endpoint_parameters - # Fake endpoint for testing various parameters - # Fake endpoint for testing various parameters + # Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + # Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # @param number None # @param double None # @param string None @@ -55,11 +55,7 @@ describe 'FakeApi' do # @return [nil] describe 'test_endpoint_parameters test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/api/pet_api_spec.rb b/samples/client/petstore/ruby/spec/api/pet_api_spec.rb index e903362291b..72a6e8209c5 100644 --- a/samples/client/petstore/ruby/spec/api/pet_api_spec.rb +++ b/samples/client/petstore/ruby/spec/api/pet_api_spec.rb @@ -32,7 +32,7 @@ describe 'PetApi' do describe 'test an instance of PetApi' do it 'should create an instact of PetApi' do - @instance.should be_a(Petstore::PetApi) + expect(@instance).to be_instance_of(Petstore::PetApi) end end @@ -44,11 +44,7 @@ describe 'PetApi' do # @return [nil] describe 'add_pet test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -61,11 +57,7 @@ describe 'PetApi' do # @return [nil] describe 'delete_pet test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -77,11 +69,7 @@ describe 'PetApi' do # @return [Array] describe 'find_pets_by_status test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -93,11 +81,7 @@ describe 'PetApi' do # @return [Array] describe 'find_pets_by_tags test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -109,11 +93,7 @@ describe 'PetApi' do # @return [Pet] describe 'get_pet_by_id test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -125,11 +105,7 @@ describe 'PetApi' do # @return [nil] describe 'update_pet test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -143,11 +119,7 @@ describe 'PetApi' do # @return [nil] describe 'update_pet_with_form test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -161,11 +133,7 @@ describe 'PetApi' do # @return [ApiResponse] describe 'upload_file test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/api/store_api_spec.rb b/samples/client/petstore/ruby/spec/api/store_api_spec.rb index 015d1d8e39d..428c9c5f282 100644 --- a/samples/client/petstore/ruby/spec/api/store_api_spec.rb +++ b/samples/client/petstore/ruby/spec/api/store_api_spec.rb @@ -32,7 +32,7 @@ describe 'StoreApi' do describe 'test an instance of StoreApi' do it 'should create an instact of StoreApi' do - @instance.should be_a(Petstore::StoreApi) + expect(@instance).to be_instance_of(Petstore::StoreApi) end end @@ -44,11 +44,7 @@ describe 'StoreApi' do # @return [nil] describe 'delete_order test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -59,27 +55,19 @@ describe 'StoreApi' do # @return [Hash] describe 'get_inventory test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end # unit tests for get_order_by_id # Find purchase order by ID - # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # @param order_id ID of pet that needs to be fetched # @param [Hash] opts the optional parameters # @return [Order] describe 'get_order_by_id test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -91,11 +79,7 @@ describe 'StoreApi' do # @return [Order] describe 'place_order test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/api/user_api_spec.rb b/samples/client/petstore/ruby/spec/api/user_api_spec.rb index 272980a6db0..37194b3c158 100644 --- a/samples/client/petstore/ruby/spec/api/user_api_spec.rb +++ b/samples/client/petstore/ruby/spec/api/user_api_spec.rb @@ -32,7 +32,7 @@ describe 'UserApi' do describe 'test an instance of UserApi' do it 'should create an instact of UserApi' do - @instance.should be_a(Petstore::UserApi) + expect(@instance).to be_instance_of(Petstore::UserApi) end end @@ -44,11 +44,7 @@ describe 'UserApi' do # @return [nil] describe 'create_user test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -60,11 +56,7 @@ describe 'UserApi' do # @return [nil] describe 'create_users_with_array_input test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -76,11 +68,7 @@ describe 'UserApi' do # @return [nil] describe 'create_users_with_list_input test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -92,27 +80,19 @@ describe 'UserApi' do # @return [nil] describe 'delete_user test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end # unit tests for get_user_by_name # Get user by user name # - # @param username The name that needs to be fetched. Use user1 for testing. + # @param username The name that needs to be fetched. Use user1 for testing. # @param [Hash] opts the optional parameters # @return [User] describe 'get_user_by_name test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -125,11 +105,7 @@ describe 'UserApi' do # @return [String] describe 'login_user test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -140,11 +116,7 @@ describe 'UserApi' do # @return [nil] describe 'logout_user test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end @@ -157,11 +129,7 @@ describe 'UserApi' do # @return [nil] describe 'update_user test' do it "should work" do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers 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 a315d52276b..5b84351f7b8 100644 --- a/samples/client/petstore/ruby/spec/base_object_spec.rb +++ b/samples/client/petstore/ruby/spec/base_object_spec.rb @@ -35,8 +35,8 @@ describe 'BaseObject' do let(:obj) { Petstore::Cat.new({declawed: false}) } it 'should have values set' do - obj.declawed.should_not eq nil - obj.declawed.should eq false + expect(obj.declawed).not_to be_nil + expect(obj.declawed).to eq(false) end end @@ -58,42 +58,43 @@ describe 'BaseObject' do it 'works for #build_from_hash' do obj.build_from_hash(data) - obj.int_arr.should == [123, 456] + expect(obj.int_arr).to match_array([123, 456]) + + expect(obj.pet_arr).to be_instance_of(Array) + expect(obj.pet_arr.size).to eq(1) - obj.pet_arr.should be_a(Array) - obj.pet_arr.size.should == 1 pet = obj.pet_arr.first - pet.should be_a(Petstore::Pet) - pet.name.should == 'Kitty' + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') - obj.int_map.should be_a(Hash) - obj.int_map.should == {'int' => 123} + expect(obj.int_map).to be_instance_of(Hash) + expect(obj.int_map).to eq({'int' => 123}) - obj.pet_map.should be_a(Hash) + expect(obj.pet_map).to be_instance_of(Hash) pet = obj.pet_map['pet'] - pet.should be_a(Petstore::Pet) - pet.name.should == 'Kitty' + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') - obj.int_arr_map.should be_a(Hash) + expect(obj.int_arr_map).to be_instance_of(Hash) arr = obj.int_arr_map['int_arr'] - arr.should == [123, 456] + expect(arr).to match_array([123, 456]) - obj.pet_arr_map.should be_a(Hash) + expect(obj.pet_arr_map).to be_instance_of(Hash) arr = obj.pet_arr_map['pet_arr'] - arr.should be_a(Array) - arr.size.should == 1 + expect(arr).to be_instance_of(Array) + expect(arr.size).to eq(1) pet = arr.first - pet.should be_a(Petstore::Pet) - pet.name.should == 'Kitty' + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') - obj.boolean_true_arr.should be_a(Array) + expect(obj.boolean_true_arr).to be_instance_of(Array) obj.boolean_true_arr.each do |b| - b.should eq true + expect(b).to eq(true) end - obj.boolean_false_arr.should be_a(Array) + expect(obj.boolean_false_arr).to be_instance_of(Array) obj.boolean_false_arr.each do |b| - b.should eq false + expect(b).to eq(false) end end @@ -102,7 +103,7 @@ describe 'BaseObject' do expect_data = data.dup expect_data[:boolean_true_arr].map! {true} expect_data[:boolean_false_arr].map! {false} - obj.to_hash.should == expect_data + expect(obj.to_hash).to eq(expect_data) end end end diff --git a/samples/client/petstore/ruby/spec/models/animal_spec.rb b/samples/client/petstore/ruby/spec/models/animal_spec.rb index e35b12411be..3f98b0f7b84 100644 --- a/samples/client/petstore/ruby/spec/models/animal_spec.rb +++ b/samples/client/petstore/ruby/spec/models/animal_spec.rb @@ -33,16 +33,12 @@ describe 'Animal' do describe 'test an instance of Animal' do it 'should create an instact of Animal' do - @instance.should be_a(Petstore::Animal) + expect(@instance).to be_instance_of(Petstore::Animal) end end describe 'test attribute "class_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/api_response_spec.rb b/samples/client/petstore/ruby/spec/models/api_response_spec.rb index 279d8cb0aa5..67b0cbe1a03 100644 --- a/samples/client/petstore/ruby/spec/models/api_response_spec.rb +++ b/samples/client/petstore/ruby/spec/models/api_response_spec.rb @@ -33,36 +33,24 @@ describe 'ApiResponse' do describe 'test an instance of ApiResponse' do it 'should create an instact of ApiResponse' do - @instance.should be_a(Petstore::ApiResponse) + expect(@instance).to be_instance_of(Petstore::ApiResponse) end end describe 'test attribute "code"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "type"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "message"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/cat_spec.rb b/samples/client/petstore/ruby/spec/models/cat_spec.rb index e9b20d57eb0..97ae668ea3b 100644 --- a/samples/client/petstore/ruby/spec/models/cat_spec.rb +++ b/samples/client/petstore/ruby/spec/models/cat_spec.rb @@ -33,26 +33,18 @@ describe 'Cat' do describe 'test an instance of Cat' do it 'should create an instact of Cat' do - @instance.should be_a(Petstore::Cat) + expect(@instance).to be_instance_of(Petstore::Cat) end end describe 'test attribute "class_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "declawed"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/category_spec.rb b/samples/client/petstore/ruby/spec/models/category_spec.rb index 0e7001053f7..1481358afdc 100644 --- a/samples/client/petstore/ruby/spec/models/category_spec.rb +++ b/samples/client/petstore/ruby/spec/models/category_spec.rb @@ -33,26 +33,18 @@ describe 'Category' do describe 'test an instance of Category' do it 'should create an instact of Category' do - @instance.should be_a(Petstore::Category) + expect(@instance).to be_instance_of(Petstore::Category) end end describe 'test attribute "id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/dog_spec.rb b/samples/client/petstore/ruby/spec/models/dog_spec.rb index b319d72b80a..e3eb4be12fc 100644 --- a/samples/client/petstore/ruby/spec/models/dog_spec.rb +++ b/samples/client/petstore/ruby/spec/models/dog_spec.rb @@ -33,26 +33,18 @@ describe 'Dog' do describe 'test an instance of Dog' do it 'should create an instact of Dog' do - @instance.should be_a(Petstore::Dog) + expect(@instance).to be_instance_of(Petstore::Dog) end end - describe 'test attribute "breed"' do + describe 'test attribute "class_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end - describe 'test attribute "class_name"' do + describe 'test attribute "breed"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/format_test_spec.rb b/samples/client/petstore/ruby/spec/models/format_test_spec.rb index 50b2980d17b..e7a81fe537c 100644 --- a/samples/client/petstore/ruby/spec/models/format_test_spec.rb +++ b/samples/client/petstore/ruby/spec/models/format_test_spec.rb @@ -33,136 +33,84 @@ describe 'FormatTest' do describe 'test an instance of FormatTest' do it 'should create an instact of FormatTest' do - @instance.should be_a(Petstore::FormatTest) + expect(@instance).to be_instance_of(Petstore::FormatTest) end end describe 'test attribute "integer"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "int32"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "int64"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "number"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "float"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "double"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "string"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "byte"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "binary"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "date"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "date_time"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "uuid"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "password"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/inline_response_200_spec.rb b/samples/client/petstore/ruby/spec/models/inline_response_200_spec.rb deleted file mode 100644 index 36a4da3baaa..00000000000 --- a/samples/client/petstore/ruby/spec/models/inline_response_200_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -=begin -Swagger Petstore - -This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters - -OpenAPI spec version: 1.0.0 -Contact: apiteam@swagger.io -Generated by: https://github.com/swagger-api/swagger-codegen.git - -License: Apache 2.0 -http://www.apache.org/licenses/LICENSE-2.0.html - -Terms of Service: http://swagger.io/terms/ - -=end - -require 'spec_helper' -require 'json' -require 'date' - -# Unit tests for Petstore::InlineResponse200 -# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen) -# Please update as you see appropriate -describe 'InlineResponse200', pending: "Original spec does not have InlineResponse200 and we'll renable this after updating Petstore server" do - before do - # run before each test - @instance = Petstore::InlineResponse200.new - end - - after do - # run after each test - end - - describe 'test an instance of InlineResponse200' do - it 'should create an instact of InlineResponse200' do - @instance.should be_a(Petstore::InlineResponse200) - end - end - describe 'test attribute "tags"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - - describe 'test attribute "id"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - - describe 'test attribute "category"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - - describe 'test attribute "status"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - - describe 'test attribute "name"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - - describe 'test attribute "photo_urls"' do - it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == - end - end - -end - diff --git a/samples/client/petstore/ruby/spec/models/model_200_response_spec.rb b/samples/client/petstore/ruby/spec/models/model_200_response_spec.rb index 88045611d9c..8b8879105d0 100644 --- a/samples/client/petstore/ruby/spec/models/model_200_response_spec.rb +++ b/samples/client/petstore/ruby/spec/models/model_200_response_spec.rb @@ -33,16 +33,12 @@ describe 'Model200Response' do describe 'test an instance of Model200Response' do it 'should create an instact of Model200Response' do - @instance.should be_a(Petstore::Model200Response) + expect(@instance).to be_instance_of(Petstore::Model200Response) end end describe 'test attribute "name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/model_return_spec.rb b/samples/client/petstore/ruby/spec/models/model_return_spec.rb index 7b6f3a571c4..5a80c97542b 100644 --- a/samples/client/petstore/ruby/spec/models/model_return_spec.rb +++ b/samples/client/petstore/ruby/spec/models/model_return_spec.rb @@ -33,16 +33,12 @@ describe 'ModelReturn' do describe 'test an instance of ModelReturn' do it 'should create an instact of ModelReturn' do - @instance.should be_a(Petstore::ModelReturn) + expect(@instance).to be_instance_of(Petstore::ModelReturn) end end describe 'test attribute "_return"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/name_spec.rb b/samples/client/petstore/ruby/spec/models/name_spec.rb index e4942b173b9..03a9c69ece1 100644 --- a/samples/client/petstore/ruby/spec/models/name_spec.rb +++ b/samples/client/petstore/ruby/spec/models/name_spec.rb @@ -33,36 +33,24 @@ describe 'Name' do describe 'test an instance of Name' do it 'should create an instact of Name' do - @instance.should be_a(Petstore::Name) + expect(@instance).to be_instance_of(Petstore::Name) end end describe 'test attribute "name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "snake_case"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "property"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/order_spec.rb b/samples/client/petstore/ruby/spec/models/order_spec.rb index 420cfea059c..73bd5c082fd 100644 --- a/samples/client/petstore/ruby/spec/models/order_spec.rb +++ b/samples/client/petstore/ruby/spec/models/order_spec.rb @@ -33,66 +33,42 @@ describe 'Order' do describe 'test an instance of Order' do it 'should create an instact of Order' do - @instance.should be_a(Petstore::Order) + expect(@instance).to be_instance_of(Petstore::Order) end end describe 'test attribute "id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "pet_id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "quantity"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "ship_date"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "status"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "complete"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/pet_spec.rb b/samples/client/petstore/ruby/spec/models/pet_spec.rb index baf3cdf008d..9911ced1366 100644 --- a/samples/client/petstore/ruby/spec/models/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/models/pet_spec.rb @@ -25,84 +25,50 @@ describe 'Pet' do before do # run before each test @instance = Petstore::Pet.new - - @pet_api = Petstore::PetApi.new(API_CLIENT) - @pet_id = prepare_pet(@pet_api) end after do # run after each test - # remove the testing pet - begin - @pet_api.delete_pet(@pet_id) - rescue Petstore::ApiError => e - # ignore ApiError 404 (Not Found) - raise e if e.code != 404 - end end describe 'test an instance of Pet' do it 'should create an instact of Pet' do - @instance.should be_a(Petstore::Pet) + expect(@instance).to be_instance_of(Petstore::Pet) end end describe 'test attribute "id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "category"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "photo_urls"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "tags"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "status"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/special_model_name_spec.rb b/samples/client/petstore/ruby/spec/models/special_model_name_spec.rb index aa32e3fc7b2..cd93568e8f9 100644 --- a/samples/client/petstore/ruby/spec/models/special_model_name_spec.rb +++ b/samples/client/petstore/ruby/spec/models/special_model_name_spec.rb @@ -33,16 +33,12 @@ describe 'SpecialModelName' do describe 'test an instance of SpecialModelName' do it 'should create an instact of SpecialModelName' do - @instance.should be_a(Petstore::SpecialModelName) + expect(@instance).to be_instance_of(Petstore::SpecialModelName) end end describe 'test attribute "special_property_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/tag_spec.rb b/samples/client/petstore/ruby/spec/models/tag_spec.rb index 55778d8fd67..68b77e026b1 100644 --- a/samples/client/petstore/ruby/spec/models/tag_spec.rb +++ b/samples/client/petstore/ruby/spec/models/tag_spec.rb @@ -33,26 +33,18 @@ describe 'Tag' do describe 'test an instance of Tag' do it 'should create an instact of Tag' do - @instance.should be_a(Petstore::Tag) + expect(@instance).to be_instance_of(Petstore::Tag) end end describe 'test attribute "id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/models/user_spec.rb b/samples/client/petstore/ruby/spec/models/user_spec.rb index a6b872e834c..fc510605b5c 100644 --- a/samples/client/petstore/ruby/spec/models/user_spec.rb +++ b/samples/client/petstore/ruby/spec/models/user_spec.rb @@ -33,86 +33,54 @@ describe 'User' do describe 'test an instance of User' do it 'should create an instact of User' do - @instance.should be_a(Petstore::User) + expect(@instance).to be_instance_of(Petstore::User) end end describe 'test attribute "id"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "username"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "first_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "last_name"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "email"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "password"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "phone"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end describe 'test attribute "user_status"' do it 'should work' do - # assertion here - # should be_a() - # should be_nil - # should == - # should_not == + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index b05b2163353..737eee56d07 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -1,16 +1,6 @@ require 'spec_helper' require 'json' -def serialize_json(o) - API_CLIENT.object_to_http_body(o) -end - -def deserialize_json(s, type) - headers = {'Content-Type' => 'application/json'} - response = double('response', headers: headers, body: s) - API_CLIENT.deserialize(response, type) -end - describe "Pet" do before do @pet_api = Petstore::PetApi.new(API_CLIENT) diff --git a/samples/client/petstore/ruby/spec/spec.opts b/samples/client/petstore/ruby/spec/spec.opts deleted file mode 100644 index 391705bf8b0..00000000000 --- a/samples/client/petstore/ruby/spec/spec.opts +++ /dev/null @@ -1,4 +0,0 @@ ---colour ---format progress ---loadby mtime ---reverse diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index 0bba600ba45..11794c9ebcf 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -1,4 +1,7 @@ -# This file was generated by the `rspec --init` command. Conventionally, all +# load the gem +require 'petstore' + +# The following was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause # this file to always be loaded, without a need to explicitly require it in any @@ -95,5 +98,50 @@ RSpec.configure do |config| =end end -require 'SwaggerClient' +# API client (shared between all the test cases) +API_CLIENT = Petstore::ApiClient.new(Petstore::Configuration.new) +# randomly generate an ID +def random_id + rand(1000000) + 20000 +end + +# create a random pet, return its id +def prepare_pet(pet_api) + pet_id = random_id + category = Petstore::Category.new('id' => 20002, 'name' => 'category test') + tag = Petstore::Tag.new('id' => 30002, 'name' => 'tag test') + 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 +end + +# create a random order, return its id +def prepare_store(store_api) + order_id = 5 + order = Petstore::Order.new("id" => order_id, + "petId" => 123, + "quantity" => 789, + "shipDate" => "2015-04-06T23:42:01.678Z", + "status" => "placed", + "complete" => false) + store_api.place_order(order) + return order_id +end + +# A random string to tack onto stuff to ensure we're not seeing +# data from a previous test run +RAND = ("a".."z").to_a.sample(8).join + +# helper method to serialize object to json string +def serialize_json(o) + API_CLIENT.object_to_http_body(o) +end + +# helper method to deserialize json string back to object +def deserialize_json(s, type) + headers = {'Content-Type' => 'application/json'} + response = double('response', headers: headers, body: s) + API_CLIENT.deserialize(response, type) +end