diff --git a/Gemfile b/Gemfile index fd799238..723e6108 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gemspec gem 'gettext', '>= 3.1.3', '< 4.0.0' group :test do - gem 'rake', '~> 10.1.0' + gem 'rake' gem 'thor' gem 'minitest', '4.7.4' gem 'minitest-spec-context' diff --git a/Rakefile b/Rakefile index b5a45a5b..7d88e9bd 100644 --- a/Rakefile +++ b/Rakefile @@ -11,6 +11,7 @@ Rake::TestTask.new do |t| t.libs.push "lib" t.test_files = Dir.glob('test/**/*_test.rb') t.verbose = true + t.warning = false unless ENV['RUBY_WARNINGS'] end file "man/hammer.1.gz" => "man/hammer.1.asciidoc" do |t| diff --git a/hammer_cli.gemspec b/hammer_cli.gemspec index 5194f8fd..08d225e8 100644 --- a/hammer_cli.gemspec +++ b/hammer_cli.gemspec @@ -27,7 +27,7 @@ EOF s.require_paths = ["lib"] s.executables = ['hammer', 'hammer-complete'] - s.add_dependency 'clamp', '>= 1.1', '< 1.2.0' + s.add_dependency 'clamp', '>= 1.1', '< 2.0.0' s.add_dependency 'logging' s.add_dependency 'unicode-display_width' s.add_dependency 'unicode' diff --git a/lib/hammer_cli/abstract.rb b/lib/hammer_cli/abstract.rb index 200410c3..877838fc 100644 --- a/lib/hammer_cli/abstract.rb +++ b/lib/hammer_cli/abstract.rb @@ -42,7 +42,7 @@ def help_extension_blocks end def command_extensions - @command_extensions = @command_extensions || inherited_command_extensions || [] + @command_extensions ||= inherited_command_extensions || [] @command_extensions end @@ -192,7 +192,7 @@ def self.extend_output_definition(&block) def self.output(definition=nil, &block) dsl = HammerCLI::Output::Dsl.new - dsl.build &block if block_given? + dsl.build(&block) if block_given? output_definition.append definition.fields unless definition.nil? output_definition.append dsl.fields end @@ -206,7 +206,7 @@ def output_definition end def self.output_definition - @output_definition = @output_definition || inherited_output_definition || HammerCLI::Output::Definition.new + @output_definition ||= inherited_output_definition || HammerCLI::Output::Definition.new @output_definition end @@ -341,27 +341,27 @@ def exception_handler_class end def self.desc(desc=nil) - @desc = desc if desc - @desc + return @desc ||= nil unless desc + + @desc = desc end def self.command_name(name=nil) - if @names && name - @names << name if !@names.include?(name) - else - @names = [name] if name - end - @names || (superclass.respond_to?(:command_names) ? superclass.command_names : nil) + command_names(name) end def self.command_names(*names) - @names = names unless names.empty? - @names || (superclass.respond_to?(:command_names) ? superclass.command_names : nil) + names = names.compact + return @names ||= (superclass.respond_to?(:command_names) ? superclass.command_names : nil) if names.empty? + + @names ||= [] + @names |= names end def self.warning(message = nil) - @warning_msg = message if message - @warning_msg + return @warning_msg ||= nil unless message + + @warning_msg = message end def self.autoload_subcommands diff --git a/lib/hammer_cli/apipie/resource.rb b/lib/hammer_cli/apipie/resource.rb index 01e4a0da..57cd4427 100644 --- a/lib/hammer_cli/apipie/resource.rb +++ b/lib/hammer_cli/apipie/resource.rb @@ -37,7 +37,7 @@ def connection_name(resource_class) end def class_resource - return @api_resource if @api_resource + return @api_resource if @api_resource ||= nil return superclass.class_resource if superclass.respond_to? :class_resource end @@ -68,7 +68,7 @@ def resource(resource=nil, action=nil) def action(action=nil) @api_action = action unless action.nil? - return @api_action if @api_action + return @api_action if @api_action ||= nil return superclass.action if superclass.respond_to? :action end diff --git a/lib/hammer_cli/command_extensions.rb b/lib/hammer_cli/command_extensions.rb index 03cd01a9..e26e8919 100644 --- a/lib/hammer_cli/command_extensions.rb +++ b/lib/hammer_cli/command_extensions.rb @@ -33,7 +33,7 @@ def inheritable? end def self.method_missing(message, *args, &block) - if @delegatee + if @delegatee ||= nil @delegatee.send(message, *args, &block) else super @@ -121,7 +121,7 @@ def extend_output allowed = @only & %i[output] return if allowed.empty? || (allowed & @except).any? - self.class.extend_output(@command_class, @command_object) + self.class.extend_output(@command_class, @command_object ||= nil) end def extend_help @@ -205,6 +205,7 @@ def self.extend_options(command_class) end def self.extend_predefined_options(command_class) + @predefined_option_names ||= nil command_class.send(:use_option, *@predefined_option_names) logger.debug("Added predefined options for #{command_class}: #{@predefined_option_names}") end @@ -259,9 +260,7 @@ def self.extend_option_sources(sources, command_object, command_class) end def self.extend_option_family(command_class) - return if @option_family_extensions.nil? - - @option_family_extensions.each do |extension| + (@option_family_extensions ||= []).each do |extension| extension[:options][:creator] = command_class command_class.send(:option_family, extension[:options], &extension[:block]) logger.debug("Called option family block for #{command_class}:\n\t#{extension[:block]}") diff --git a/lib/hammer_cli/defaults_commands.rb b/lib/hammer_cli/defaults_commands.rb index cff5bf66..74df19b1 100644 --- a/lib/hammer_cli/defaults_commands.rb +++ b/lib/hammer_cli/defaults_commands.rb @@ -1,4 +1,3 @@ -require 'hammer_cli' require 'yaml' module HammerCLI class BaseDefaultsProvider diff --git a/lib/hammer_cli/help/builder.rb b/lib/hammer_cli/help/builder.rb index 544acd41..dbe9edc3 100644 --- a/lib/hammer_cli/help/builder.rb +++ b/lib/hammer_cli/help/builder.rb @@ -14,7 +14,7 @@ def initialize(richtext = false) def add_usage(invocation_path, usage_descriptions) heading(Clamp.message(:usage_heading)) usage_descriptions.each do |usage| - puts " #{HammerCLI.expand_invocation_path(invocation_path)} #{usage}".rstrip + line " #{HammerCLI.expand_invocation_path(invocation_path)} #{usage}".rstrip end end @@ -24,7 +24,7 @@ def add_list(heading, items) end items.reject! {|item| item.respond_to?(:hidden?) && item.hidden?} - puts + line heading(heading) label_width = DEFAULT_LABEL_INDENT @@ -47,15 +47,15 @@ def add_list(heading, items) item.help end description.gsub(/^(.)/) { Unicode.capitalize(Regexp.last_match(1)) }.wrap.each_line do |line| - puts " %-#{label_width}s %s" % [label, line] + line " %-#{label_width}s %s" % [label, line] label = '' end end end def add_text(content) - puts - puts content + line + line content end protected @@ -63,7 +63,7 @@ def add_text(content) def heading(label) label = "#{label}:" label = HighLine.color(label, :bold) if @richtext - puts label + line label end end end diff --git a/lib/hammer_cli/logger.rb b/lib/hammer_cli/logger.rb index b6dc66a4..af7f459b 100644 --- a/lib/hammer_cli/logger.rb +++ b/lib/hammer_cli/logger.rb @@ -54,7 +54,7 @@ def self.initialize_logger(logger) log_dir = File.expand_path(HammerCLI::Settings.get(:log_dir) || DEFAULT_LOG_DIR) begin FileUtils.mkdir_p(log_dir, :mode => 0750) - rescue Errno::EACCES => e + rescue Errno::EACCES => _ $stderr.puts _("No permissions to create log dir %s.") % log_dir end @@ -68,7 +68,7 @@ def self.initialize_logger(logger) :size => (HammerCLI::Settings.get(:log_size) || 1)*1024*1024) # 1MB # set owner and group (it's ignored if attribute is nil) FileUtils.chown HammerCLI::Settings.get(:log_owner), HammerCLI::Settings.get(:log_group), filename - rescue ArgumentError => e + rescue ArgumentError => _ $stderr.puts _("File %s not writeable, won't log anything to the file!") % filename end diff --git a/lib/hammer_cli/modules.rb b/lib/hammer_cli/modules.rb index 62465091..f5d6f8c8 100644 --- a/lib/hammer_cli/modules.rb +++ b/lib/hammer_cli/modules.rb @@ -67,7 +67,7 @@ def self.load!(name) def self.load(name) load! name - rescue Exception => e + rescue Exception => _ false end diff --git a/lib/hammer_cli/options/normalizers.rb b/lib/hammer_cli/options/normalizers.rb index 70e795fc..9b498d97 100644 --- a/lib/hammer_cli/options/normalizers.rb +++ b/lib/hammer_cli/options/normalizers.rb @@ -298,7 +298,7 @@ def format(val) json_string = ::File.exist?(::File.expand_path(val)) ? super(val) : val ::JSON.parse(json_string) - rescue ::JSON::ParserError => e + rescue ::JSON::ParserError => _ raise ArgumentError, _("Unable to parse JSON input.") end diff --git a/lib/hammer_cli/options/option_family.rb b/lib/hammer_cli/options/option_family.rb index 4f9f0993..17ff3b4b 100644 --- a/lib/hammer_cli/options/option_family.rb +++ b/lib/hammer_cli/options/option_family.rb @@ -19,6 +19,7 @@ def initialize(options = {}) @children = [] @options = options @creator = options[:creator] || self + @parent = nil @prefix = options[:prefix] @root = options[:root] || options[:aliased_resource] || options[:referenced_resource] @creator.family_registry.register(self) if @creator != self diff --git a/lib/hammer_cli/options/validators/dsl.rb b/lib/hammer_cli/options/validators/dsl.rb index eb4f6971..8c25d2d7 100644 --- a/lib/hammer_cli/options/validators/dsl.rb +++ b/lib/hammer_cli/options/validators/dsl.rb @@ -152,7 +152,7 @@ def one_of(*to_check) end def run(&block) - self.instance_eval &block + self.instance_eval(&block) end end end diff --git a/lib/hammer_cli/output/adapter/csv.rb b/lib/hammer_cli/output/adapter/csv.rb index 26f5269e..d6fadbc7 100644 --- a/lib/hammer_cli/output/adapter/csv.rb +++ b/lib/hammer_cli/output/adapter/csv.rb @@ -94,7 +94,6 @@ def initialize(field) @name = nil @prefixes = [] @suffixes = [] - @data end def append_suffix(suffix) diff --git a/lib/hammer_cli/output/dsl.rb b/lib/hammer_cli/output/dsl.rb index 1606e930..bc8ad225 100644 --- a/lib/hammer_cli/output/dsl.rb +++ b/lib/hammer_cli/output/dsl.rb @@ -12,7 +12,7 @@ def fields end def build(&block) - self.instance_eval &block + self.instance_eval(&block) end protected diff --git a/lib/hammer_cli/output/fields.rb b/lib/hammer_cli/output/fields.rb index 98671ab6..44bb0fdb 100644 --- a/lib/hammer_cli/output/fields.rb +++ b/lib/hammer_cli/output/fields.rb @@ -13,6 +13,7 @@ def initialize(options={}) @label = options[:label] @sets = options[:sets] @options = options + @parent = nil end def id @@ -57,8 +58,7 @@ def parameters protected def inherited_sets - return nil if @parent.nil? - @parent.sets + @parent&.sets end def default_sets @@ -72,7 +72,7 @@ class ContainerField < Field def initialize(options={}, &block) super(options) dsl = HammerCLI::Output::Dsl.new - dsl.build &block if block_given? + dsl.build(&block) if block_given? dsl.fields.each { |f| f.parent = self } self.output_definition.append dsl.fields end diff --git a/lib/hammer_cli/output/formatters.rb b/lib/hammer_cli/output/formatters.rb index 5b659d9e..40915d6f 100644 --- a/lib/hammer_cli/output/formatters.rb +++ b/lib/hammer_cli/output/formatters.rb @@ -13,7 +13,7 @@ def initialize(formatter_map={}) def register_formatter(type, *formatters) if @_formatters[type].nil? - @_formatters[type] = FormatterContainer.new *formatters + @_formatters[type] = FormatterContainer.new(*formatters) else formatters.each { |f| @_formatters[type].add_formatter(f) } end @@ -84,8 +84,8 @@ def required_features tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) } end - def format(data, field_params={}) - c = HighLine.color(data.to_s, @color) + def format(data, _={}) + HighLine.color(data.to_s, @color) end end @@ -97,7 +97,7 @@ def required_features tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) } end - def format(string_date, field_params={}) + def format(string_date, _={}) t = DateTime.parse(string_date.to_s) t.strftime("%Y/%m/%d %H:%M:%S") rescue ArgumentError diff --git a/lib/hammer_cli/output/record_collection.rb b/lib/hammer_cli/output/record_collection.rb index e3396edc..757165d5 100644 --- a/lib/hammer_cli/output/record_collection.rb +++ b/lib/hammer_cli/output/record_collection.rb @@ -6,10 +6,10 @@ class MetaData attr_accessor :total, :subtotal, :page, :per_page, :search, :sort_by, :sort_order, :pagination_verbosity def initialize(options={}) - @total = options[:total].to_i if options[:total] - @subtotal = options[:subtotal].to_i if options[:subtotal] - @page = options[:page].to_i if options[:page] - @per_page = options[:per_page].to_i if options[:per_page] + @total = options[:total]&.to_i + @subtotal = options[:subtotal]&.to_i + @page = options[:page]&.to_i + @per_page = options[:per_page]&.to_i @search = options[:search] @sort_by = options[:sort_by] @sort_order = options[:sort_order] diff --git a/lib/hammer_cli/ssloptions.rb b/lib/hammer_cli/ssloptions.rb index bf0fad60..8799f0dc 100644 --- a/lib/hammer_cli/ssloptions.rb +++ b/lib/hammer_cli/ssloptions.rb @@ -68,13 +68,13 @@ def cert_key_options def read_certificate(path) OpenSSL::X509::Certificate.new(File.read(path)) unless path.nil? - rescue SystemCallError => e + rescue SystemCallError => _ warn _("Could't read SSL client certificate %s.") % path end def read_key(path) OpenSSL::PKey.read(File.read(path)) unless path.nil? - rescue SystemCallError => e + rescue SystemCallError => _ warn _("Could't read SSL client key %s.") % path end end diff --git a/lib/hammer_cli/subcommand.rb b/lib/hammer_cli/subcommand.rb index 9598bb8a..85b47a22 100644 --- a/lib/hammer_cli/subcommand.rb +++ b/lib/hammer_cli/subcommand.rb @@ -11,6 +11,7 @@ def initialize(names, description, subcommand_class, options = {}) @subcommand_class = subcommand_class @hidden = options[:hidden] @warning = options[:warning] + super(@names, @description, @subcommand_class) end def hidden? diff --git a/lib/hammer_cli/testing/command_assertions.rb b/lib/hammer_cli/testing/command_assertions.rb index 10089e33..40d74002 100644 --- a/lib/hammer_cli/testing/command_assertions.rb +++ b/lib/hammer_cli/testing/command_assertions.rb @@ -35,7 +35,7 @@ def run_cmd(options, context={}, cmd_class=HammerCLI::MainCommand) end def exit_code_map - return @exit_code_map unless @exit_code_map.nil? + return @exit_code_map if @exit_code_map ||= nil hammer_exit_codes = HammerCLI.constants.select{|c| c.to_s.start_with?('EX_')} @exit_code_map = hammer_exit_codes.inject({}) do |code_map, code| diff --git a/lib/hammer_cli/utils.rb b/lib/hammer_cli/utils.rb index bd40112a..dcb94010 100644 --- a/lib/hammer_cli/utils.rb +++ b/lib/hammer_cli/utils.rb @@ -48,18 +48,6 @@ def wrap(line_width: 80, break_sequence: "\n") end end -class Hash - # for ruby < 2.5.0 - def transform_keys - result = {} - each do |key, value| - new_key = yield key - result[new_key] = value - end - result - end -end - module HammerCLI def self.tty? diff --git a/test/functional/defaults_test.rb b/test/functional/defaults_test.rb index bf90353b..d5b046bf 100644 --- a/test/functional/defaults_test.rb +++ b/test/functional/defaults_test.rb @@ -24,7 +24,6 @@ def self.get_defaults(param) let(:cmd) { ['defaults', 'list'] } it 'prints all defaults' do - header = 'Parameter,Value' default_values = { :organization_id => { :value => 3, diff --git a/test/unit/apipie/command_test.rb b/test/unit/apipie/command_test.rb index 10a2eb0c..c0ceab24 100644 --- a/test/unit/apipie/command_test.rb +++ b/test/unit/apipie/command_test.rb @@ -42,7 +42,7 @@ class CommandUnsupp < HammerCLI::Apipie::Command let(:cmd_class) { CommandUnsupp.dup } let(:cmd) { cmd_class.new("unsupported", ctx) } it "should print help for unsupported command" do - assert_match /.*Unfortunately the server does not support such operation.*/, cmd.help + assert_match(/.*Unfortunately the server does not support such operation.*/, cmd.help) end end diff --git a/test/unit/apipie/option_definition_test.rb b/test/unit/apipie/option_definition_test.rb index 5ce02264..2c614bf8 100644 --- a/test/unit/apipie/option_definition_test.rb +++ b/test/unit/apipie/option_definition_test.rb @@ -4,7 +4,7 @@ describe HammerCLI::Apipie::OptionDefinition do - let(:opt) { HammerCLI::Apipie::OptionDefinition.new("--opt", "OPT", "", :referenced_resource => @referenced_resource) } + let(:opt) { HammerCLI::Apipie::OptionDefinition.new("--opt", "OPT", "", :referenced_resource => @referenced_resource ||= nil) } describe "referenced resource" do it "should be nil by default" do @@ -23,7 +23,7 @@ end - let(:opt2) { HammerCLI::Apipie::OptionDefinition.new("--opt2", "OPT2", "'OPT2'", :referenced_resource => @referenced_resource) } + let(:opt2) { HammerCLI::Apipie::OptionDefinition.new("--opt2", "OPT2", "'OPT2'") } describe "Option Description should be converted" do it "should be converted" do diff --git a/test/unit/exception_handler_test.rb b/test/unit/exception_handler_test.rb index c6a55ee8..87e9843e 100644 --- a/test/unit/exception_handler_test.rb +++ b/test/unit/exception_handler_test.rb @@ -30,7 +30,7 @@ end it "should handle help request" do - output.expects(:print_message).with(cmd.help, {}, verbosity: HammerCLI::V_QUIET) + output.expects(:print_message).with(cmd.help, {}, { verbosity: HammerCLI::V_QUIET }) handler.handle_exception(Clamp::HelpWanted.new(cmd), :heading => heading) end @@ -51,8 +51,8 @@ ex = RestClient::ResourceNotFound.new output.default_adapter = :silent handler.handle_exception(ex) - assert_match /Using exception handler HammerCLI::ExceptionHandler#handle_not_found/, @log_output.readline.strip - assert_match /ERROR Exception : (Resource )?Not Found/, @log_output.readline.strip + assert_match(/Using exception handler HammerCLI::ExceptionHandler#handle_not_found/, @log_output.readline.strip) + assert_match(/ERROR Exception : (Resource )?Not Found/, @log_output.readline.strip) end it "should print default prompts for standard missing arguments" do diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index ce22d4fb..5a3aa5e9 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -20,13 +20,13 @@ describe "loading old history" do it "skips loading if the file does not exist" do - history = HammerCLI::ShellHistory.new(new_file.path) + HammerCLI::ShellHistory.new(new_file.path) Readline::HISTORY.to_a.must_equal [] end it "preseeds readline's history" do - history = HammerCLI::ShellHistory.new(history_file.path) + HammerCLI::ShellHistory.new(history_file.path) Readline::HISTORY.to_a.must_equal ["line 1", "line 2"] end diff --git a/test/unit/logger_test.rb b/test/unit/logger_test.rb index 8dff9d15..9385fb66 100644 --- a/test/unit/logger_test.rb +++ b/test/unit/logger_test.rb @@ -12,7 +12,7 @@ HammerCLI::Settings.load({:log_dir => log_dir}) - out, err = capture_io do + _, err = capture_io do HammerCLI::Logger::initialize_logger(logger) end diff --git a/test/unit/options/option_definition_test.rb b/test/unit/options/option_definition_test.rb index e18233ae..f45dff3e 100644 --- a/test/unit/options/option_definition_test.rb +++ b/test/unit/options/option_definition_test.rb @@ -63,8 +63,8 @@ def opt_with_deprecation(deprecation) context = {} cmd = TestDeprecatedOptionCmd.new("", context) - out, err = capture_io { cmd.run(["--another-deprecated=VALUE"]) } - err.must_match /Warning: Option --another-deprecated is deprecated. It is going to be removed/ + _, err = capture_io { cmd.run(["--another-deprecated=VALUE"]) } + err.must_match(/Warning: Option --another-deprecated is deprecated. It is going to be removed/) context[:old_option].must_equal "VALUE" end @@ -72,8 +72,8 @@ def opt_with_deprecation(deprecation) context = {} cmd = TestDeprecatedOptionCmd.new("", context) - out, err = capture_io { cmd.run(["--deprecated=VALUE"]) } - err.must_match /Warning: Option --deprecated is deprecated. Use --test-option instead/ + _, err = capture_io { cmd.run(["--deprecated=VALUE"]) } + err.must_match(/Warning: Option --deprecated is deprecated. Use --test-option instead/) context[:test_option].must_equal "VALUE" end diff --git a/test/unit/options/sources/saved_defaults_test.rb b/test/unit/options/sources/saved_defaults_test.rb index 1a63b531..9830f920 100644 --- a/test/unit/options/sources/saved_defaults_test.rb +++ b/test/unit/options/sources/saved_defaults_test.rb @@ -20,10 +20,6 @@ @defaults.expects(:get_defaults).with('--test-multi1').returns(:first_value) current_result = {} - expected_result = { - :different_attr_name => 1, - :multiple_switches_option => :first_value - } @logger.expects(:info).with('Custom default value 1 was used for attribute --test') @logger.expects(:info).with('Custom default value first_value was used for attribute --test-multi1') diff --git a/test/unit/output/adapter/abstract_test.rb b/test/unit/output/adapter/abstract_test.rb index f4cd357b..ba3266a7 100644 --- a/test/unit/output/adapter/abstract_test.rb +++ b/test/unit/output/adapter/abstract_test.rb @@ -27,7 +27,7 @@ def required_features it "should filter formatters with incompatible features" do HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [] }) - adapter = adapter_class.new({}, {:type => [UnknownTestFormatter.new]}) + adapter_class.new({}, {:type => [UnknownTestFormatter.new]}) end it "should keep compatible formatters" do @@ -35,7 +35,7 @@ def required_features HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [formatter] }) # set :unknown tag to abstract adapter_class.any_instance.stubs(:features).returns([:unknown]) - adapter = adapter_class.new({}, {:type => [formatter]}) + adapter_class.new({}, {:type => [formatter]}) end it "should put serializers first" do @@ -46,7 +46,7 @@ def required_features HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [formatter2, formatter1] }) # set :unknown tag to abstract adapter_class.any_instance.stubs(:features).returns([:serialized]) - adapter = adapter_class.new({}, {:type => [formatter1, formatter2]}) + adapter_class.new({}, {:type => [formatter1, formatter2]}) end diff --git a/test/unit/output/adapter/csv_test.rb b/test/unit/output/adapter/csv_test.rb index b1f56598..db07d999 100644 --- a/test/unit/output/adapter/csv_test.rb +++ b/test/unit/output/adapter/csv_test.rb @@ -24,28 +24,28 @@ it "should print column name" do out, err = capture_io { adapter.print_collection(fields, data) } - out.must_match /.*Name,Started At.*/ - err.must_match // + out.must_match(/.*Name,Started At.*/) + err.must_match(//) end it "should print field value" do out, err = capture_io { adapter.print_collection(fields, data) } - out.must_match /.*John Doe.*/ - err.must_match // + out.must_match(/.*John Doe.*/) + err.must_match(//) end it "does not print fields which data are missing from api by default" do fields << field_login out, err = capture_io { adapter.print_collection(fields, data) } - out.wont_match /.*Login.*/ - err.must_match // + out.wont_match(/.*Login.*/) + err.must_match(//) end it "prints fields which data are missing from api when field has hide_missing flag set to false" do fields << field_missing out, err = capture_io { adapter.print_collection(fields, data) } - out.must_match /.*Missing.*/ - err.must_match // + out.must_match(/.*Missing.*/) + err.must_match(//) end context "handle ids" do @@ -59,14 +59,14 @@ }]} it "should ommit column of type Id by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.wont_match(/.*Id.*/) out.wont_match(/.*2000,.*/) end it "should print column of type Id when --show-ids is set" do adapter = HammerCLI::Output::Adapter::CSValues.new( { :show_ids => true } ) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*Id.*/) end end @@ -75,12 +75,12 @@ let(:empty_data) { HammerCLI::Output::RecordCollection.new [] } it "should print headers by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*Name.*/) end it "should print headers by default even if there is no data" do - out, err = capture_io { adapter.print_collection(fields, empty_data) } + out, _ = capture_io { adapter.print_collection(fields, empty_data) } out.must_match(/.*Name.*/) end @@ -127,14 +127,14 @@ it "should print column names" do out, err = capture_io { adapter.print_collection(fields, data) } - out.must_match /.*Demographics::Age,Demographics::Gender,Biometrics::Weight,Biometrics::Height*/ - err.must_match // + out.must_match(/.*Demographics::Age,Demographics::Gender,Biometrics::Weight,Biometrics::Height*/) + err.must_match(//) end it "should print data" do out, err = capture_io { adapter.print_collection(fields, data) } - out.must_match /.*2000,22,m,123,155*/ - err.must_match // + out.must_match(/.*2000,22,m,123,155*/) + err.must_match(//) end end @@ -169,7 +169,7 @@ lines = out.split("\n") lines[0].must_equal 'Name,Started At,Items::Item Name::1,Items::Item Quantity::1,Items::Item Name::2,Items::Item Quantity::2' - err.must_match // + err.must_match(//) end it "should print collection data" do @@ -179,7 +179,7 @@ lines[1].must_equal 'John Doe,2000,hammer,100,"",""' lines[2].must_equal 'Jane Roe,2001,cleaver,1,sledge,50' - err.must_match // + err.must_match(//) end it "should handle empty collection" do @@ -188,7 +188,7 @@ lines[0].must_equal 'Name,Started At,Items' - err.must_match // + err.must_match(//) end end @@ -202,7 +202,7 @@ def format(data, field_params={}) end adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ DotFormatter.new ]}) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*-DOT-.*/) end @@ -215,7 +215,7 @@ def format(data, field_params={}) adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ NilFormatter.new ]}) nil_data = HammerCLI::Output::RecordCollection.new [{ :name => nil }] - out, err = capture_io { adapter.print_collection([field_name], nil_data) } + out, _ = capture_io { adapter.print_collection([field_name], nil_data) } out.must_match(/.*NIL.*/) end end diff --git a/test/unit/output/adapter/table_test.rb b/test/unit/output/adapter/table_test.rb index 85313165..260d2263 100644 --- a/test/unit/output/adapter/table_test.rb +++ b/test/unit/output/adapter/table_test.rb @@ -94,7 +94,7 @@ } it "should ommit column of type Id by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.wont_match(/.*ID.*/) end @@ -110,7 +110,7 @@ it "should print column of type Id when --show-ids is set" do adapter = HammerCLI::Output::Adapter::Table.new( { :show_ids => true } ) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*ID.*/) end @@ -128,12 +128,12 @@ context "handle headers" do it "should print headers by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*NAME.*/) end it "should print headers by default even if there is no data" do - out, err = capture_io { adapter.print_collection(fields, empty_data) } + out, _ = capture_io { adapter.print_collection(fields, empty_data) } out.must_match(/.*NAME.*/) end @@ -353,7 +353,7 @@ def format(data, field_params={}) end adapter = HammerCLI::Output::Adapter::Table.new({}, { :Field => [ DotFormatter.new ]}) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*-DOT-.*/) end