From a7d8c447465eaba806307759b008a59340783835 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 26 Feb 2021 13:24:16 +0100 Subject: [PATCH 1/5] Support Ruby 2.3 --- .rubocop.yml | 3 +-- Dockerfile | 4 ++-- Gemfile | 8 +++++++ Rakefile | 23 +++++++++++-------- aruba.gemspec | 13 ++++------- features/support/env.rb | 6 ++++- features/support/simplecov_setup.rb | 14 +++++++---- lib/aruba/config/jruby.rb | 2 +- lib/aruba/matchers/base/message_indenter.rb | 2 +- lib/aruba/platforms/determine_disk_usage.rb | 4 +++- .../platforms/unix_environment_variables.rb | 2 +- lib/aruba/platforms/unix_platform.rb | 2 +- lib/aruba/platforms/windows_command_string.rb | 2 +- spec/spec_helper.rb | 10 +++++--- 14 files changed, 59 insertions(+), 36 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e51b55c11..2175ced2b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,4 @@ require: - - rubocop-packaging - rubocop-performance - rubocop-rspec @@ -9,7 +8,7 @@ AllCops: - vendor/**/* DisplayCopNames: true NewCops: enable - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.3 # Spec blocks can be any size Metrics/BlockLength: diff --git a/Dockerfile b/Dockerfile index 7e1434487..85f20289a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # ------------ # # This Dockerfile will always target the lowest version of Ruby supported by -# Aruba. This is currently version 2.4.0. +# Aruba. This is currently version 2.3.0. # # Build the Docker image using: # @@ -16,7 +16,7 @@ # The `-v $PWD:/aruba` will make the container pick up any changes to the # code, so you can edit and re-run the tests. -FROM ruby:2.4 +FROM ruby:2.3 # Create aruba user RUN useradd -m -s /bin/bash aruba diff --git a/Gemfile b/Gemfile index b7a27b7aa..b961c3d50 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,14 @@ source "https://rubygems.org" # Use dependencies from gemspec gemspec +group :development do + if RUBY_VERSION >= "2.4.0" + gem "license_finder", "~> 6.0" + gem "rake-manifest", "~> 0.2.0" + gem "simplecov", [">= 0.18.0", "< 0.22.0"] + end +end + # Load local Gemfile if File.file? File.expand_path("Gemfile.local", __dir__) load File.expand_path("Gemfile.local", __dir__) diff --git a/Rakefile b/Rakefile index 9bcee4ac3..43acb0326 100644 --- a/Rakefile +++ b/Rakefile @@ -42,18 +42,23 @@ end desc "Run all linters." task lint: %w(lint:coding_guidelines lint:licenses) -# Also check the manifest as part of the linting -task lint: "manifest:check" - Bundler::GemHelper.install_tasks -require "rake/manifest/task" +begin + require "rake/manifest/task" -Rake::Manifest::Task.new do |t| - t.patterns = ["lib/**/*", "exe/*", "CHANGELOG.md", "CONTRIBUTING.md", - "LICENSE", "README.md"] -end + Rake::Manifest::Task.new do |t| + t.patterns = ["lib/**/*", "exe/*", "CHANGELOG.md", "CONTRIBUTING.md", + "LICENSE", "README.md"] + end -task build: "manifest:check" + # Check the manifest before building the gem + task build: "manifest:check" + + # Also check the manifest as part of the linting + task lint: "manifest:check" +rescue LoadError + # skip +end task default: :test diff --git a/aruba.gemspec b/aruba.gemspec index cfba80d82..4625bb132 100644 --- a/aruba.gemspec +++ b/aruba.gemspec @@ -28,21 +28,18 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "thor", "~> 1.0" spec.add_development_dependency "json", "~> 2.1" - spec.add_development_dependency "license_finder", "~> 6.0" + spec.add_development_dependency "license_finder", [">= 5.3", "< 7.0"] spec.add_development_dependency "minitest", "~> 5.10" spec.add_development_dependency "pry-doc", "~> 1.0" spec.add_development_dependency "rake", "~> 13.0" - spec.add_development_dependency "rake-manifest", "~> 0.2.0" spec.add_development_dependency "rspec", "~> 3.10.0" - spec.add_development_dependency "rubocop", "~> 1.10.0" - spec.add_development_dependency "rubocop-packaging", "~> 0.5.0" - spec.add_development_dependency "rubocop-performance", "~> 1.9.0" - spec.add_development_dependency "rubocop-rspec", "~> 2.2.0" - spec.add_development_dependency "simplecov", [">= 0.18.0", "< 0.22.0"] + spec.add_development_dependency "rubocop", "~> 0.81.0" + spec.add_development_dependency "rubocop-performance", "~> 1.5.2" + spec.add_development_dependency "rubocop-rspec", "~> 1.38.0" spec.add_development_dependency "yard-junk", "~> 0.0.7" spec.rubygems_version = ">= 1.6.1" - spec.required_ruby_version = ">= 2.4" + spec.required_ruby_version = ">= 2.3" spec.files = File.readlines("Manifest.txt", chomp: true) diff --git a/features/support/env.rb b/features/support/env.rb index b6294882c..d93c05a4c 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,7 +1,11 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__) # Has to be the first file required so that all other files show coverage information -require "simplecov" unless RUBY_PLATFORM.include?("java") +begin + require "simplecov" unless RUBY_PLATFORM.include?("java") +rescue LoadError + # skip +end # Standard Library require "fileutils" diff --git a/features/support/simplecov_setup.rb b/features/support/simplecov_setup.rb index a0fe444ad..b2412fbba 100644 --- a/features/support/simplecov_setup.rb +++ b/features/support/simplecov_setup.rb @@ -1,9 +1,13 @@ # @note this file is loaded in env.rb to setup simplecov using RUBYOPTs for # child processes and @in-process unless RUBY_PLATFORM.include?("java") - require "simplecov" - root = File.expand_path("../..", __dir__) - SimpleCov.command_name(ENV["SIMPLECOV_COMMAND_NAME"]) - SimpleCov.root(root) - load File.join(root, ".simplecov") + begin + require "simplecov" + root = File.expand_path("../..", __dir__) + SimpleCov.command_name(ENV["SIMPLECOV_COMMAND_NAME"]) + SimpleCov.root(root) + load File.join(root, ".simplecov") + rescue LoadError + # skip + end end diff --git a/lib/aruba/config/jruby.rb b/lib/aruba/config/jruby.rb index dbe4d41b6..99244729d 100644 --- a/lib/aruba/config/jruby.rb +++ b/lib/aruba/config/jruby.rb @@ -17,7 +17,7 @@ env["JRUBY_OPTS"] = jruby_opts - if /solaris|sunos/i.match?(RbConfig::CONFIG["host_os"]) + if /solaris|sunos/i.match(RbConfig::CONFIG["host_os"]) java_opts = env["JAVA_OPTS"] || "" # force jRuby to use client JVM for faster startup times diff --git a/lib/aruba/matchers/base/message_indenter.rb b/lib/aruba/matchers/base/message_indenter.rb index 623df5f09..afc806a4f 100644 --- a/lib/aruba/matchers/base/message_indenter.rb +++ b/lib/aruba/matchers/base/message_indenter.rb @@ -10,7 +10,7 @@ module MessageIndenter def indent_multiline_message(message) message = message.sub(/\n+\z/, "") message.lines.map do |line| - /\S/.match?(line) ? " #{line}" : line + /\S/.match(line) ? " #{line}" : line end.join end end diff --git a/lib/aruba/platforms/determine_disk_usage.rb b/lib/aruba/platforms/determine_disk_usage.rb index c5ff99251..58e46a3c9 100644 --- a/lib/aruba/platforms/determine_disk_usage.rb +++ b/lib/aruba/platforms/determine_disk_usage.rb @@ -7,7 +7,9 @@ module Platforms # @private class DetermineDiskUsage def call(paths) - size = paths.flatten.sum { |path| minimum_disk_space_used path } + size = paths.flatten.map do |path| + minimum_disk_space_used path + end.inject(0, &:+) FileSize.new(size) end diff --git a/lib/aruba/platforms/unix_environment_variables.rb b/lib/aruba/platforms/unix_environment_variables.rb index 095a67391..e0b133c0e 100644 --- a/lib/aruba/platforms/unix_environment_variables.rb +++ b/lib/aruba/platforms/unix_environment_variables.rb @@ -9,7 +9,7 @@ class UpdateAction attr_reader :other_env, :block def initialize(other_env, &block) - @other_env = other_env.to_h.transform_values(&:to_s) + @other_env = other_env.to_h.each_with_object({}) { |(k, v), a| a[k] = v.to_s } @block = block end diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index 0f9c7bb58..ad0232047 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -83,7 +83,7 @@ def default_shell end def detect_ruby(cmd) - if /^ruby\s/.match?(cmd) + if /^ruby\s/.match(cmd) cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd diff --git a/lib/aruba/platforms/windows_command_string.rb b/lib/aruba/platforms/windows_command_string.rb index 0c16f2cec..ad1250355 100644 --- a/lib/aruba/platforms/windows_command_string.rb +++ b/lib/aruba/platforms/windows_command_string.rb @@ -22,7 +22,7 @@ def to_a def escaped_arguments @arguments.map { |arg| arg.gsub(/"/, '"""') } - .map { |arg| / /.match?(arg) ? "\"#{arg}\"" : arg } + .map { |arg| / /.match(arg) ? "\"#{arg}\"" : arg } end def escaped_command diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0dc8cb069..ca4da7ae1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,13 @@ $LOAD_PATH << ::File.expand_path("../lib", __dir__) unless RUBY_PLATFORM.include?("java") - require "simplecov" - SimpleCov.command_name "rspec" - SimpleCov.start + begin + require "simplecov" + SimpleCov.command_name "rspec" + SimpleCov.start + rescue LoadError + # skip + end end # Pull in all of the gems including those in the `test` group From 3a8bbd831251c685e3196a308fba285027489153 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 26 Feb 2021 13:25:13 +0100 Subject: [PATCH 2/5] Update RuboCop configuration --- .rubocop.yml | 15 ++++++++++- .rubocop_todo.yml | 69 +++++++++++++---------------------------------- 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2175ced2b..01d92ad6d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,6 @@ AllCops: - tmp/**/* - vendor/**/* DisplayCopNames: true - NewCops: enable TargetRubyVersion: 2.3 # Spec blocks can be any size @@ -38,4 +37,18 @@ Style/FrozenStringLiteralComment: Layout/LineLength: Max: 94 + +# New cops to enable. Needed for RuboCop 0.81.0 since it does not support AllCops/NewCops option + +Lint/RaiseException: + Enabled: true +Lint/StructNewOverride: + Enabled: true +Style/HashEachMethods: + Enabled: true +Style/HashTransformKeys: + Enabled: true +Style/HashTransformValues: + Enabled: true + inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0da5f8ab5..efe3bbcd3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,66 +1,49 @@ # This configuration was generated by # `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp` -# using RuboCop version 1.9.0. +# using RuboCop version 0.81.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. -# Configuration parameters: Include. -# Include: **/*.gemspec -Gemspec/RequiredRubyVersion: - Exclude: - - 'fixtures/cli-app/cli-app.gemspec' - - 'fixtures/empty-app/cli-app.gemspec' - Lint/AmbiguousBlockAssociation: Exclude: - 'lib/aruba/platforms/announcer.rb' -# Configuration parameters: AllowComments. -Lint/EmptyClass: - Exclude: - - 'spec/event_bus_spec.rb' - -Lint/MissingSuper: - Exclude: - - 'lib/aruba/contracts/enum.rb' - - 'lib/aruba/matchers/collection/include_an_object.rb' - # Configuration parameters: CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: - 'lib/aruba/platforms/announcer.rb' - 'lib/aruba/platforms/unix_environment_variables.rb' -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +# Configuration parameters: IgnoredMethods. Metrics/AbcSize: - Max: 118 + Max: 116 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -# IgnoredMethods: refine +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: Max: 68 -# Configuration parameters: CountComments, CountAsOne. +# Configuration parameters: CountComments. Metrics/ClassLength: Max: 158 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: - Max: 13 + Max: 12 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 59 -# Configuration parameters: CountComments, CountAsOne. +# Configuration parameters: CountComments. Metrics/ModuleLength: Max: 198 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 14 + Max: 13 Naming/ConstantName: Exclude: @@ -79,7 +62,7 @@ Naming/MemoizedInstanceVariableName: - 'lib/aruba/api/core.rb' # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp Naming/MethodParameterName: Exclude: - 'lib/aruba/aruba_path.rb' @@ -88,7 +71,6 @@ Naming/MethodParameterName: - 'lib/aruba/platforms/aruba_logger.rb' - 'lib/aruba/platforms/unix_platform.rb' -# Cop supports --auto-correct. Performance/Caller: Exclude: - 'lib/aruba/platforms/unix_platform.rb' @@ -106,7 +88,6 @@ RSpec/ContextWording: - 'spec/aruba/platform/windows_environment_variables_spec.rb' - 'spec/support/shared_contexts/aruba.rb' -# Configuration parameters: IgnoredMetadata. RSpec/DescribeClass: Exclude: - 'spec/aruba/api/runtime_spec.rb' @@ -118,6 +99,7 @@ RSpec/DescribeClass: - 'spec/aruba/matchers/file_spec.rb' - 'spec/aruba/matchers/path_spec.rb' - 'spec/aruba/platform/simple_table_spec.rb' + - 'spec/aruba/rspec_spec.rb' # Configuration parameters: Max. RSpec/ExampleLength: @@ -127,8 +109,7 @@ RSpec/ExampleLength: - 'spec/aruba/aruba_path_spec.rb' - 'spec/aruba/matchers/collection_spec.rb' -# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. -# Include: **/*_spec*rb*, **/spec/**/* +# Configuration parameters: CustomTransform, IgnoreMethods. RSpec/FilePath: Exclude: - 'spec/aruba/platform/windows_environment_variables_spec.rb' @@ -154,13 +135,10 @@ RSpec/InstanceVariable: - 'spec/event_bus_spec.rb' - 'spec/support/shared_contexts/aruba.rb' +# Configuration parameters: AggregateFailuresByDefault. RSpec/MultipleExpectations: Max: 5 -# Configuration parameters: AllowSubject. -RSpec/MultipleMemoizedHelpers: - Max: 11 - RSpec/NestedGroups: Max: 6 @@ -174,8 +152,6 @@ Style/AccessModifierDeclarations: Exclude: - 'lib/aruba/matchers/collection/all.rb' -# Cop supports --auto-correct. -# Configuration parameters: AllowOnConstant. Style/CaseEquality: Exclude: - 'lib/aruba/matchers/base/object_formatter.rb' @@ -192,20 +168,11 @@ Style/Documentation: - 'lib/aruba/platforms/command_monitor.rb' - 'lib/aruba/setup.rb' -# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods. +# Configuration parameters: EnforcedStyle. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: - EnforcedStyle: unannotated - -# Configuration parameters: MinBranchesCount. -Style/HashLikeCase: - Exclude: - - 'lib/aruba/cucumber/command.rb' + Enabled: false -# Configuration parameters: AllowedMethods. -# AllowedMethods: respond_to_missing? -Style/OptionalBooleanParameter: +Style/MethodMissingSuper: Exclude: - - 'lib/aruba/api/core.rb' - - 'lib/aruba/platforms/aruba_file_creator.rb' - - 'lib/aruba/setup.rb' + - 'lib/aruba/platforms/command_monitor.rb' From d1886e2cae0eac542b20e82555a6b1c6dad5b4af Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 26 Feb 2021 13:33:41 +0100 Subject: [PATCH 3/5] Run tests on Ruby 2.3 on Linux in CI --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index eb6ca4193..2c4f5d815 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -18,7 +18,7 @@ jobs: test-ubuntu: strategy: matrix: - ruby: [2.4.0, 2.4, 2.5, 2.6, 2.7, "3.0", jruby-9.2] + ruby: [2.3.0, 2.3, 2.4, 2.5, 2.6, 2.7, "3.0", jruby-9.2] runs-on: ubuntu-latest From c9786770e8ac65f00cfa4b40fc86e58516ac3a32 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 27 Feb 2021 11:18:38 +0100 Subject: [PATCH 4/5] Fix RuboCop offenses --- lib/aruba/config/jruby.rb | 2 +- lib/aruba/initializer.rb | 2 +- lib/aruba/matchers/base/message_indenter.rb | 2 +- lib/aruba/platforms/unix_platform.rb | 2 +- lib/aruba/platforms/windows_command_string.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/aruba/config/jruby.rb b/lib/aruba/config/jruby.rb index 99244729d..01481cc7e 100644 --- a/lib/aruba/config/jruby.rb +++ b/lib/aruba/config/jruby.rb @@ -17,7 +17,7 @@ env["JRUBY_OPTS"] = jruby_opts - if /solaris|sunos/i.match(RbConfig::CONFIG["host_os"]) + if /solaris|sunos/i =~ RbConfig::CONFIG["host_os"] java_opts = env["JAVA_OPTS"] || "" # force jRuby to use client JVM for faster startup times diff --git a/lib/aruba/initializer.rb b/lib/aruba/initializer.rb index 6af2a5230..47246dfa8 100644 --- a/lib/aruba/initializer.rb +++ b/lib/aruba/initializer.rb @@ -24,7 +24,7 @@ def add_gem content = if File.exist? file file_ends_with_carriage_return = - File.open(file, "r").readlines.last.match(/.*\n$/) + File.open(file, "r").readlines.last =~ /.*\n$/ prefix = file_ends_with_carriage_return ? "" : "\n" diff --git a/lib/aruba/matchers/base/message_indenter.rb b/lib/aruba/matchers/base/message_indenter.rb index afc806a4f..4cdcf150f 100644 --- a/lib/aruba/matchers/base/message_indenter.rb +++ b/lib/aruba/matchers/base/message_indenter.rb @@ -10,7 +10,7 @@ module MessageIndenter def indent_multiline_message(message) message = message.sub(/\n+\z/, "") message.lines.map do |line| - /\S/.match(line) ? " #{line}" : line + /\S/ =~ line ? " #{line}" : line end.join end end diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index ad0232047..261ad2745 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -83,7 +83,7 @@ def default_shell end def detect_ruby(cmd) - if /^ruby\s/.match(cmd) + if /^ruby\s/ =~ cmd cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd diff --git a/lib/aruba/platforms/windows_command_string.rb b/lib/aruba/platforms/windows_command_string.rb index ad1250355..08dc05929 100644 --- a/lib/aruba/platforms/windows_command_string.rb +++ b/lib/aruba/platforms/windows_command_string.rb @@ -22,7 +22,7 @@ def to_a def escaped_arguments @arguments.map { |arg| arg.gsub(/"/, '"""') } - .map { |arg| / /.match(arg) ? "\"#{arg}\"" : arg } + .map { |arg| / / =~ arg ? "\"#{arg}\"" : arg } end def escaped_command From 7be07f06b0715089a6ab90b94c7eda13ef3234f7 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 28 Feb 2021 13:04:06 +0100 Subject: [PATCH 5/5] Update version support section in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f9692b12..fc2bdaab4 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ We try to comply with [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0. ## Supported Ruby versions -Aruba is supported on Ruby 2.4 and up, and tested against CRuby 2.4, 2.5, 2.6 -and 2.7, and JRuby 9.2. +Aruba is supported on Ruby 2.3 and up, and tested against CRuby 2.3, 2.4, 2.5, +2.6 and 2.7, and JRuby 9.2. ## Supported operating systems