diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a026879d5..64aeb1d4f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,8 +3,6 @@ on: [push, pull_request] jobs: test: runs-on: ubuntu-latest - env: - BUNDLE_GEMFILE: lint_gems.rb steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d54e00c0..736a7b7c8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,8 +5,7 @@ jobs: strategy: fail-fast: false matrix: - # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' - ruby: ['2.0', 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, head] + ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', 'head'] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.rubocop.yml b/.rubocop.yml index 545c5587d..69943b31a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,16 +1,14 @@ -inherit_from: .rubocop_todo.yml - AllCops: - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.6 DisabledByDefault: true + SuggestExtensions: false Exclude: - spec/sandbox/**/* - spec/fixtures/**/* - vendor/bundle/**/** -# Enforce Ruby 1.8-compatible hash syntax Style/HashSyntax: - EnforcedStyle: hash_rockets + EnforcedStyle: ruby19 # No spaces inside hash literals Layout/SpaceInsideHashLiteralBraces: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index c538d9291..000000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,51 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2020-02-14 14:37:56 -0500 using RuboCop version 0.50.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: outdent, indent -Layout/AccessModifierIndentation: - Exclude: - - 'lib/thor/nested_context.rb' - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/thor/actions/inject_into_file.rb' - - 'spec/actions_spec.rb' - - 'spec/command_spec.rb' - -# Offense count: 65 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'lib/thor/actions/inject_into_file.rb' - - 'spec/actions/inject_into_file_spec.rb' - -# Offense count: 24 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Gemfile' - - 'lib/thor/actions.rb' - - 'lib/thor/actions/inject_into_file.rb' - - 'lib/thor/base.rb' - - 'lib/thor/error.rb' - - 'lib/thor/parser/option.rb' - - 'lib/thor/shell/color.rb' - - 'spec/parser/options_spec.rb' - - 'spec/script_exit_status_spec.rb' diff --git a/Gemfile b/Gemfile index fa8c43992..c82a4c3e2 100644 --- a/Gemfile +++ b/Gemfile @@ -5,17 +5,16 @@ gem "rake" group :development do gem "pry" gem "pry-byebug" + gem "rubocop", "~> 1.30" end group :test do gem "childlabor" - gem 'coveralls_reborn', '~> 0.23.1', :require => false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0") + gem "coveralls_reborn", "~> 0.23.1", require: false gem "rspec", ">= 3.2" gem "rspec-mocks", ">= 3" gem "simplecov", ">= 0.13" - gem "webmock", '~> 3.14.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4.0") - gem "webmock", '>= 3.14' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.0") - gem "rexml", '3.2.4' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1.0") + gem "webmock", ">= 3.14" end gemspec diff --git a/lib/thor.rb b/lib/thor.rb index 58b1ce613..cc4591b00 100644 --- a/lib/thor.rb +++ b/lib/thor.rb @@ -258,7 +258,7 @@ def command_help(shell, command_name) if command.long_description shell.say "Description:" - shell.print_wrapped(command.long_description, :indent => 2) + shell.print_wrapped(command.long_description, indent: 2) else shell.say command.description end @@ -283,7 +283,7 @@ def help(shell, subcommand = false) shell.say "Commands:" end - shell.print_table(list, :indent => 2, :truncate => true) + shell.print_table(list, indent: 2, truncate: true) shell.say class_options_help(shell) print_exclusive_options(shell) @@ -318,7 +318,7 @@ def subcommand(subcommand, subcommand_class) define_method(subcommand) do |*args| args, opts = Thor::Arguments.split(args) - invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}] + invoke_args = [args, opts, {invoked_via_subcommand: true, class_options: options}] invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h") invoke subcommand_class, *invoke_args end @@ -459,7 +459,7 @@ def print_exclusive_options(shell, command = nil) # :nodoc: opts += class_exclusive_option_names unless opts.empty? shell.say "Exclusive Options:" - shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, :indent => 2 ) + shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 ) shell.say end end @@ -470,7 +470,7 @@ def print_at_least_one_required_options(shell, command = nil) # :nodoc: opts += class_at_least_one_option_names unless opts.empty? shell.say "Required At Least One:" - shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, :indent => 2 ) + shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 ) shell.say end end @@ -539,8 +539,8 @@ def create_command(meth) #:nodoc: if @usage && @desc base_class = @hide ? Thor::HiddenCommand : Thor::Command - relations = {:exclusive_option_names => method_exclusive_option_names, - :at_least_one_option_names => method_at_least_one_option_names} + relations = {exclusive_option_names: method_exclusive_option_names, + at_least_one_option_names: method_at_least_one_option_names} commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, relations) @usage, @desc, @long_desc, @method_options, @hide = nil @method_exclusive_option_names, @method_at_least_one_option_names = nil diff --git a/lib/thor/actions.rb b/lib/thor/actions.rb index e4af5df95..50475452d 100644 --- a/lib/thor/actions.rb +++ b/lib/thor/actions.rb @@ -46,17 +46,17 @@ def source_paths_for_search # Add runtime options that help actions execution. # def add_runtime_options! - class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime, - :desc => "Overwrite files that already exist" + class_option :force, type: :boolean, aliases: "-f", group: :runtime, + desc: "Overwrite files that already exist" - class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime, - :desc => "Run but do not make any changes" + class_option :pretend, type: :boolean, aliases: "-p", group: :runtime, + desc: "Run but do not make any changes" - class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime, - :desc => "Suppress status output" + class_option :quiet, type: :boolean, aliases: "-q", group: :runtime, + desc: "Suppress status output" - class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime, - :desc => "Skip files that already exist" + class_option :skip, type: :boolean, aliases: "-s", group: :runtime, + desc: "Skip files that already exist" end end @@ -113,9 +113,9 @@ def destination_root=(root) # def relative_to_original_destination_root(path, remove_dot = true) root = @destination_stack[0] - if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ''].include?(path[root.size..root.size]) + if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ""].include?(path[root.size..root.size]) path = path.dup - path[0...root.size] = '.' + path[0...root.size] = "." remove_dot ? (path[2..-1] || "") : path else path @@ -223,8 +223,7 @@ def apply(path, config = {}) contents = if is_uri require "open-uri" - # for ruby 2.1-2.4 - URI.send(:open, path, "Accept" => "application/x-thor-template", &:read) + URI.open(path, "Accept" => "application/x-thor-template", &:read) else File.open(path, &:read) end @@ -285,7 +284,7 @@ def run(command, config = {}) # def run_ruby_script(command, config = {}) return unless behavior == :invoke - run command, config.merge(:with => Thor::Util.ruby_command) + run command, config.merge(with: Thor::Util.ruby_command) end # Run a thor command. A hash of options can be given and it's converted to @@ -316,7 +315,7 @@ def thor(command, *args) args.push Thor::Options.to_switches(config) command = args.join(" ").strip - run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture + run command, with: :thor, verbose: verbose, pretend: pretend, capture: capture end protected @@ -324,7 +323,7 @@ def thor(command, *args) # Allow current root to be shared between invocations. # def _shared_configuration #:nodoc: - super.merge!(:destination_root => destination_root) + super.merge!(destination_root: destination_root) end def _cleanup_options_and_set(options, key) #:nodoc: diff --git a/lib/thor/actions/directory.rb b/lib/thor/actions/directory.rb index e133dc88a..e57bec9e1 100644 --- a/lib/thor/actions/directory.rb +++ b/lib/thor/actions/directory.rb @@ -58,7 +58,7 @@ class Directory < EmptyDirectory #:nodoc: def initialize(base, source, destination = nil, config = {}, &block) @source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first) @block = block - super(base, destination, {:recursive => true}.merge(config)) + super(base, destination, {recursive: true}.merge(config)) end def invoke! diff --git a/lib/thor/actions/empty_directory.rb b/lib/thor/actions/empty_directory.rb index fcd4e30cc..46a602361 100644 --- a/lib/thor/actions/empty_directory.rb +++ b/lib/thor/actions/empty_directory.rb @@ -33,7 +33,7 @@ class EmptyDirectory #:nodoc: # def initialize(base, destination, config = {}) @base = base - @config = {:verbose => true}.merge(config) + @config = {verbose: true}.merge(config) self.destination = destination end diff --git a/lib/thor/actions/file_manipulation.rb b/lib/thor/actions/file_manipulation.rb index 7267092a5..e4aa8e890 100644 --- a/lib/thor/actions/file_manipulation.rb +++ b/lib/thor/actions/file_manipulation.rb @@ -123,12 +123,7 @@ def template(source, *args, &block) context = config.delete(:context) || instance_eval("binding") create_file destination, nil, config do - match = ERB.version.match(/(\d+\.\d+\.\d+)/) - capturable_erb = if match && match[1] >= "2.2.0" # Ruby 2.6+ - CapturableERB.new(::File.binread(source), :trim_mode => "-", :eoutvar => "@output_buffer") - else - CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer") - end + capturable_erb = CapturableERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer") content = capturable_erb.tap do |erb| erb.filename = source end.result(context) diff --git a/lib/thor/actions/inject_into_file.rb b/lib/thor/actions/inject_into_file.rb index 2635e7554..8ba676447 100644 --- a/lib/thor/actions/inject_into_file.rb +++ b/lib/thor/actions/inject_into_file.rb @@ -21,7 +21,7 @@ module Actions # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n") # end # - WARNINGS = { unchanged_no_flag: 'File unchanged! Either the supplied flag value not found or the content has already been inserted!' } + WARNINGS = {unchanged_no_flag: "File unchanged! Either the supplied flag value not found or the content has already been inserted!"} def insert_into_file(destination, *args, &block) data = block_given? ? block : args.shift @@ -37,7 +37,7 @@ class InjectIntoFile < EmptyDirectory #:nodoc: attr_reader :replacement, :flag, :behavior def initialize(base, destination, data, config) - super(base, destination, {:verbose => true}.merge(config)) + super(base, destination, {verbose: true}.merge(config)) @behavior, @flag = if @config.key?(:after) [:after, @config.delete(:after)] diff --git a/lib/thor/base.rb b/lib/thor/base.rb index ac3eba44a..1c4ba08ed 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -24,9 +24,9 @@ class Thor class << self def deprecation_warning(message) #:nodoc: - unless ENV['THOR_SILENCE_DEPRECATION'] + unless ENV["THOR_SILENCE_DEPRECATION"] warn "Deprecation warning: #{message}\n" + - 'You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.' + "You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION." end end end @@ -79,7 +79,7 @@ def initialize(args = [], local_options = {}, config = {}) # Give a relation of options. # After parsing, Thor::Options check whether right relations are kept relations = if current_command.nil? - {:exclusive_option_names => [], :at_least_one_option_names => []} + {exclusive_option_names: [], at_least_one_option_names: []} else current_command.options_relation end @@ -664,7 +664,7 @@ def print_options(shell, options, group_name = nil) end shell.say(group_name ? "#{group_name} options:" : "Options:") - shell.print_table(list, :indent => 2) + shell.print_table(list, indent: 2) shell.say "" end @@ -681,7 +681,7 @@ def is_thor_reserved_word?(word, type) #:nodoc: # options:: Described in both class_option and method_option. # scope:: Options hash that is being built up def build_option(name, options, scope) #:nodoc: - scope[name] = Thor::Option.new(name, {:check_default_type => check_default_type}.merge!(options)) + scope[name] = Thor::Option.new(name, {check_default_type: check_default_type}.merge!(options)) end # Receives a hash of options, parse them and add to the scope. This is a diff --git a/lib/thor/error.rb b/lib/thor/error.rb index 973f7b8ef..11fa250c2 100644 --- a/lib/thor/error.rb +++ b/lib/thor/error.rb @@ -1,26 +1,15 @@ class Thor Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName - # In order to support versions of Ruby that don't have keyword - # arguments, we need our own spell checker class that doesn't take key - # words. Even though this code wouldn't be hit because of the check - # above, it's still necessary because the interpreter would otherwise be - # unable to parse the file. - class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc: - def initialize(dictionary) - @dictionary = dictionary - end - end - - Module.new do - def to_s - super + DidYouMean.formatter.message_for(corrections) - end - - def corrections - @corrections ||= self.class.const_get(:SpellChecker).new(self).corrections - end - end - end + Module.new do + def to_s + super + DidYouMean.formatter.message_for(corrections) + end + + def corrections + @corrections ||= self.class.const_get(:SpellChecker).new(self).corrections + end + end + end # Thor::Error is raised when it's caused by wrong usage of thor classes. Those # errors have their backtrace suppressed and are nicely shown to the user. @@ -45,7 +34,7 @@ def corrections end def spell_checker - NoKwargSpellChecker.new(error.all_commands) + DidYouMean::SpellChecker.new(dictionary: error.all_commands) end end @@ -87,7 +76,7 @@ def corrections end def spell_checker - @spell_checker ||= NoKwargSpellChecker.new(error.switches) + @spell_checker ||= DidYouMean::SpellChecker.new(dictionary: error.switches) end end diff --git a/lib/thor/invocation.rb b/lib/thor/invocation.rb index 4c7f89366..4c0e4fac1 100644 --- a/lib/thor/invocation.rb +++ b/lib/thor/invocation.rb @@ -143,7 +143,7 @@ def invoke_with_padding(*args) # Configuration values that are shared between invocations. def _shared_configuration #:nodoc: - {:invocations => @_invocations} + {invocations: @_invocations} end # This method simply retrieves the class and command to be invoked. diff --git a/lib/thor/nested_context.rb b/lib/thor/nested_context.rb index 74f56bbdb..5460112bb 100644 --- a/lib/thor/nested_context.rb +++ b/lib/thor/nested_context.rb @@ -13,10 +13,10 @@ def enter end def entered? - @depth > 0 + @depth.positive? end - private + private def push @depth += 1 diff --git a/lib/thor/parser/arguments.rb b/lib/thor/parser/arguments.rb index 30c350d00..814cfb87a 100644 --- a/lib/thor/parser/arguments.rb +++ b/lib/thor/parser/arguments.rb @@ -30,11 +30,7 @@ def initialize(arguments = []) arguments.each do |argument| if !argument.default.nil? - begin - @assigns[argument.human_name] = argument.default.dup - rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 - @assigns[argument.human_name] = argument.default - end + @assigns[argument.human_name] = argument.default.dup elsif argument.required? @non_assigned_required << argument end diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index 703352018..bb7fe1527 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -69,7 +69,7 @@ def self.parse(key, value) value.class.name.downcase.to_sym end - new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases) + new(name.to_s, required: required, type: type, default: default, aliases: aliases) end def switch_name @@ -142,8 +142,8 @@ def validate_default_type! raise ArgumentError, err elsif @check_default_type == nil Thor.deprecation_warning "#{err}.\n" + - 'This will be rejected in the future unless you explicitly pass the options `check_default_type: false`' + - ' or call `allow_incompatible_default_type!` in your code' + "This will be rejected in the future unless you explicitly pass the options `check_default_type: false`" + + " or call `allow_incompatible_default_type!` in your code" end end end diff --git a/lib/thor/parser/options.rb b/lib/thor/parser/options.rb index 0c0ac9ae2..ab930d3dc 100644 --- a/lib/thor/parser/options.rb +++ b/lib/thor/parser/options.rb @@ -103,7 +103,7 @@ def parse(args) # rubocop:disable Metrics/MethodLength unshift($1.split("").map { |f| "-#{f}" }) next when EQ_RE - unshift($2, :is_value => true) + unshift($2, is_value: true) switch = $1 when SHORT_NUM unshift($2) diff --git a/lib/thor/runner.rb b/lib/thor/runner.rb index 24accfde5..e1a0f3394 100644 --- a/lib/thor/runner.rb +++ b/lib/thor/runner.rb @@ -23,7 +23,7 @@ def help(meth = nil) initialize_thorfiles(meth) klass, command = Thor::Util.find_class_and_command_by_namespace(meth) self.class.handle_no_command_error(command, false) if klass.nil? - klass.start(["-h", command].compact, :shell => shell) + klass.start(["-h", command].compact, shell: shell) else super end @@ -38,11 +38,11 @@ def method_missing(meth, *args) klass, command = Thor::Util.find_class_and_command_by_namespace(meth) self.class.handle_no_command_error(command, false) if klass.nil? args.unshift(command) if command - klass.start(args, :shell => shell) + klass.start(args, shell: shell) end desc "install NAME", "Install an optionally named Thor file into your system commands" - method_options :as => :string, :relative => :boolean, :force => :boolean + method_options as: :string, relative: :boolean, force: :boolean def install(name) # rubocop:disable Metrics/MethodLength initialize_thorfiles @@ -53,7 +53,7 @@ def install(name) # rubocop:disable Metrics/MethodLength package = :file require "open-uri" begin - contents = URI.send(:open, name, &:read) # Using `send` for Ruby 2.4- support + contents = URI.open(name, &:read) rescue OpenURI::HTTPError raise Error, "Error opening URI '#{name}'" end @@ -69,7 +69,7 @@ def install(name) # rubocop:disable Metrics/MethodLength base = name package = :file require "open-uri" - contents = URI.send(:open, name, &:read) # for ruby 2.1-2.4 + contents = URI.open(name, &:read) end rescue Errno::ENOENT raise Error, "Error opening file '#{name}'" @@ -101,9 +101,9 @@ def install(name) # rubocop:disable Metrics/MethodLength end thor_yaml[as] = { - :filename => Digest::SHA256.hexdigest(name + as), - :location => location, - :namespaces => Thor::Util.namespaces_in_content(contents, base) + filename: Digest::SHA256.hexdigest(name + as), + location: location, + namespaces: Thor::Util.namespaces_in_content(contents, base) } save_yaml(thor_yaml) @@ -164,14 +164,14 @@ def update(name) end desc "installed", "List the installed Thor modules and commands" - method_options :internal => :boolean + method_options internal: :boolean def installed initialize_thorfiles(nil, true) display_klasses(true, options["internal"]) end desc "list [SEARCH]", "List the available thor commands (--substring means .*SEARCH)" - method_options :substring => :boolean, :group => :string, :all => :boolean, :debug => :boolean + method_options substring: :boolean, group: :string, all: :boolean, debug: :boolean def list(search = "") initialize_thorfiles @@ -313,7 +313,7 @@ def display_commands(namespace, list) #:nodoc: say shell.set_color(namespace, :blue, true) say "-" * namespace.size - print_table(list, :truncate => true) + print_table(list, truncate: true) say end alias_method :display_tasks, :display_commands diff --git a/lib/thor/shell.rb b/lib/thor/shell.rb index f3719ce54..0e6113a19 100644 --- a/lib/thor/shell.rb +++ b/lib/thor/shell.rb @@ -75,7 +75,7 @@ def with_padding # Allow shell to be shared between invocations. # def _shared_configuration #:nodoc: - super.merge!(:shell => shell) + super.merge!(shell: shell) end end end diff --git a/lib/thor/shell/basic.rb b/lib/thor/shell/basic.rb index 64e0afe7a..75975f9a0 100644 --- a/lib/thor/shell/basic.rb +++ b/lib/thor/shell/basic.rb @@ -145,14 +145,14 @@ def say_status(status, message, log_status = true) # "yes". # def yes?(statement, color = nil) - !!(ask(statement, color, :add_to_history => false) =~ is?(:yes)) + !!(ask(statement, color, add_to_history: false) =~ is?(:yes)) end # Make a question the to user and returns true if the user replies "n" or # "no". # def no?(statement, color = nil) - !!(ask(statement, color, :add_to_history => false) =~ is?(:no)) + !!(ask(statement, color, add_to_history: false) =~ is?(:no)) end # Prints values in columns @@ -289,7 +289,7 @@ def file_collision(destination) loop do answer = ask( %[Overwrite #{destination}? (enter "h" for help) #{options}], - :add_to_history => false + add_to_history: false ) case answer diff --git a/lib/thor/shell/color.rb b/lib/thor/shell/color.rb index 7bafcd87f..78e507e5a 100644 --- a/lib/thor/shell/color.rb +++ b/lib/thor/shell/color.rb @@ -108,7 +108,7 @@ def are_colors_supported? end def are_colors_disabled? - !ENV['NO_COLOR'].nil? && !ENV['NO_COLOR'].empty? + !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty? end end end diff --git a/lint_gems.rb b/lint_gems.rb deleted file mode 100644 index 8bc06f81a..000000000 --- a/lint_gems.rb +++ /dev/null @@ -1,3 +0,0 @@ -source "https://rubygems.org" - -gem "rubocop", "~> 1.30" diff --git a/spec/actions/create_file_spec.rb b/spec/actions/create_file_spec.rb index 257a95074..963814e17 100644 --- a/spec/actions/create_file_spec.rb +++ b/spec/actions/create_file_spec.rb @@ -8,10 +8,10 @@ end def create_file(destination = nil, config = {}, options = {}, contents = "CONFIGURATION") - @base = MyCounter.new([1, 2], options, :destination_root => destination_root) + @base = MyCounter.new([1, 2], options, destination_root: destination_root) allow(@base).to receive(:file_name).and_return("rdoc") - @action = Thor::Actions::CreateFile.new(@base, destination, contents, {:verbose => !@silence}.merge(config)) + @action = Thor::Actions::CreateFile.new(@base, destination, contents, {verbose: !@silence}.merge(config)) end def invoke! @@ -34,7 +34,7 @@ def silence! end it "allows setting file permissions" do - create_file("config/private.key", :perm => 0o600) + create_file("config/private.key", perm: 0o600) invoke! stat = File.stat(File.join(destination_root, "config/private.key")) @@ -42,7 +42,7 @@ def silence! end it "does not create a file if pretending" do - create_file("doc/config.rb", {}, :pretend => true) + create_file("doc/config.rb", {}, pretend: true) invoke! expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be false end @@ -90,22 +90,22 @@ def silence! end it "shows forced status to the user if force is given" do - expect(create_file("doc/config.rb", {}, :force => true)).not_to be_identical + expect(create_file("doc/config.rb", {}, force: true)).not_to be_identical expect(invoke!).to eq(" force doc/config.rb\n") end it "shows skipped status to the user if skip is given" do - expect(create_file("doc/config.rb", {}, :skip => true)).not_to be_identical + expect(create_file("doc/config.rb", {}, skip: true)).not_to be_identical expect(invoke!).to eq(" skip doc/config.rb\n") end it "shows forced status to the user if force is configured" do - expect(create_file("doc/config.rb", :force => true)).not_to be_identical + expect(create_file("doc/config.rb", force: true)).not_to be_identical expect(invoke!).to eq(" force doc/config.rb\n") end it "shows skipped status to the user if skip is configured" do - expect(create_file("doc/config.rb", :skip => true)).not_to be_identical + expect(create_file("doc/config.rb", skip: true)).not_to be_identical expect(invoke!).to eq(" skip doc/config.rb\n") end diff --git a/spec/actions/create_link_spec.rb b/spec/actions/create_link_spec.rb index 2f79b692f..9625f7367 100644 --- a/spec/actions/create_link_spec.rb +++ b/spec/actions/create_link_spec.rb @@ -2,7 +2,7 @@ require "thor/actions" require "tempfile" -describe Thor::Actions::CreateLink, :unless => windows? do +describe Thor::Actions::CreateLink, unless: windows? do before do @hardlink_to = File.join(Dir.tmpdir, "linkdest.rb") ::FileUtils.rm_rf(destination_root) @@ -13,7 +13,7 @@ let(:options) { {} } let(:base) do - base = MyCounter.new([1, 2], options, :destination_root => destination_root) + base = MyCounter.new([1, 2], options, destination_root: destination_root) allow(base).to receive(:file_name).and_return("rdoc") base end @@ -38,7 +38,7 @@ def revoke! describe "#invoke!" do context "specifying :symbolic => true" do - let(:config) { {:symbolic => true} } + let(:config) { {symbolic: true} } it "creates a symbolic link" do invoke! @@ -49,7 +49,7 @@ def revoke! end context "specifying :symbolic => false" do - let(:config) { {:symbolic => false} } + let(:config) { {symbolic: false} } let(:destination) { @hardlink_to } it "creates a hard link" do @@ -68,7 +68,7 @@ def revoke! end context "specifying :pretend => true" do - let(:options) { {:pretend => true} } + let(:options) { {pretend: true} } it "does not create a link" do invoke! expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be false @@ -80,7 +80,7 @@ def revoke! end context "specifying :verbose => false" do - let(:config) { {:verbose => false} } + let(:config) { {verbose: false} } it "does not show any information" do expect(invoke!).to be_empty end diff --git a/spec/actions/directory_spec.rb b/spec/actions/directory_spec.rb index a1c5860cc..ea80e40f0 100644 --- a/spec/actions/directory_spec.rb +++ b/spec/actions/directory_spec.rb @@ -9,11 +9,11 @@ end def invoker - @invoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root) + @invoker ||= WhinyGenerator.new([1, 2], {}, destination_root: destination_root) end def revoker - @revoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke) + @revoker ||= WhinyGenerator.new([1, 2], {}, destination_root: destination_root, behavior: :revoke) end def invoke!(*args, &block) @@ -42,7 +42,7 @@ def exists_and_identical?(source_path, destination_path) end it "does not create a directory in pretend mode" do - invoke! "doc", "ghost", :pretend => true + invoke! "doc", "ghost", pretend: true expect(File.exist?("ghost")).to be false end @@ -57,7 +57,7 @@ def exists_and_identical?(source_path, destination_path) end it "copies only the first level files if recursive" do - invoke! ".", "commands", :recursive => false + invoke! ".", "commands", recursive: false file = File.join(destination_root, "commands", "group.thor") expect(File.exist?(file)).to be true @@ -70,7 +70,7 @@ def exists_and_identical?(source_path, destination_path) end it "ignores files within excluding/ directories when exclude_pattern is provided" do - invoke! "doc", "docs", :exclude_pattern => %r{excluding/} + invoke! "doc", "docs", exclude_pattern: %r{excluding/} file = File.join(destination_root, "docs", "excluding", "rdoc.rb") expect(File.exist?(file)).to be false end @@ -97,7 +97,7 @@ def exists_and_identical?(source_path, destination_path) end it "copies directories and preserves file mode" do - invoke! "preserve", "preserved", :mode => :preserve + invoke! "preserve", "preserved", mode: :preserve original = File.join(source_root, "preserve", "script.sh") copy = File.join(destination_root, "preserved", "script.sh") expect(File.stat(original).mode).to eq(File.stat(copy).mode) @@ -148,7 +148,7 @@ def exists_and_identical?(source_path, destination_path) expect(content).to match(%r{create app\{1\}/README}) end - context "windows temp directories", :if => windows? do + context "windows temp directories", if: windows? do let(:spec_dir) { File.join(@temp_dir, "spec") } before(:each) do diff --git a/spec/actions/empty_directory_spec.rb b/spec/actions/empty_directory_spec.rb index 7304a24e2..97fe3d95b 100644 --- a/spec/actions/empty_directory_spec.rb +++ b/spec/actions/empty_directory_spec.rb @@ -19,7 +19,7 @@ def revoke! end def base - @base ||= MyCounter.new([1, 2], {}, :destination_root => destination_root) + @base ||= MyCounter.new([1, 2], {}, destination_root: destination_root) end describe "#destination" do @@ -63,7 +63,7 @@ def base end it "does not create a directory if pretending" do - base.inside("foo", :pretend => true) do + base.inside("foo", pretend: true) do empty_directory("ghost") end expect(File.exist?(File.join(base.destination_root, "ghost"))).to be false diff --git a/spec/actions/file_manipulation_spec.rb b/spec/actions/file_manipulation_spec.rb index 8fdd6401f..a1b902af3 100644 --- a/spec/actions/file_manipulation_spec.rb +++ b/spec/actions/file_manipulation_spec.rb @@ -2,7 +2,7 @@ describe Thor::Actions do def runner(options = {}, behavior = :invoke) - @runner ||= MyCounter.new([1], options, :destination_root => destination_root, :behavior => behavior) + @runner ||= MyCounter.new([1], options, destination_root: destination_root, behavior: behavior) end def action(*args, &block) @@ -33,7 +33,7 @@ def file it "does not execute the command if pretending" do expect(FileUtils).not_to receive(:chmod_R) - runner(:pretend => true) + runner(pretend: true) action :chmod, "foo", 0755 end @@ -44,7 +44,7 @@ def file it "does not log status if required" do expect(FileUtils).to receive(:chmod_R).with(0755, file) - expect(action(:chmod, "foo", 0755, :verbose => false)).to be_empty + expect(action(:chmod, "foo", 0755, verbose: false)).to be_empty end end @@ -67,7 +67,7 @@ def file end it "copies file from source to default destination and preserves file mode" do - action :copy_file, "preserve/script.sh", :mode => :preserve + action :copy_file, "preserve/script.sh", mode: :preserve original = File.join(source_root, "preserve/script.sh") copy = File.join(destination_root, "preserve/script.sh") expect(File.stat(original).mode).to eq(File.stat(copy).mode) @@ -75,7 +75,7 @@ def file it "copies file from source to default destination and preserves file mode for templated filenames" do expect(runner).to receive(:filename).and_return("app") - action :copy_file, "preserve/%filename%.sh", :mode => :preserve + action :copy_file, "preserve/%filename%.sh", mode: :preserve original = File.join(source_root, "preserve/%filename%.sh") copy = File.join(destination_root, "preserve/app.sh") expect(File.stat(original).mode).to eq(File.stat(copy).mode) @@ -93,7 +93,7 @@ def file end end - describe "#link_file", :unless => windows? do + describe "#link_file", unless: windows? do it "links file from source to default destination" do action :link_file, "command.thor" exists_and_identical?("command.thor", "command.thor") @@ -144,7 +144,7 @@ def file it "accepts http remote sources" do body = "__start__\nHTTPFILE\n__end__\n" - stub_request(:get, "http://example.com/file.txt").to_return(:body => body.dup) + stub_request(:get, "http://example.com/file.txt").to_return(body: body.dup) action :get, "http://example.com/file.txt" do |content| expect(a_request(:get, "http://example.com/file.txt")).to have_been_made expect(content).to eq(body) @@ -153,7 +153,7 @@ def file it "accepts https remote sources" do body = "__start__\nHTTPSFILE\n__end__\n" - stub_request(:get, "https://example.com/file.txt").to_return(:body => body.dup) + stub_request(:get, "https://example.com/file.txt").to_return(body: body.dup) action :get, "https://example.com/file.txt" do |content| expect(a_request(:get, "https://example.com/file.txt")).to have_been_made expect(content).to eq(body) @@ -163,8 +163,8 @@ def file it "accepts http headers" do body = "__start__\nHTTPFILE\n__end__\n" headers = {"Content-Type" => "application/json"} - stub_request(:get, "https://example.com/file.txt").with(:headers => headers).to_return(:body => body.dup) - action :get, "https://example.com/file.txt", {:http_headers => headers} do |content| + stub_request(:get, "https://example.com/file.txt").with(headers: headers).to_return(body: body.dup) + action :get, "https://example.com/file.txt", {http_headers: headers} do |content| expect(a_request(:get, "https://example.com/file.txt")).to have_been_made expect(content).to eq(body) end @@ -224,7 +224,7 @@ def file it "accepts a context to use as the binding" do begin @klass = "FooBar" - action :template, "doc/config.rb", :context => eval("binding") + action :template, "doc/config.rb", context: eval("binding") expect(File.read(File.join(destination_root, "doc/config.rb"))).to eq("class FooBar; end\n") ensure remove_instance_variable(:@klass) @@ -279,7 +279,7 @@ def file end it "does not remove if pretending" do - runner(:pretend => true) + runner(pretend: true) action :remove_file, "doc/README" expect(File.exist?(file)).to be true end @@ -289,7 +289,7 @@ def file end it "does not log status if required" do - expect(action(:remove_file, "doc/README", :verbose => false)).to be_empty + expect(action(:remove_file, "doc/README", verbose: false)).to be_empty end end @@ -301,7 +301,7 @@ def file end it "does not replace if pretending" do - runner(:pretend => true) + runner(pretend: true) action :gsub_file, "doc/README", "__start__", "START" expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") end @@ -316,7 +316,7 @@ def file end it "does not log status if required" do - expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty + expect(action(:gsub_file, file, "__", verbose: false) { |match| match * 2 }).to be_empty end end @@ -329,7 +329,7 @@ def file end it "does not replace if pretending" do - runner({:pretend => true}, :revoke) + runner({pretend: true}, :revoke) action :gsub_file, "doc/README", "__start__", "START" expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") end @@ -347,37 +347,37 @@ def file it "does not log status if required" do runner({}, :revoke) - expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty + expect(action(:gsub_file, file, "__", verbose: false) { |match| match * 2 }).to be_empty end end context "and force option" do it "replaces the content in the file" do runner({}, :revoke) - action :gsub_file, "doc/README", "__start__", "START", :force => true + action :gsub_file, "doc/README", "__start__", "START", force: true expect(File.binread(file)).to eq("START\nREADME\n__end__\n") end it "does not replace if pretending" do - runner({:pretend => true}, :revoke) - action :gsub_file, "doc/README", "__start__", "START", :force => true + runner({pretend: true}, :revoke) + action :gsub_file, "doc/README", "__start__", "START", force: true expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") end it "replaces the content in the file when given a block" do runner({}, :revoke) - action(:gsub_file, "doc/README", "__start__", :force => true) { |match| match.gsub("__", "").upcase } + action(:gsub_file, "doc/README", "__start__", force: true) { |match| match.gsub("__", "").upcase } expect(File.binread(file)).to eq("START\nREADME\n__end__\n") end it "logs status" do runner({}, :revoke) - expect(action(:gsub_file, "doc/README", "__start__", "START", :force => true)).to eq(" gsub doc/README\n") + expect(action(:gsub_file, "doc/README", "__start__", "START", force: true)).to eq(" gsub doc/README\n") end it "does not log status if required" do runner({}, :revoke) - expect(action(:gsub_file, file, "__", :verbose => false, :force => true) { |match| match * 2 }).to be_empty + expect(action(:gsub_file, file, "__", verbose: false, force: true) { |match| match * 2 }).to be_empty end end end diff --git a/spec/actions/inject_into_file_spec.rb b/spec/actions/inject_into_file_spec.rb index 617d2705c..c610cd92d 100644 --- a/spec/actions/inject_into_file_spec.rb +++ b/spec/actions/inject_into_file_spec.rb @@ -9,11 +9,11 @@ end def invoker(options = {}) - @invoker ||= MyCounter.new([1, 2], options, :destination_root => destination_root) + @invoker ||= MyCounter.new([1, 2], options, destination_root: destination_root) end def revoker - @revoker ||= MyCounter.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke) + @revoker ||= MyCounter.new([1, 2], {}, destination_root: destination_root, behavior: :revoke) end def invoke!(*args, &block) @@ -30,12 +30,12 @@ def file describe "#invoke!" do it "changes the file adding content after the flag" do - invoke! "doc/README", "\nmore content", :after => "__start__" + invoke! "doc/README", "\nmore content", after: "__start__" expect(File.read(file)).to eq("__start__\nmore content\nREADME\n__end__\n") end it "changes the file adding content before the flag" do - invoke! "doc/README", "more content\n", :before => "__end__" + invoke! "doc/README", "more content\n", before: "__end__" expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") end @@ -51,7 +51,7 @@ def file end it "accepts data as a block" do - invoke! "doc/README", :before => "__end__" do + invoke! "doc/README", before: "__end__" do "more content\n" end @@ -59,28 +59,28 @@ def file end it "logs status" do - expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n") + expect(invoke!("doc/README", "\nmore content", after: "__start__")).to eq(" insert doc/README\n") end it "logs status if pretending" do - invoker(:pretend => true) - expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n") + invoker(pretend: true) + expect(invoke!("doc/README", "\nmore content", after: "__start__")).to eq(" insert doc/README\n") end it "does not change the file if pretending" do - invoker :pretend => true - invoke! "doc/README", "\nmore content", :after => "__start__" + invoker pretend: true + invoke! "doc/README", "\nmore content", after: "__start__" expect(File.read(file)).to eq("__start__\nREADME\n__end__\n") end it "does not change the file if already includes content" do - invoke! "doc/README", :before => "__end__" do + invoke! "doc/README", before: "__end__" do "more content\n" end expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") - invoke! "doc/README", :before => "__end__" do + invoke! "doc/README", before: "__end__" do "more content\n" end @@ -88,13 +88,13 @@ def file end it "does not change the file if already includes content using before with capture" do - invoke! "doc/README", :before => /(__end__)/ do + invoke! "doc/README", before: /(__end__)/ do "more content\n" end expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") - invoke! "doc/README", :before => /(__end__)/ do + invoke! "doc/README", before: /(__end__)/ do "more content\n" end @@ -102,13 +102,13 @@ def file end it "does not change the file if already includes content using after with capture" do - invoke! "doc/README", :after => /(README\n)/ do + invoke! "doc/README", after: /(README\n)/ do "more content\n" end expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") - invoke! "doc/README", :after => /(README\n)/ do + invoke! "doc/README", after: /(README\n)/ do "more content\n" end @@ -117,7 +117,7 @@ def file it "does not attempt to change the file if it doesn't exist - instead raises Thor::Error" do expect do - invoke! "idontexist", :before => "something" do + invoke! "idontexist", before: "something" do "any content" end end.to raise_error(Thor::Error, /does not appear to exist/) @@ -126,8 +126,8 @@ def file it "does not attempt to change the file if it doesn't exist and pretending" do expect do - invoker :pretend => true - invoke! "idontexist", :before => "something" do + invoker pretend: true + invoke! "idontexist", before: "something" do "any content" end end.not_to raise_error @@ -135,13 +135,13 @@ def file end it "does change the file if already includes content and :force is true" do - invoke! "doc/README", :before => "__end__" do + invoke! "doc/README", before: "__end__" do "more content\n" end expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") - invoke! "doc/README", :before => "__end__", :force => true do + invoke! "doc/README", before: "__end__", force: true do "more content\n" end @@ -153,7 +153,7 @@ def file begin Encoding.default_external = Encoding.find("UTF-8") - invoke! "doc/README.zh", "\n中文", :after => "__start__" + invoke! "doc/README.zh", "\n中文", after: "__start__" expect(File.read(File.join(destination_root, "doc/README.zh"))).to eq("__start__\n中文\n说明\n__end__\n") ensure Encoding.default_external = encoding_original @@ -163,48 +163,48 @@ def file describe "#revoke!" do it "subtracts the destination file after injection" do - invoke! "doc/README", "\nmore content", :after => "__start__" - revoke! "doc/README", "\nmore content", :after => "__start__" + invoke! "doc/README", "\nmore content", after: "__start__" + revoke! "doc/README", "\nmore content", after: "__start__" expect(File.read(file)).to eq("__start__\nREADME\n__end__\n") end it "subtracts the destination file before injection" do - invoke! "doc/README", "more content\n", :before => "__start__" - revoke! "doc/README", "more content\n", :before => "__start__" + invoke! "doc/README", "more content\n", before: "__start__" + revoke! "doc/README", "more content\n", before: "__start__" expect(File.read(file)).to eq("__start__\nREADME\n__end__\n") end it "subtracts even with double after injection" do - invoke! "doc/README", "\nmore content", :after => "__start__" - invoke! "doc/README", "\nanother stuff", :after => "__start__" - revoke! "doc/README", "\nmore content", :after => "__start__" + invoke! "doc/README", "\nmore content", after: "__start__" + invoke! "doc/README", "\nanother stuff", after: "__start__" + revoke! "doc/README", "\nmore content", after: "__start__" expect(File.read(file)).to eq("__start__\nanother stuff\nREADME\n__end__\n") end it "subtracts even with double before injection" do - invoke! "doc/README", "more content\n", :before => "__start__" - invoke! "doc/README", "another stuff\n", :before => "__start__" - revoke! "doc/README", "more content\n", :before => "__start__" + invoke! "doc/README", "more content\n", before: "__start__" + invoke! "doc/README", "another stuff\n", before: "__start__" + revoke! "doc/README", "more content\n", before: "__start__" expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n") end it "subtracts when prepending" do - invoke! "doc/README", "more content\n", :after => /\A/ - invoke! "doc/README", "another stuff\n", :after => /\A/ - revoke! "doc/README", "more content\n", :after => /\A/ + invoke! "doc/README", "more content\n", after: /\A/ + invoke! "doc/README", "another stuff\n", after: /\A/ + revoke! "doc/README", "more content\n", after: /\A/ expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n") end it "subtracts when appending" do - invoke! "doc/README", "more content\n", :before => /\z/ - invoke! "doc/README", "another stuff\n", :before => /\z/ - revoke! "doc/README", "more content\n", :before => /\z/ + invoke! "doc/README", "more content\n", before: /\z/ + invoke! "doc/README", "another stuff\n", before: /\z/ + revoke! "doc/README", "more content\n", before: /\z/ expect(File.read(file)).to eq("__start__\nREADME\n__end__\nanother stuff\n") end it "shows progress information to the user" do - invoke!("doc/README", "\nmore content", :after => "__start__") - expect(revoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" subtract doc/README\n") + invoke!("doc/README", "\nmore content", after: "__start__") + expect(revoke!("doc/README", "\nmore content", after: "__start__")).to eq(" subtract doc/README\n") end end end diff --git a/spec/actions_spec.rb b/spec/actions_spec.rb index ee050deb1..f34de63a3 100644 --- a/spec/actions_spec.rb +++ b/spec/actions_spec.rb @@ -2,7 +2,7 @@ describe Thor::Actions do def runner(options = {}) - @runner ||= MyCounter.new([1], options, :destination_root => destination_root) + @runner ||= MyCounter.new([1], options, destination_root: destination_root) end def action(*args, &block) @@ -28,18 +28,18 @@ def file end it "can have behavior revoke" do - expect(MyCounter.new([1], {}, :behavior => :revoke).behavior).to eq(:revoke) + expect(MyCounter.new([1], {}, behavior: :revoke).behavior).to eq(:revoke) end it "when behavior is set to force, overwrite options" do - runner = MyCounter.new([1], {:force => false, :skip => true}, :behavior => :force) + runner = MyCounter.new([1], {force: false, skip: true}, behavior: :force) expect(runner.behavior).to eq(:invoke) expect(runner.options.force).to be true expect(runner.options.skip).not_to be true end it "when behavior is set to skip, overwrite options" do - runner = MyCounter.new([1], %w(--force), :behavior => :skip) + runner = MyCounter.new([1], %w(--force), behavior: :skip) expect(runner.behavior).to eq(:invoke) expect(runner.options.force).not_to be true expect(runner.options.skip).to be true @@ -102,7 +102,7 @@ def file end it "does not fail with files containing regexp characters" do - runner = MyCounter.new([1], {}, :destination_root => File.join(destination_root, "fo[o-b]ar")) + runner = MyCounter.new([1], {}, destination_root: File.join(destination_root, "fo[o-b]ar")) expect(runner.relative_to_original_destination_root("bar")).to eq("bar") end @@ -171,7 +171,7 @@ def file describe "when pretending" do it "no directories should be created" do - runner.inside("bar", :pretend => true) {} + runner.inside("bar", pretend: true) {} expect(File.exist?("bar")).to be false end @@ -183,13 +183,13 @@ def file describe "when verbose" do it "logs status" do expect(capture(:stdout) do - runner.inside("foo", :verbose => true) {} + runner.inside("foo", verbose: true) {} end).to match(/inside foo/) end it "uses padding in next status" do expect(capture(:stdout) do - runner.inside("foo", :verbose => true) do + runner.inside("foo", verbose: true) do runner.say_status :cool, :padding end end).to match(/cool padding/) @@ -197,7 +197,7 @@ def file it "removes padding after block" do expect(capture(:stdout) do - runner.inside("foo", :verbose => true) {} + runner.inside("foo", verbose: true) {} runner.say_status :no, :padding end).to match(/no padding/) end @@ -273,7 +273,7 @@ def file end it "does not log status" do - content = action(:apply, @file, :verbose => false) + content = action(:apply, @file, verbose: false) expect(content).to match(/cool padding/) expect(content).not_to match(/apply http/) end @@ -294,12 +294,12 @@ def file end it "does not log status if required" do - expect(action(:run, "ls", :verbose => false)).to be_empty + expect(action(:run, "ls", verbose: false)).to be_empty end it "accepts a color as status" do expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow) - action :run, "ls", :verbose => :yellow + action :run, "ls", verbose: :yellow end end @@ -307,36 +307,36 @@ def file it "doesn't execute the command" do runner = MyCounter.new([1], %w(--pretend)) expect(runner).not_to receive(:system) - runner.run("ls", :verbose => false) + runner.run("ls", verbose: false) end end describe "when not capturing" do it "aborts when abort_on_failure is given and command fails" do - expect { action :run, "false", :abort_on_failure => true }.to raise_error(SystemExit) + expect { action :run, "false", abort_on_failure: true }.to raise_error(SystemExit) end it "succeeds when abort_on_failure is given and command succeeds" do - expect { action :run, "true", :abort_on_failure => true }.not_to raise_error + expect { action :run, "true", abort_on_failure: true }.not_to raise_error end it "supports env option" do - expect { action :run, "echo $BAR", :env => { "BAR" => "foo" } }.to output("foo\n").to_stdout_from_any_process + expect { action :run, "echo $BAR", env: {"BAR" => "foo"} }.to output("foo\n").to_stdout_from_any_process end end describe "when capturing" do it "aborts when abort_on_failure is given, capture is given and command fails" do - expect { action :run, "false", :abort_on_failure => true, :capture => true }.to raise_error(SystemExit) + expect { action :run, "false", abort_on_failure: true, capture: true }.to raise_error(SystemExit) end it "succeeds when abort_on_failure is given and command succeeds" do - expect { action :run, "true", :abort_on_failure => true, :capture => true }.not_to raise_error + expect { action :run, "true", abort_on_failure: true, capture: true }.not_to raise_error end it "supports env option" do silence(:stdout) do - expect(runner.run "echo $BAR", :env => { "BAR" => "foo" }, :capture => true).to eq("foo\n") + expect(runner.run "echo $BAR", env: {"BAR" => "foo"}, capture: true).to eq("foo\n") end end end @@ -351,7 +351,7 @@ def file end it "does not abort when abort_on_failure is false even if the command fails" do - expect { action :run, "false", :abort_on_failure => false }.not_to raise_error + expect { action :run, "false", abort_on_failure: false }.not_to raise_error end end end @@ -371,14 +371,14 @@ def file end it "does not log status if required" do - expect(action(:run_ruby_script, "script.rb", :verbose => false)).to be_empty + expect(action(:run_ruby_script, "script.rb", verbose: false)).to be_empty end end describe "#thor" do it "executes the thor command" do expect(runner).to receive(:system).with("thor list") - action :thor, :list, :verbose => true + action :thor, :list, verbose: true end it "converts extra arguments to command arguments" do @@ -388,10 +388,10 @@ def file it "converts options hash to switches" do expect(runner).to receive(:system).with("thor list foo bar --foo") - action :thor, :list, "foo", "bar", :foo => true + action :thor, :list, "foo", "bar", foo: true expect(runner).to receive(:system).with("thor list --foo 1 2 3") - action :thor, :list, :foo => [1, 2, 3] + action :thor, :list, foo: [1, 2, 3] end it "logs status" do @@ -401,12 +401,12 @@ def file it "does not log status if required" do expect(runner).to receive(:system).with("thor list --foo 1 2 3") - expect(action(:thor, :list, :foo => [1, 2, 3], :verbose => false)).to be_empty + expect(action(:thor, :list, foo: [1, 2, 3], verbose: false)).to be_empty end it "captures the output when :capture is given" do - expect(runner).to receive(:run).with("list", hash_including(:capture => true)) - action :thor, :list, :capture => true + expect(runner).to receive(:run).with("list", hash_including(capture: true)) + action :thor, :list, capture: true end end end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index cecb7e3c3..989fb1628 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -27,7 +27,7 @@ def hello end it "allows options to be given as symbols or strings" do - base = MyCounter.new [1, 2], :third => 4 + base = MyCounter.new [1, 2], third: 4 expect(base.options[:third]).to eq(4) base = MyCounter.new [1, 2], "third" => 4 @@ -35,12 +35,12 @@ def hello end it "creates options with indifferent access" do - base = MyCounter.new [1, 2], :third => 3 + base = MyCounter.new [1, 2], third: 3 expect(base.options["third"]).to eq(3) end it "creates options with magic predicates" do - base = MyCounter.new [1, 2], :third => 3 + base = MyCounter.new [1, 2], third: 3 expect(base.options.third).to eq(3) end end @@ -313,7 +313,7 @@ def hello it "raises an error instead of rescuing if :debug option is given" do expect do - MyScript.start %w(what), :debug => true + MyScript.start %w(what), debug: true end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.') end diff --git a/spec/command_spec.rb b/spec/command_spec.rb index 4e9df7e8b..7e409933f 100644 --- a/spec/command_spec.rb +++ b/spec/command_spec.rb @@ -12,28 +12,28 @@ def command(options = {}, usage = "can_has") describe "#formatted_usage" do it "includes namespace within usage" do object = Struct.new(:namespace, :arguments).new("foo", []) - expect(command(:bar => :required).formatted_usage(object)).to eq("foo:can_has --bar=BAR") + expect(command(bar: :required).formatted_usage(object)).to eq("foo:can_has --bar=BAR") end it "includes subcommand name within subcommand usage" do object = Struct.new(:namespace, :arguments).new("main:foo", []) - expect(command(:bar => :required).formatted_usage(object, false, true)).to eq("foo can_has --bar=BAR") + expect(command(bar: :required).formatted_usage(object, false, true)).to eq("foo can_has --bar=BAR") end it "removes default from namespace" do object = Struct.new(:namespace, :arguments).new("default:foo", []) - expect(command(:bar => :required).formatted_usage(object)).to eq(":foo:can_has --bar=BAR") + expect(command(bar: :required).formatted_usage(object)).to eq(":foo:can_has --bar=BAR") end it "injects arguments into usage" do - options = {:required => true, :type => :string} + options = {required: true, type: :string} object = Struct.new(:namespace, :arguments).new("foo", [Thor::Argument.new(:bar, options)]) - expect(command(:foo => :required).formatted_usage(object)).to eq("foo:can_has BAR --foo=FOO") + expect(command(foo: :required).formatted_usage(object)).to eq("foo:can_has BAR --foo=FOO") end it "allows multiple usages" do object = Struct.new(:namespace, :arguments).new("foo", []) - expect(command({ :bar => :required }, ["can_has FOO", "can_has BAR"]).formatted_usage(object, false)).to eq("can_has FOO --bar=BAR\ncan_has BAR --bar=BAR") + expect(command({bar: :required}, ["can_has FOO", "can_has BAR"]).formatted_usage(object, false)).to eq("can_has FOO --bar=BAR\ncan_has BAR --bar=BAR") end end @@ -54,7 +54,7 @@ def command(options = {}, usage = "can_has") describe "#dup" do it "dup options hash" do - command = Thor::Command.new("can_has", nil, nil, nil, :foo => true, :bar => :required) + command = Thor::Command.new("can_has", nil, nil, nil, foo: true, bar: :required) command.dup.options.delete(:foo) expect(command.options[:foo]).to be end diff --git a/spec/group_spec.rb b/spec/group_spec.rb index 5a088c190..660a40d55 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -23,7 +23,7 @@ it "raises an error if a required argument is added after a non-required" do expect do - MyCounter.argument(:foo, :type => :string) + MyCounter.argument(:foo, type: :string) end.to raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".') end @@ -186,8 +186,8 @@ it "can handle boolean options followed by arguments" do klass = Class.new(Thor::Group) do desc "say hi to name" - argument :name, :type => :string - class_option :loud, :type => :boolean + argument :name, type: :string + class_option :loud, type: :boolean def hi self.name = name.upcase if options[:loud] @@ -203,8 +203,8 @@ def hi it "provides extra args as `args`" do klass = Class.new(Thor::Group) do desc "say hi to name" - argument :name, :type => :string - class_option :loud, :type => :boolean + argument :name, type: :string + class_option :loud, type: :boolean def hi self.name = name.upcase if options[:loud] diff --git a/spec/helper.rb b/spec/helper.rb index d3df9a9b9..b322f4464 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,15 +1,13 @@ $TESTING = true -if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0") - require "simplecov" - require "coveralls" +require "simplecov" +require "coveralls" - SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] +SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] - SimpleCov.start do - add_filter "/spec" - minimum_coverage(90) - end +SimpleCov.start do + add_filter "/spec" + minimum_coverage(90) end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) @@ -22,7 +20,7 @@ require "diff/lcs" # You need diff/lcs installed to run specs (but not to run Thor). require "webmock/rspec" -WebMock.disable_net_connect!(:allow => "coveralls.io") +WebMock.disable_net_connect!(allow: "coveralls.io") # Set shell to basic ENV["THOR_COLUMNS"] = "10000" diff --git a/spec/invocation_spec.rb b/spec/invocation_spec.rb index eb6d805d2..e584eba77 100644 --- a/spec/invocation_spec.rb +++ b/spec/invocation_spec.rb @@ -33,13 +33,13 @@ end it "accepts a class as argument with a command to invoke" do - base = A.new([], :last_name => "Valim") + base = A.new([], last_name: "Valim") expect(base.invoke(B, :one, %w(Jose))).to eq("Valim, Jose") end it "allows customized options to be given" do - base = A.new([], :last_name => "Wrong") - expect(base.invoke(B, :one, %w(Jose), :last_name => "Valim")).to eq("Valim, Jose") + base = A.new([], last_name: "Wrong") + expect(base.invoke(B, :one, %w(Jose), last_name: "Valim")).to eq("Valim, Jose") end it "reparses options in the new class" do @@ -47,7 +47,7 @@ end it "shares initialize options with invoked class" do - expect(A.new([], :foo => :bar).invoke("b:two")).to eq("foo" => :bar) + expect(A.new([], foo: :bar).invoke("b:two")).to eq("foo" => :bar) end it "uses default options from invoked class if no matching arguments are given" do @@ -55,7 +55,7 @@ end it "overrides default options if options are passed to the invoker" do - expect(A.new([], :defaulted_value => "not default").invoke("b:four")).to eq("not default") + expect(A.new([], defaulted_value: "not default").invoke("b:four")).to eq("not default") end it "returns the command chain" do @@ -72,7 +72,7 @@ it "allow extra configuration values to be given" do base = A.new shell = Thor::Base.shell.new - expect(base.invoke("b:three", [], {}, :shell => shell).shell).to eq(shell) + expect(base.invoke("b:three", [], {}, shell: shell).shell).to eq(shell) end it "invokes a Thor::Group and all of its commands" do diff --git a/spec/line_editor/basic_spec.rb b/spec/line_editor/basic_spec.rb index 0aefe8c74..df88dc595 100644 --- a/spec/line_editor/basic_spec.rb +++ b/spec/line_editor/basic_spec.rb @@ -21,7 +21,7 @@ noecho_stdin = double("noecho_stdin") expect(noecho_stdin).to receive(:gets).and_return("secret") expect($stdin).to receive(:noecho).and_yield(noecho_stdin) - editor = Thor::LineEditor::Basic.new("Password: ", :echo => false) + editor = Thor::LineEditor::Basic.new("Password: ", echo: false) expect(editor.readline).to eq("secret") end end diff --git a/spec/line_editor/readline_spec.rb b/spec/line_editor/readline_spec.rb index 7ab67aaa9..a7daa8bd4 100644 --- a/spec/line_editor/readline_spec.rb +++ b/spec/line_editor/readline_spec.rb @@ -33,7 +33,7 @@ it "supports the add_to_history option" do expect(::Readline).to receive(:readline).with("> ", false).and_return("foo") expect(::Readline).to_not receive(:completion_proc=) - editor = Thor::LineEditor::Readline.new("> ", :add_to_history => false) + editor = Thor::LineEditor::Readline.new("> ", add_to_history: false) expect(editor.readline).to eq("foo") end @@ -45,7 +45,7 @@ expect(proc.call("Chi")).to eq ["Chicken"] end - editor = Thor::LineEditor::Readline.new("Best food: ", :limited_to => %w(Apples Chicken Chocolate)) + editor = Thor::LineEditor::Readline.new("Best food: ", limited_to: %w(Apples Chicken Chocolate)) editor.readline end @@ -55,7 +55,7 @@ expect(proc.call("../line_ed").sort).to eq ["../line_editor/", "../line_editor_spec.rb"].sort end - editor = Thor::LineEditor::Readline.new("Path to file: ", :path => true) + editor = Thor::LineEditor::Readline.new("Path to file: ", path: true) Dir.chdir(File.dirname(__FILE__)) { editor.readline } end @@ -64,7 +64,7 @@ noecho_stdin = double("noecho_stdin") expect(noecho_stdin).to receive(:gets).and_return("secret") expect($stdin).to receive(:noecho).and_yield(noecho_stdin) - editor = Thor::LineEditor::Readline.new("Password: ", :echo => false) + editor = Thor::LineEditor::Readline.new("Password: ", echo: false) expect(editor.readline).to eq("secret") end end diff --git a/spec/line_editor_spec.rb b/spec/line_editor_spec.rb index 5e91d092d..4f1ff24a5 100644 --- a/spec/line_editor_spec.rb +++ b/spec/line_editor_spec.rb @@ -16,9 +16,9 @@ describe ".readline" do it "uses the Readline line editor" do editor = double("Readline") - expect(Thor::LineEditor::Readline).to receive(:new).with("Enter your name ", {:default => "Brian"}).and_return(editor) + expect(Thor::LineEditor::Readline).to receive(:new).with("Enter your name ", {default: "Brian"}).and_return(editor) expect(editor).to receive(:readline).and_return("George") - expect(Thor::LineEditor.readline("Enter your name ", :default => "Brian")).to eq("George") + expect(Thor::LineEditor.readline("Enter your name ", default: "Brian")).to eq("George") end end end @@ -36,9 +36,9 @@ describe ".readline" do it "uses the Basic line editor" do editor = double("Basic") - expect(Thor::LineEditor::Basic).to receive(:new).with("Enter your name ", {:default => "Brian"}).and_return(editor) + expect(Thor::LineEditor::Basic).to receive(:new).with("Enter your name ", {default: "Brian"}).and_return(editor) expect(editor).to receive(:readline).and_return("George") - expect(Thor::LineEditor.readline("Enter your name ", :default => "Brian")).to eq("George") + expect(Thor::LineEditor.readline("Enter your name ", default: "Brian")).to eq("George") end end end diff --git a/spec/parser/argument_spec.rb b/spec/parser/argument_spec.rb index 72debd54d..25ac55043 100644 --- a/spec/parser/argument_spec.rb +++ b/spec/parser/argument_spec.rb @@ -15,61 +15,61 @@ def argument(name, options = {}) it "raises an error if type is unknown" do expect do - argument(:command, :type => :unknown) + argument(:command, type: :unknown) end.to raise_error(ArgumentError, "Type :unknown is not valid for arguments.") end it "raises an error if argument is required and has default values" do expect do - argument(:command, :type => :string, :default => "bar", :required => true) + argument(:command, type: :string, default: "bar", required: true) end.to raise_error(ArgumentError, "An argument cannot be required and have default value.") end it "raises an error if enum isn't an array" do expect do - argument(:command, :type => :string, :enum => "bar") + argument(:command, type: :string, enum: "bar") end.to raise_error(ArgumentError, "An argument cannot have an enum other than an array.") end end describe "#usage" do it "returns usage for string types" do - expect(argument(:foo, :type => :string).usage).to eq("FOO") + expect(argument(:foo, type: :string).usage).to eq("FOO") end it "returns usage for numeric types" do - expect(argument(:foo, :type => :numeric).usage).to eq("N") + expect(argument(:foo, type: :numeric).usage).to eq("N") end it "returns usage for array types" do - expect(argument(:foo, :type => :array).usage).to eq("one two three") + expect(argument(:foo, type: :array).usage).to eq("one two three") end it "returns usage for hash types" do - expect(argument(:foo, :type => :hash).usage).to eq("key:value") + expect(argument(:foo, type: :hash).usage).to eq("key:value") end end describe "#print_default" do it "prints arrays in a copy pasteable way" do expect(argument(:foo, { - :required => false, - :type => :array, - :default => ["one","two"] + required: false, + type: :array, + default: ["one","two"] }).print_default).to eq('"one" "two"') end it "prints arrays with a single string default as before" do expect(argument(:foo, { - :required => false, - :type => :array, - :default => "foobar" + required: false, + type: :array, + default: "foobar" }).print_default).to eq("foobar") end it "prints none arrays as default" do expect(argument(:foo, { - :required => false, - :type => :numeric, - :default => 13, + required: false, + type: :numeric, + default: 13, }).print_default).to eq(13) end end diff --git a/spec/parser/arguments_spec.rb b/spec/parser/arguments_spec.rb index ab5d9d7f6..4e60f8add 100644 --- a/spec/parser/arguments_spec.rb +++ b/spec/parser/arguments_spec.rb @@ -4,7 +4,7 @@ describe Thor::Arguments do def create(opts = {}) arguments = opts.map do |type, default| - options = {:required => default.nil?, :type => type, :default => default} + options = {required: default.nil?, type: type, default: default} Thor::Argument.new(type.to_s, options) end @@ -18,7 +18,7 @@ def parse(*args) describe "#parse" do it "parses arguments in the given order" do - create :string => nil, :numeric => nil + create string: nil, numeric: nil expect(parse("name", "13")["string"]).to eq("name") expect(parse("name", "13")["numeric"]).to eq(13) expect(parse("name", "+13")["numeric"]).to eq(13) @@ -28,20 +28,20 @@ def parse(*args) end it "accepts hashes" do - create :string => nil, :hash => nil + create string: nil, hash: nil expect(parse("product", "title:string", "age:integer")["string"]).to eq("product") expect(parse("product", "title:string", "age:integer")["hash"]).to eq("title" => "string", "age" => "integer") expect(parse("product", "url:http://www.amazon.com/gp/product/123")["hash"]).to eq("url" => "http://www.amazon.com/gp/product/123") end it "accepts arrays" do - create :string => nil, :array => nil + create string: nil, array: nil expect(parse("product", "title", "age")["string"]).to eq("product") expect(parse("product", "title", "age")["array"]).to eq(%w(title age)) end it "accepts - as an array argument" do - create :array => nil + create array: nil expect(parse("-")["array"]).to eq(%w(-)) expect(parse("-", "title", "-")["array"]).to eq(%w(- title -)) end @@ -53,23 +53,23 @@ def parse(*args) end it "and required arguments raises an error" do - create :string => nil, :numeric => nil + create string: nil, numeric: nil expect { parse }.to raise_error(Thor::RequiredArgumentMissingError, "No value provided for required arguments 'string', 'numeric'") end it "and default arguments returns default values" do - create :string => "name", :numeric => 13 + create string: "name", numeric: 13 expect(parse).to eq("string" => "name", "numeric" => 13) end end it "returns the input if it's already parsed" do - create :string => nil, :hash => nil, :array => nil, :numeric => nil + create string: nil, hash: nil, array: nil, numeric: nil expect(parse("", 0, {}, [])).to eq("string" => "", "numeric" => 0, "hash" => {}, "array" => []) end it "returns the default value if none is provided" do - create :string => "foo", :numeric => 3.0 + create string: "foo", numeric: 3.0 expect(parse("bar")).to eq("string" => "bar", "numeric" => 3.0) end end diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 8485e9ec3..3e5cff90d 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -47,11 +47,11 @@ def option(name, options = {}) describe "with value as hash" do it "has default type :hash" do - expect(parse(:foo, :a => :b).type).to eq(:hash) + expect(parse(:foo, a: :b).type).to eq(:hash) end it "has default value equal to the hash" do - expect(parse(:foo, :a => :b).default).to eq(:a => :b) + expect(parse(:foo, a: :b).default).to eq(a: :b) end end @@ -129,62 +129,62 @@ def option(name, options = {}) end it "can be required and have default values" do - option = option("foo", :required => true, :type => :string, :default => "bar") + option = option("foo", required: true, type: :string, default: "bar") expect(option.default).to eq("bar") expect(option).to be_required end it "raises an error if default is inconsistent with type and check_default_type is true" do expect do - option("foo_bar", :type => :numeric, :default => "baz", :check_default_type => true) + option("foo_bar", type: :numeric, default: "baz", check_default_type: true) end.to raise_error(ArgumentError, 'Expected numeric default value for \'--foo-bar\'; got "baz" (string)') end it "raises an error if repeatable and default is inconsistent with type and check_default_type is true" do expect do - option("foo_bar", :type => :numeric, :repeatable => true, :default => "baz", :check_default_type => true) + option("foo_bar", type: :numeric, repeatable: true, default: "baz", check_default_type: true) end.to raise_error(ArgumentError, 'Expected array default value for \'--foo-bar\'; got "baz" (string)') end it "raises an error type hash is repeatable and default is inconsistent with type and check_default_type is true" do expect do - option("foo_bar", :type => :hash, :repeatable => true, :default => "baz", :check_default_type => true) + option("foo_bar", type: :hash, repeatable: true, default: "baz", check_default_type: true) end.to raise_error(ArgumentError, 'Expected hash default value for \'--foo-bar\'; got "baz" (string)') end it "does not raises an error if type hash is repeatable and default is consistent with type and check_default_type is true" do expect do - option("foo_bar", :type => :hash, :repeatable => true, :default => {}, :check_default_type => true) + option("foo_bar", type: :hash, repeatable: true, default: {}, check_default_type: true) end.not_to raise_error end it "does not raises an error if repeatable and default is consistent with type and check_default_type is true" do expect do - option("foo_bar", :type => :numeric, :repeatable => true, :default => [1], :check_default_type => true) + option("foo_bar", type: :numeric, repeatable: true, default: [1], check_default_type: true) end.not_to raise_error end it "does not raises an error if default is an symbol and type string and check_default_type is true" do expect do - option("foo", :type => :string, :default => :bar, :check_default_type => true) + option("foo", type: :string, default: :bar, check_default_type: true) end.not_to raise_error end it "does not raises an error if default is inconsistent with type and check_default_type is false" do expect do - option("foo_bar", :type => :numeric, :default => "baz", :check_default_type => false) + option("foo_bar", type: :numeric, default: "baz", check_default_type: false) end.not_to raise_error end it "boolean options cannot be required" do expect do - option("foo", :required => true, :type => :boolean) + option("foo", required: true, type: :boolean) end.to raise_error(ArgumentError, "An option cannot be boolean and required.") end it "does not raises an error if default is a boolean and it is required" do expect do - option("foo", :required => true, :default => true) + option("foo", required: true, default: true) end.not_to raise_error end @@ -242,11 +242,11 @@ def option(name, options = {}) end it "uses banner when supplied" do - expect(option(:foo, :required => false, :type => :string, :banner => "BAR").usage).to eq("[--foo=BAR]") + expect(option(:foo, required: false, type: :string, banner: "BAR").usage).to eq("[--foo=BAR]") end it "checks when banner is an empty string" do - expect(option(:foo, :required => false, :type => :string, :banner => "").usage).to eq("[--foo]") + expect(option(:foo, required: false, type: :string, banner: "").usage).to eq("[--foo]") end describe "with required values" do diff --git a/spec/parser/options_spec.rb b/spec/parser/options_spec.rb index cba47c930..9b565332e 100644 --- a/spec/parser/options_spec.rb +++ b/spec/parser/options_spec.rb @@ -4,8 +4,8 @@ describe Thor::Options do def create(opts, defaults = {}, stop_on_unknown = false, exclusives = [], at_least_ones = []) relation = { - :exclusive_option_names => exclusives, - :at_least_one_option_names => at_least_ones + exclusive_option_names: exclusives, + at_least_one_option_names: at_least_ones } opts.each do |key, value| opts[key] = Thor::Option.parse(key, value) unless value.is_a?(Thor::Option) @@ -27,40 +27,40 @@ def remaining describe "#to_switches" do it "turns true values into a flag" do - expect(Thor::Options.to_switches(:color => true)).to eq("--color") + expect(Thor::Options.to_switches(color: true)).to eq("--color") end it "ignores nil" do - expect(Thor::Options.to_switches(:color => nil)).to eq("") + expect(Thor::Options.to_switches(color: nil)).to eq("") end it "ignores false" do - expect(Thor::Options.to_switches(:color => false)).to eq("") + expect(Thor::Options.to_switches(color: false)).to eq("") end it "avoids extra spaces" do - expect(Thor::Options.to_switches(:color => false, :foo => nil)).to eq("") + expect(Thor::Options.to_switches(color: false, foo: nil)).to eq("") end it "writes --name value for anything else" do - expect(Thor::Options.to_switches(:format => "specdoc")).to eq('--format "specdoc"') + expect(Thor::Options.to_switches(format: "specdoc")).to eq('--format "specdoc"') end it "joins several values" do - switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(" ").sort + switches = Thor::Options.to_switches(color: true, foo: "bar").split(" ").sort expect(switches).to eq(%w("bar" --color --foo)) end it "accepts arrays" do - expect(Thor::Options.to_switches(:count => [1, 2, 3])).to eq("--count 1 2 3") + expect(Thor::Options.to_switches(count: [1, 2, 3])).to eq("--count 1 2 3") end it "accepts hashes" do - expect(Thor::Options.to_switches(:count => {:a => :b})).to eq("--count a:b") + expect(Thor::Options.to_switches(count: {a: :b})).to eq("--count a:b") end it "accepts underscored options" do - expect(Thor::Options.to_switches(:under_score_option => "foo bar")).to eq('--under_score_option "foo bar"') + expect(Thor::Options.to_switches(under_score_option: "foo bar")).to eq('--under_score_option "foo bar"') end end @@ -99,22 +99,22 @@ def remaining end it "returns the default value if none is provided" do - create :foo => "baz", :bar => :required + create foo: "baz", bar: :required expect(parse("--bar", "boom")["foo"]).to eq("baz") end it "returns the default value from defaults hash to required arguments" do - create Hash[:bar => :required], Hash[:bar => "baz"] + create Hash[bar: :required], Hash[bar: "baz"] expect(parse["bar"]).to eq("baz") end it "gives higher priority to defaults given in the hash" do - create Hash[:bar => true], Hash[:bar => false] + create Hash[bar: true], Hash[bar: false] expect(parse["bar"]).to eq(false) end it "raises an error for unknown switches" do - create :foo => "baz", :bar => :required + create foo: "baz", bar: :required parse("--bar", "baz", "--baz", "unknown") expected = "Unknown switches \"--baz\"" @@ -126,55 +126,55 @@ def remaining end it "skips leading non-switches" do - create(:foo => "baz") + create(foo: "baz") expect(parse("asdf", "--foo", "bar")).to eq("foo" => "bar") end it "correctly recognizes things that look kind of like options, but aren't, as not options" do - create(:foo => "baz") + create(foo: "baz") expect(parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf")).to eq("foo" => "--asdf---dsf--asdf") check_unknown! end it "accepts underscores in commandline args hash for boolean" do - create :foo_bar => :boolean + create foo_bar: :boolean expect(parse("--foo_bar")["foo_bar"]).to eq(true) expect(parse("--no_foo_bar")["foo_bar"]).to eq(false) end it "accepts underscores in commandline args hash for strings" do - create :foo_bar => :string, :baz_foo => :string + create foo_bar: :string, baz_foo: :string expect(parse("--foo_bar", "baz")["foo_bar"]).to eq("baz") expect(parse("--baz_foo", "foo bar")["baz_foo"]).to eq("foo bar") end it "interprets everything after -- as args instead of options" do - create(:foo => :string, :bar => :required) + create(foo: :string, bar: :required) expect(parse(%w(--bar abc moo -- --foo def -a))).to eq("bar" => "abc") expect(remaining).to eq(%w(moo --foo def -a)) end it "ignores -- when looking for single option values" do - create(:foo => :string, :bar => :required) + create(foo: :string, bar: :required) expect(parse(%w(--bar -- --foo def -a))).to eq("bar" => "--foo") expect(remaining).to eq(%w(def -a)) end it "ignores -- when looking for array option values" do - create(:foo => :array) + create(foo: :array) expect(parse(%w(--foo a b -- c d -e))).to eq("foo" => %w(a b c d -e)) expect(remaining).to eq([]) end it "ignores -- when looking for hash option values" do - create(:foo => :hash) + create(foo: :hash) expect(parse(%w(--foo a:b -- c:d -e))).to eq("foo" => {"a" => "b", "c" => "d"}) expect(remaining).to eq(%w(-e)) end it "ignores trailing --" do - create(:foo => :string) + create(foo: :string) expect(parse(%w(--foo --))).to eq("foo" => nil) expect(remaining).to eq([]) end @@ -214,15 +214,15 @@ def remaining end it "does not raises an error if the required option has a default value" do - options = {:required => true, :type => :string, :default => "baz"} - create :foo => Thor::Option.new("foo", options), :bar => :boolean + options = {required: true, type: :string, default: "baz"} + create foo: Thor::Option.new("foo", options), bar: :boolean expect { parse("--bar") }.not_to raise_error end end context "when stop_on_unknown is true" do before do - create({:foo => :string, :verbose => :boolean}, {}, true) + create({foo: :string, verbose: :boolean}, {}, true) end it "stops parsing on first non-option" do @@ -258,7 +258,7 @@ def remaining context "when exclusives is given" do before do - create({:foo => :boolean, :bar => :boolean, :baz =>:boolean, :qux => :boolean}, {}, false, + create({foo: :boolean, bar: :boolean, baz: :boolean, qux: :boolean}, {}, false, [["foo", "bar"], ["baz","qux"]]) end @@ -273,7 +273,7 @@ def remaining context "when at_least_ones is given" do before do - create({:foo => :string, :bar => :boolean, :baz =>:boolean, :qux => :boolean}, {}, false, + create({foo: :string, bar: :boolean, baz: :boolean, qux: :boolean}, {}, false, [], [["foo", "bar"], ["baz","qux"]]) end @@ -288,7 +288,7 @@ def remaining context "when exclusives is given" do before do - create({:foo => :boolean, :bar => :boolean, :baz =>:boolean, :qux => :boolean}, {}, false, + create({foo: :boolean, bar: :boolean, baz: :boolean, qux: :boolean}, {}, false, [["foo", "bar"], ["baz","qux"]]) end @@ -303,7 +303,7 @@ def remaining context "when at_least_ones is given" do before do - create({:foo => :string, :bar => :boolean, :baz =>:boolean, :qux => :boolean}, {}, false, + create({foo: :string, bar: :boolean, baz: :boolean, qux: :boolean}, {}, false, [], [["foo", "bar"], ["baz","qux"]]) end @@ -334,7 +334,7 @@ def remaining end it "must accept underscores switch=value assignment" do - create :foo_bar => :required + create foo_bar: :required expect(parse("--foo_bar=http://example.com/under_score/")["foo_bar"]).to eq("http://example.com/under_score/") end @@ -365,13 +365,13 @@ def remaining it "raises error when value isn't in enum" do enum = %w(apple banana) - create :fruit => Thor::Option.new("fruit", :type => :string, :enum => enum) + create fruit: Thor::Option.new("fruit", type: :string, enum: enum) expect { parse("--fruit", "orange") }.to raise_error(Thor::MalformattedArgumentError, "Expected '--fruit' to be one of #{enum.join(', ')}; got orange") end it "does not erroneously mutate defaults" do - create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true, :required => false, :default => []) + create foo: Thor::Option.new("foo", type: :string, repeatable: true, required: false, default: []) expect(parse("--foo=bar", "--foo", "12")["foo"]).to eq(["bar", "12"]) expect(@opt.instance_variable_get(:@switches)["--foo"].default).to eq([]) end @@ -432,7 +432,7 @@ def remaining end it "accepts inputs in the human name format" do - create :foo_bar => :boolean + create foo_bar: :boolean expect(parse("--foo-bar")["foo_bar"]).to eq(true) expect(parse("--no-foo-bar")["foo_bar"]).to eq(false) expect(parse("--skip-foo-bar")["foo_bar"]).to eq(false) @@ -454,7 +454,7 @@ def remaining end it "allows multiple values if repeatable is specified" do - create :verbose => Thor::Option.new("verbose", :type => :boolean, :aliases => '-v', :repeatable => true) + create verbose: Thor::Option.new("verbose", type: :boolean, aliases: "-v", repeatable: true) expect(parse("-v", "-v", "-v")["verbose"].count).to eq(3) end end @@ -482,7 +482,7 @@ def remaining end it "allows multiple values if repeatable is specified" do - create :attributes => Thor::Option.new("attributes", :type => :hash, :repeatable => true) + create attributes: Thor::Option.new("attributes", type: :hash, repeatable: true) expect(parse("--attributes", "name:one", "foo:1", "--attributes", "name:two", "bar:2")["attributes"]).to eq({"name"=>"two", "foo"=>"1", "bar" => "2"}) end end @@ -506,7 +506,7 @@ def remaining end it "allows multiple values if repeatable is specified" do - create :attributes => Thor::Option.new("attributes", :type => :array, :repeatable => true) + create attributes: Thor::Option.new("attributes", type: :array, repeatable: true) expect(parse("--attributes", "1", "2", "--attributes", "3", "4")["attributes"]).to eq([["1", "2"], ["3", "4"]]) end end @@ -531,13 +531,13 @@ def remaining it "raises error when value isn't in enum" do enum = [1, 2] - create :limit => Thor::Option.new("limit", :type => :numeric, :enum => enum) + create limit: Thor::Option.new("limit", type: :numeric, enum: enum) expect { parse("--limit", "3") }.to raise_error(Thor::MalformattedArgumentError, "Expected '--limit' to be one of #{enum.join(', ')}; got 3") end it "allows multiple values if repeatable is specified" do - create :run => Thor::Option.new("run", :type => :numeric, :repeatable => true) + create run: Thor::Option.new("run", type: :numeric, repeatable: true) expect(parse("--run", "1", "--run", "2")["run"]).to eq([1, 2]) end end diff --git a/spec/register_spec.rb b/spec/register_spec.rb index d168473eb..d7524882d 100644 --- a/spec/register_spec.rb +++ b/spec/register_spec.rb @@ -42,9 +42,9 @@ def part_two class ClassOptionGroupPlugin < Thor::Group class_option :who, - :type => :string, - :aliases => "-w", - :default => "zebra" + type: :string, + aliases: "-w", + default: "zebra" end class PluginInheritingFromClassOptionsGroup < ClassOptionGroupPlugin @@ -108,7 +108,7 @@ def with_args(*args) "secret", "secret stuff", "Nothing to see here. Move along.", - :hide => true + hide: true ) BoringVendorProvidedCLI.register( diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 0edbe2f15..ea31fd2ff 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -122,9 +122,9 @@ def when_no_thorfiles_exist before do @original_yaml = { "random" => { - :location => location, - :filename => "4a33b894ffce85d7b412fc1b36f88fe0", - :namespaces => %w(amazing) + location: location, + filename: "4a33b894ffce85d7b412fc1b36f88fe0", + namespaces: %w(amazing) } } @@ -249,7 +249,7 @@ def when_no_thorfiles_exist it "installs thor files" do allow(Thor::LineEditor).to receive(:readline).and_return("Y", "random") - stub_request(:get, location).to_return(:body => "class Foo < Thor; end") + stub_request(:get, location).to_return(body: "class Foo < Thor; end") path = File.join(Thor::Util.thor_root, Digest::SHA256.hexdigest(location + "random")) expect(File).to receive(:open).with(path, "w") expect { silence(:stdout) { Thor::Runner.start(%W(install #{location})) } }.not_to raise_error diff --git a/spec/script_exit_status_spec.rb b/spec/script_exit_status_spec.rb index 49ed5439c..6021b2b45 100644 --- a/spec/script_exit_status_spec.rb +++ b/spec/script_exit_status_spec.rb @@ -3,13 +3,13 @@ def thor_command(command) gem_dir= File.expand_path("#{File.dirname(__FILE__)}/..") lib_path= "#{gem_dir}/lib" script_path= "#{gem_dir}/spec/fixtures/exit_status.thor" - ruby_lib= ENV['RUBYLIB'].nil? ? lib_path : "#{lib_path}:#{ENV['RUBYLIB']}" + ruby_lib= ENV["RUBYLIB"].nil? ? lib_path : "#{lib_path}:#{ENV['RUBYLIB']}" full_command= "ruby #{script_path} #{command}" r,w= IO.pipe - pid= spawn({'RUBYLIB' => ruby_lib}, + pid= spawn({"RUBYLIB" => ruby_lib}, full_command, - {:out => w, :err => [:child, :out]}) + {out: w, err: [:child, :out]}) w.close _, exit_status= Process.wait2(pid) diff --git a/spec/shell/basic_spec.rb b/spec/shell/basic_spec.rb index 74b89697e..99ad9e1f8 100644 --- a/spec/shell/basic_spec.rb +++ b/spec/shell/basic_spec.rb @@ -65,85 +65,85 @@ def shell it "prints a message to the user and does not echo stdin if the echo option is set to false" do expect($stdout).to receive(:print).with("What's your password? ") expect($stdin).to receive(:noecho).and_return("mysecretpass") - expect(shell.ask("What's your password?", :echo => false)).to eq("mysecretpass") + expect(shell.ask("What's your password?", echo: false)).to eq("mysecretpass") end it "prints a message to the user with the available options, expects case-sensitive matching, and determines the correctness of the answer" do flavors = %w(strawberry chocolate vanilla) - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {:limited_to => flavors}).and_return("chocolate") - expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => flavors)).to eq("chocolate") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {limited_to: flavors}).and_return("chocolate") + expect(shell.ask("What's your favorite Neopolitan flavor?", limited_to: flavors)).to eq("chocolate") end it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after an incorrect response" do flavors = %w(strawberry chocolate vanilla) expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n") - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {:limited_to => flavors}).and_return("moose tracks", "chocolate") - expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => flavors)).to eq("chocolate") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {limited_to: flavors}).and_return("moose tracks", "chocolate") + expect(shell.ask("What's your favorite Neopolitan flavor?", limited_to: flavors)).to eq("chocolate") end it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after a case-insensitive match" do flavors = %w(strawberry chocolate vanilla) expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n") - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {:limited_to => flavors}).and_return("cHoCoLaTe", "chocolate") - expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => flavors)).to eq("chocolate") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {limited_to: flavors}).and_return("cHoCoLaTe", "chocolate") + expect(shell.ask("What's your favorite Neopolitan flavor?", limited_to: flavors)).to eq("chocolate") end it "prints a message to the user with the available options, expects case-insensitive matching, and determines the correctness of the answer" do flavors = %w(strawberry chocolate vanilla) - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {:limited_to => flavors, :case_insensitive => true}).and_return("CHOCOLATE") - expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => flavors, :case_insensitive => true)).to eq("chocolate") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {limited_to: flavors, case_insensitive: true}).and_return("CHOCOLATE") + expect(shell.ask("What's your favorite Neopolitan flavor?", limited_to: flavors, case_insensitive: true)).to eq("chocolate") end it "prints a message to the user with the available options, expects case-insensitive matching, and reasks the question after an incorrect response" do flavors = %w(strawberry chocolate vanilla) expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n") - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {:limited_to => flavors, :case_insensitive => true}).and_return("moose tracks", "chocolate") - expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => flavors, :case_insensitive => true)).to eq("chocolate") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ", {limited_to: flavors, case_insensitive: true}).and_return("moose tracks", "chocolate") + expect(shell.ask("What's your favorite Neopolitan flavor?", limited_to: flavors, case_insensitive: true)).to eq("chocolate") end it "prints a message to the user containing a default and sets the default if only enter is pressed" do - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? (vanilla) ", {:default => "vanilla"}).and_return("") - expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla")).to eq("vanilla") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? (vanilla) ", {default: "vanilla"}).and_return("") + expect(shell.ask("What's your favorite Neopolitan flavor?", default: "vanilla")).to eq("vanilla") end it "prints a message to the user with the available options and reasks the question after an incorrect response and then returns the default" do flavors = %w(strawberry chocolate vanilla) expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n") - expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ", {:default => "vanilla", :limited_to => flavors}).and_return("moose tracks", "") - expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => flavors)).to eq("vanilla") + expect(Thor::LineEditor).to receive(:readline).with("What's your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ", {default: "vanilla", limited_to: flavors}).and_return("moose tracks", "") + expect(shell.ask("What's your favorite Neopolitan flavor?", default: "vanilla", limited_to: flavors)).to eq("vanilla") end end describe "#yes?" do it "asks the user and returns true if the user replies yes" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("y") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("y") expect(shell.yes?("Should I overwrite it?")).to be true end it "asks the user and returns false if the user replies no" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("n") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("n") expect(shell.yes?("Should I overwrite it?")).not_to be true end it "asks the user and returns false if the user replies with an answer other than yes or no" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("foobar") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("foobar") expect(shell.yes?("Should I overwrite it?")).to be false end end describe "#no?" do it "asks the user and returns true if the user replies no" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("n") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("n") expect(shell.no?("Should I overwrite it?")).to be true end it "asks the user and returns false if the user replies yes" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("Yes") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("Yes") expect(shell.no?("Should I overwrite it?")).to be false end it "asks the user and returns false if the user replies with an answer other than yes or no" do - expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("foobar") + expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {add_to_history: false}).and_return("foobar") expect(shell.no?("Should I overwrite it?")).to be false end end @@ -183,7 +183,7 @@ def shell it "does not print a message if base is set to quiet" do shell.base = MyCounter.new [1, 2] - expect(shell.base).to receive(:options).and_return(:quiet => true) + expect(shell.base).to receive(:options).and_return(quiet: true) expect($stdout).not_to receive(:print) shell.say("Running...") @@ -225,7 +225,7 @@ def shell it "does not print a message if base is set to quiet" do shell.base = MyCounter.new [1, 2] - expect(shell.base).to receive(:options).and_return(:quiet => true) + expect(shell.base).to receive(:options).and_return(quiet: true) expect($stderr).not_to receive(:print) shell.say_error("Running...") @@ -258,7 +258,7 @@ def shell end context "with indentation" do - subject(:wrap_text) { described_class.new.print_wrapped(message, :indent => 4) } + subject(:wrap_text) { described_class.new.print_wrapped(message, indent: 4) } let(:expected_output) do " Creates a back-up of the given folder by compressing it in a .tar.gz file\n"\ @@ -308,7 +308,7 @@ def shell it "does not print a message if base is set to quiet" do base = MyCounter.new [1, 2] - expect(base).to receive(:options).and_return(:quiet => true) + expect(base).to receive(:options).and_return(quiet: true) expect($stdout).not_to receive(:print) shell.base = base @@ -357,7 +357,7 @@ def shell end it "prints a table with indentation" do - content = capture(:stdout) { shell.print_table(@table, :indent => 2) } + content = capture(:stdout) { shell.print_table(@table, indent: 2) } expect(content).to eq(<<-TABLE) abc #123 first three #0 empty @@ -369,7 +369,7 @@ def shell @table << ["def", "#456", "Lançam foo bar"] @table << ["ghi", "#789", "بالله عليكم"] expect(shell).to receive(:terminal_width).and_return(20) - content = capture(:stdout) { shell.print_table(@table, :indent => 2, :truncate => true) } + content = capture(:stdout) { shell.print_table(@table, indent: 2, truncate: true) } expect(content).to eq(<<-TABLE) abc #123 firs... #0 empty @@ -380,7 +380,7 @@ def #456 Lanç... end it "honors the colwidth option" do - content = capture(:stdout) { shell.print_table(@table, :colwidth => 10) } + content = capture(:stdout) { shell.print_table(@table, colwidth: 10) } expect(content).to eq(<<-TABLE) abc #123 first three #0 empty @@ -437,7 +437,7 @@ def #456 Lanç... describe "#file_collision" do it "shows a menu with options" do - expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {:add_to_history => false}).and_return("n") + expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {add_to_history: false}).and_return("n") shell.file_collision("foo") end @@ -478,7 +478,7 @@ def #456 Lanç... end it "always returns true if the user chooses always" do - expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {:add_to_history => false}).and_return("a") + expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {add_to_history: false}).and_return("a") expect(shell.file_collision("foo")).to be true @@ -488,7 +488,7 @@ def #456 Lanç... describe "when a block is given" do it "displays diff and merge options to the user" do - expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqdhm] ', {:add_to_history => false}).and_return("s") + expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqdhm] ', {add_to_history: false}).and_return("s") shell.file_collision("foo") {} end diff --git a/spec/shell/color_spec.rb b/spec/shell/color_spec.rb index 2c63bee7f..3b40c0b35 100644 --- a/spec/shell/color_spec.rb +++ b/spec/shell/color_spec.rb @@ -18,7 +18,7 @@ def shell shell.ask "Is this green?", :green expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? [Yes, No, Maybe] \e[0m", anything).and_return("Yes") - shell.ask "Is this green?", :green, :limited_to => %w(Yes No Maybe) + shell.ask "Is this green?", :green, limited_to: %w(Yes No Maybe) end it "does not set the color if specified and NO_COLOR is set to a non-empty value" do @@ -27,7 +27,7 @@ def shell shell.ask "Is this green?", :green expect(Thor::LineEditor).to receive(:readline).with("Is this green? [Yes, No, Maybe] ", anything).and_return("Yes") - shell.ask "Is this green?", :green, :limited_to => %w(Yes No Maybe) + shell.ask "Is this green?", :green, limited_to: %w(Yes No Maybe) end it "sets the color when NO_COLOR is ignored because the environment variable is nil" do @@ -36,7 +36,7 @@ def shell shell.ask "Is this green?", :green expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? [Yes, No, Maybe] \e[0m", anything).and_return("Yes") - shell.ask "Is this green?", :green, :limited_to => %w(Yes No Maybe) + shell.ask "Is this green?", :green, limited_to: %w(Yes No Maybe) end it "sets the color when NO_COLOR is ignored because the environment variable is an empty-string" do @@ -45,7 +45,7 @@ def shell shell.ask "Is this green?", :green expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? [Yes, No, Maybe] \e[0m", anything).and_return("Yes") - shell.ask "Is this green?", :green, :limited_to => %w(Yes No Maybe) + shell.ask "Is this green?", :green, limited_to: %w(Yes No Maybe) end it "handles an Array of colors" do diff --git a/spec/shell_spec.rb b/spec/shell_spec.rb index 50adcf3f7..87c038d53 100644 --- a/spec/shell_spec.rb +++ b/spec/shell_spec.rb @@ -7,12 +7,12 @@ def shell describe "#initialize" do it "sets shell value" do - base = MyCounter.new [1, 2], {}, :shell => shell + base = MyCounter.new [1, 2], {}, shell: shell expect(base.shell).to eq(shell) end it "sets the base value on the shell if an accessor is available" do - base = MyCounter.new [1, 2], {}, :shell => shell + base = MyCounter.new [1, 2], {}, shell: shell expect(shell.base).to eq(base) end end diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb index dce8f5e13..4f9108df2 100644 --- a/spec/thor_spec.rb +++ b/spec/thor_spec.rb @@ -91,8 +91,8 @@ describe "#stop_on_unknown_option!" do my_script = Class.new(Thor) do - class_option "verbose", :type => :boolean - class_option "mode", :type => :string + class_option "verbose", type: :boolean + class_option "mode", type: :string stop_on_unknown_option! :exec @@ -140,9 +140,9 @@ def boring(*args) stop_on_unknown_option! :foo, :bar end it "affects all specified commands" do - expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be true - expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be true - expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be false + expect(klass.stop_on_unknown_option?(double(name: "foo"))).to be true + expect(klass.stop_on_unknown_option?(double(name: "bar"))).to be true + expect(klass.stop_on_unknown_option?(double(name: "baz"))).to be false end end @@ -152,9 +152,9 @@ def boring(*args) stop_on_unknown_option! :bar end it "affects all specified commands" do - expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be true - expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be true - expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be false + expect(klass.stop_on_unknown_option?(double(name: "foo"))).to be true + expect(klass.stop_on_unknown_option?(double(name: "bar"))).to be true + expect(klass.stop_on_unknown_option?(double(name: "baz"))).to be false end end @@ -164,8 +164,8 @@ def boring(*args) context "along with check_unknown_options!" do my_script2 = Class.new(Thor) do - class_option "verbose", :type => :boolean - class_option "mode", :type => :string + class_option "verbose", type: :boolean + class_option "mode", type: :string check_unknown_options! stop_on_unknown_option! :exec @@ -219,8 +219,8 @@ def self.exit_on_failure? describe "#check_unknown_options!" do my_script = Class.new(Thor) do - class_option "verbose", :type => :boolean - class_option "mode", :type => :string + class_option "verbose", type: :boolean + class_option "mode", type: :string check_unknown_options! desc "checked", "a command with checked" @@ -280,7 +280,7 @@ def self.exit_on_failure? describe "#disable_required_check!" do my_script = Class.new(Thor) do - class_option "foo", :required => true + class_option "foo", required: true disable_required_check! :boring @@ -309,7 +309,7 @@ def self.exit_on_failure? end it "does affects help by default" do - expect(my_script.disable_required_check?(double(:name => "help"))).to be true + expect(my_script.disable_required_check?(double(name: "help"))).to be true end context "when provided with multiple command names" do @@ -318,10 +318,10 @@ def self.exit_on_failure? end it "affects all specified commands" do - expect(klass.disable_required_check?(double(:name => "help"))).to be true - expect(klass.disable_required_check?(double(:name => "foo"))).to be true - expect(klass.disable_required_check?(double(:name => "bar"))).to be true - expect(klass.disable_required_check?(double(:name => "baz"))).to be false + expect(klass.disable_required_check?(double(name: "help"))).to be true + expect(klass.disable_required_check?(double(name: "foo"))).to be true + expect(klass.disable_required_check?(double(name: "bar"))).to be true + expect(klass.disable_required_check?(double(name: "baz"))).to be false end end @@ -332,10 +332,10 @@ def self.exit_on_failure? end it "affects all specified commands" do - expect(klass.disable_required_check?(double(:name => "help"))).to be true - expect(klass.disable_required_check?(double(:name => "foo"))).to be true - expect(klass.disable_required_check?(double(:name => "bar"))).to be true - expect(klass.disable_required_check?(double(:name => "baz"))).to be false + expect(klass.disable_required_check?(double(name: "help"))).to be true + expect(klass.disable_required_check?(double(name: "foo"))).to be true + expect(klass.disable_required_check?(double(name: "bar"))).to be true + expect(klass.disable_required_check?(double(name: "baz"))).to be false end end end @@ -516,13 +516,13 @@ def self.exit_on_failure? it "raises an exception and displays a message that explains the ambiguity" do shell = Thor::Base.shell.new expect(shell).to receive(:error).with("Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]") - MyScript.start(%w(call), :shell => shell) + MyScript.start(%w(call), shell: shell) end it "raises an exception when there is an alias" do shell = Thor::Base.shell.new expect(shell).to receive(:error).with("Ambiguous command f matches [foo, fu]") - MyScript.start(%w(f), :shell => shell) + MyScript.start(%w(f), shell: shell) end end end @@ -677,7 +677,7 @@ def shell context "with required class_options" do let(:klass) do Class.new(Thor) do - class_option :foo, :required => true + class_option :foo, required: true desc "bar", "do something" def bar; end @@ -722,7 +722,7 @@ def bar; end describe "edge-cases" do it "can handle boolean options followed by arguments" do klass = Class.new(Thor) do - method_option :loud, :type => :boolean + method_option :loud, type: :boolean desc "hi NAME", "say hi to name" def hi(name) name = name.upcase if options[:loud] @@ -780,7 +780,7 @@ def unknown(*args) it "issues a deprecation warning on incompatible types by default" do expect do Class.new(Thor) do - option "bar", :type => :numeric, :default => "foo" + option "bar", type: :numeric, default: "foo" end end.to output(/^Deprecation warning/).to_stderr end @@ -790,7 +790,7 @@ def unknown(*args) Class.new(Thor) do allow_incompatible_default_type! - option "bar", :type => :numeric, :default => "foo" + option "bar", type: :numeric, default: "foo" end end.not_to output.to_stderr end @@ -798,7 +798,7 @@ def unknown(*args) it "allows incompatible types if `check_default_type: false` is given" do expect do Class.new(Thor) do - option "bar", :type => :numeric, :default => "foo", :check_default_type => false + option "bar", type: :numeric, default: "foo", check_default_type: false end end.not_to output.to_stderr end @@ -808,7 +808,7 @@ def unknown(*args) Class.new(Thor) do check_default_type! - option "bar", :type => :numeric, :default => "foo" + option "bar", type: :numeric, default: "foo" end end.to raise_error(ArgumentError, "Expected numeric default value for '--bar'; got \"foo\" (string)") end diff --git a/thor.gemspec b/thor.gemspec index 493ac7e60..6f26e4e35 100644 --- a/thor.gemspec +++ b/thor.gemspec @@ -4,15 +4,15 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) require "thor/version" Gem::Specification.new do |spec| - spec.add_development_dependency "bundler", ">= 1.0", "< 3" + spec.name = "thor" + spec.version = Thor::VERSION + spec.licenses = %w(MIT) spec.authors = ["Yehuda Katz", "José Valim"] - spec.description = "Thor is a toolkit for building powerful command-line interfaces." spec.email = "ruby-thor@googlegroups.com" - spec.executables = %w(thor) - spec.files = %w(.document thor.gemspec) + Dir["*.md", "bin/*", "lib/**/*.rb"] spec.homepage = "http://whatisthor.com/" - spec.licenses = %w(MIT) - spec.name = "thor" + spec.description = "Thor is a toolkit for building powerful command-line interfaces." + spec.summary = spec.description + spec.metadata = { "bug_tracker_uri" => "https://github.com/rails/thor/issues", "changelog_uri" => "https://github.com/rails/thor/releases/tag/v#{Thor::VERSION}", @@ -21,9 +21,13 @@ Gem::Specification.new do |spec| "wiki_uri" => "https://github.com/rails/thor/wiki", "rubygems_mfa_required" => "true", } - spec.require_paths = %w(lib) - spec.required_ruby_version = ">= 2.0.0" + + spec.required_ruby_version = ">= 2.6.0" spec.required_rubygems_version = ">= 1.3.5" - spec.summary = spec.description - spec.version = Thor::VERSION + + spec.files = %w(.document thor.gemspec) + Dir["*.md", "bin/*", "lib/**/*.rb"] + spec.executables = %w(thor) + spec.require_paths = %w(lib) + + spec.add_development_dependency "bundler", ">= 1.0", "< 3" end