From 745de8f0b2c9aec3236fa226ab3a981be860e1c1 Mon Sep 17 00:00:00 2001 From: Panayotis Matsinopoulos Date: Thu, 29 Sep 2016 08:42:07 +0300 Subject: [PATCH] Fixes rubocop violation Style/FormatString --- .rubocop_todo.yml | 12 ------------ lib/cucumber/formatter/duration.rb | 2 +- lib/cucumber/formatter/junit.rb | 4 ++-- lib/cucumber/formatter/usage.rb | 4 ++-- lib/cucumber/rake/task.rb | 4 ++-- lib/cucumber/rb_support/rb_world.rb | 2 +- lib/cucumber/rb_support/snippet.rb | 2 +- 7 files changed, 9 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8504169d07..78fdb5d376 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -555,18 +555,6 @@ Style/FirstParameterIndentation: Exclude: - 'spec/cucumber/rake/forked_spec.rb' -# Offense count: 9 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'lib/cucumber/formatter/duration.rb' - - 'lib/cucumber/formatter/junit.rb' - - 'lib/cucumber/formatter/usage.rb' - - 'lib/cucumber/rake/task.rb' - - 'lib/cucumber/rb_support/rb_world.rb' - - 'lib/cucumber/rb_support/snippet.rb' - # Offense count: 13 # Configuration parameters: AllowedVariables. Style/GlobalVars: diff --git a/lib/cucumber/formatter/duration.rb b/lib/cucumber/formatter/duration.rb index 5443c17f26..41d06894ef 100644 --- a/lib/cucumber/formatter/duration.rb +++ b/lib/cucumber/formatter/duration.rb @@ -7,7 +7,7 @@ module Duration # time format. def format_duration(seconds) m, s = seconds.divmod(60) - "#{m}m#{'%.3f' % s}s" + "#{m}m#{format('%.3f', s)}s" end end end diff --git a/lib/cucumber/formatter/junit.rb b/lib/cucumber/formatter/junit.rb index ebe74393e0..2dd2cfc252 100644 --- a/lib/cucumber/formatter/junit.rb +++ b/lib/cucumber/formatter/junit.rb @@ -92,7 +92,7 @@ def end_feature(feature_data) :errors => feature_data[:errors], :skipped => feature_data[:skipped], :tests => feature_data[:tests], - :time => '%.6f' % feature_data[:time], + :time => format('%.6f', feature_data[:time]), :name => feature_data[:feature].name ) do @testsuite << feature_data[:builder].target! end @@ -122,7 +122,7 @@ def build_testcase(result, scenario_designation, output) classname = @current_feature_data[:feature].name name = scenario_designation - @current_feature_data[:builder].testcase(:classname => classname, :name => name, :time => '%.6f' % duration) do + @current_feature_data[:builder].testcase(:classname => classname, :name => name, :time => format('%.6f', duration)) do if !result.passed? && result.ok?(@config.strict?) @current_feature_data[:builder].skipped @current_feature_data[:skipped] += 1 diff --git a/lib/cucumber/formatter/usage.rb b/lib/cucumber/formatter/usage.rb index 5ffb9ec117..d875045ca7 100644 --- a/lib/cucumber/formatter/usage.rb +++ b/lib/cucumber/formatter/usage.rb @@ -79,7 +79,7 @@ def print_summary end def print_step_definition(stepdef_key) - @io.print format_string(sprintf('%.7f', stepdef_key.mean_duration), :skipped) + ' ' unless config.dry_run? + @io.print format_string(format('%.7f', stepdef_key.mean_duration), :skipped) + ' ' unless config.dry_run? @io.print format_string(stepdef_key.regexp_source, stepdef_key.status) if config.source? indent = max_length - stepdef_key.regexp_source.unpack('U*').length @@ -92,7 +92,7 @@ def print_step_definition(stepdef_key) def print_steps(stepdef_key) @stepdef_to_match[stepdef_key].each do |step| @io.print ' ' - @io.print format_string(sprintf('%.7f', step[:duration]), :skipped) + ' ' unless config.dry_run? + @io.print format_string(format('%.7f', step[:duration]), :skipped) + ' ' unless config.dry_run? @io.print format_step(step[:keyword], step[:step_match], step[:status], nil) if config.source? indent = max_length - (step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length) diff --git a/lib/cucumber/rake/task.rb b/lib/cucumber/rake/task.rb index cda6a22bdb..1cf60ea158 100644 --- a/lib/cucumber/rake/task.rb +++ b/lib/cucumber/rake/task.rb @@ -62,11 +62,11 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files) end def load_path(libs) - ['"%s"' % @libs.join(File::PATH_SEPARATOR)] + [format('"%s"', @libs.join(File::PATH_SEPARATOR))] end def quoted_binary(cucumber_bin) - ['"%s"' % cucumber_bin] + [format('"%s"', cucumber_bin)] end def use_bundler diff --git a/lib/cucumber/rb_support/rb_world.rb b/lib/cucumber/rb_support/rb_world.rb index f0d1e60d2c..281b16b340 100644 --- a/lib/cucumber/rb_support/rb_world.rb +++ b/lib/cucumber/rb_support/rb_world.rb @@ -125,7 +125,7 @@ def inspect modules += included_modules end modules << stringify_namespaced_modules - sprintf('#<%s:0x%x>', modules.join('+'), self.object_id) + format('#<%s:0x%x>', modules.join('+'), self.object_id) end # see {#inspect} diff --git a/lib/cucumber/rb_support/snippet.rb b/lib/cucumber/rb_support/snippet.rb index 36b2e25b08..9bceec169e 100644 --- a/lib/cucumber/rb_support/snippet.rb +++ b/lib/cucumber/rb_support/snippet.rb @@ -38,7 +38,7 @@ def step end def self.cli_option_string(type) - '%-7s: %-28s e.g. %s' % [type, description, example] + format('%-7s: %-28s e.g. %s', type, description, example) end private