diff --git a/.rubocop.yml b/.rubocop.yml index fe89e9f56..0413f848b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,20 +13,18 @@ Style/PercentLiteralDelimiters: PreferredDelimiters: '%w': () +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + # Code is currently broken with frozen string literal comments applied. # TODO: Enable and fix build Style/FrozenStringLiteralComment: Enabled: false -# TODO: This is placed in here so the auto-gen-config doesn't destroy these. -# Most of these need to be manually tackled, the LineLength value currently is good enough to stop most of -# these leaking through into the codebase -# Offense count: 375+ -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https +# Be relatively lenient with line length Layout/LineLength: - Max: 140 + Max: 94 # We only permit it in this one area which is internal code testing. Never exposed to users Security/Eval: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 468e18b18..2dba218a8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,24 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-04-11 12:33:09 +0200 using RuboCop version 0.79.0. +# on 2020-04-11 14:49:42 +0200 using RuboCop version 0.79.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: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'lib/aruba/api/core.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'lib/aruba/api/core.rb' - # Offense count: 7 Lint/AmbiguousBlockAssociation: Exclude: @@ -40,30 +27,30 @@ Lint/Void: Metrics/AbcSize: Max: 116 -# Offense count: 74 +# Offense count: 75 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 593 + Max: 604 # Offense count: 2 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 153 + Max: 158 # Offense count: 5 Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 27 +# Offense count: 28 # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: - Max: 47 + Max: 59 -# Offense count: 2 +# Offense count: 3 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 171 + Max: 182 # Offense count: 3 # Configuration parameters: CountKeywordArgs. @@ -106,17 +93,6 @@ Naming/MethodParameterName: - 'lib/aruba/platforms/unix_platform.rb' - 'lib/aruba/tasks/docker_helpers.rb' -# Offense count: 1 -# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# ForbiddenPrefixes: is_, has_, have_ -# AllowedMethods: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: - Exclude: - - 'spec/**/*' - - 'lib/aruba/matchers/base/base_matcher.rb' - # Offense count: 1 Performance/Caller: Exclude: @@ -141,20 +117,6 @@ Style/CaseEquality: Exclude: - 'lib/aruba/matchers/base/object_formatter.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/CharacterLiteral: - Exclude: - - 'spec/support/shared_contexts/aruba.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: is_a?, kind_of? -Style/ClassCheck: - Exclude: - - 'lib/aruba/api/filesystem.rb' - # Offense count: 1 Style/CommentedKeyword: Exclude: @@ -179,7 +141,7 @@ Style/EvalWithLocation: Exclude: - 'spec/support/helpers/reporting.rb' -# Offense count: 84 +# Offense count: 83 # Configuration parameters: EnforcedStyle. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: @@ -190,24 +152,6 @@ Style/IdenticalConditionalBranches: Exclude: - 'lib/aruba/hooks.rb' -# Offense count: 7 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'lib/aruba/cucumber/command.rb' - - 'lib/aruba/matchers/collection/include_an_object.rb' - - 'lib/aruba/platforms/unix_environment_variables.rb' - - 'lib/aruba/setup.rb' - - 'spec/aruba/platform/windows_environment_variables_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'spec/aruba/hooks_spec.rb' - # Offense count: 5 Style/MethodMissingSuper: Exclude: @@ -216,14 +160,6 @@ Style/MethodMissingSuper: - 'lib/aruba/platforms/command_monitor.rb' - 'lib/aruba/tasks/docker_helpers.rb' -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowedMethods. -# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'spec/aruba/matchers/collection_spec.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. @@ -233,14 +169,6 @@ Style/NumericPredicate: - 'spec/**/*' - 'lib/aruba/contracts/is_power_of_two.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'Rakefile' - - 'lib/aruba/api/bundler.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowInnerSlashes. @@ -249,41 +177,3 @@ Style/RegexpLiteral: Exclude: - 'lib/aruba/cucumber/command.rb' - 'lib/aruba/cucumber/file.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'lib/aruba/contracts/absolute_path.rb' - - 'lib/aruba/contracts/is_power_of_two.rb' - - 'lib/aruba/contracts/relative_path.rb' - - 'lib/aruba/event_bus/name_resolver.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'lib/aruba/platforms/aruba_fixed_size_file_creator.rb' - -# Offense count: 35 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: only_raise, only_fail, semantic -Style/SignalException: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/StderrPuts: - Exclude: - - 'lib/aruba/initializer.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets diff --git a/Gemfile b/Gemfile index 76067723f..8f39fe12c 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,9 @@ source 'https://rubygems.org' gemspec # Load local Gemfile -load File.expand_path('Gemfile.local', __dir__) if File.file? File.expand_path('Gemfile.local', __dir__) +if File.file? File.expand_path('Gemfile.local', __dir__) + load File.expand_path('Gemfile.local', __dir__) +end unless RUBY_PLATFORM.include?('java') gem 'byebug', '~> 11.0' diff --git a/Rakefile b/Rakefile index 6ea718fce..fc56da43c 100644 --- a/Rakefile +++ b/Rakefile @@ -18,13 +18,13 @@ require 'cucumber/rake/task' require 'rspec/core/rake_task' Cucumber::Rake::Task.new do |t| - t.cucumber_opts = %w{--format progress} + t.cucumber_opts = %w(--format progress) end Cucumber::Rake::Task.new('cucumber:wip', 'Run Cucumber features '\ 'which are "WORK IN PROGRESS" and '\ 'are allowed to fail') do |t| - t.cucumber_opts = %w{--format progress} + t.cucumber_opts = %w(--format progress) t.profile = 'wip' end @@ -53,7 +53,8 @@ namespace :docker do args.with_defaults(version: 'latest') args.with_defaults(cache: true) - docker_compose_file = Aruba::DockerComposeFile.new(File.expand_path('docker-compose.yml', __dir__)) + docker_compose_file = + Aruba::DockerComposeFile.new(File.expand_path('docker-compose.yml', __dir__)) docker_run_instance = Aruba::DockerRunInstance.new(docker_compose_file, :base) builder = Aruba::DockerBuildCommandLineBuilder.new( @@ -67,7 +68,8 @@ namespace :docker do desc 'Run docker container' task :run, :command do |_, args| - docker_compose_file = Aruba::DockerComposeFile.new(File.expand_path('docker-compose.yml', __dir__)) + docker_compose_file = + Aruba::DockerComposeFile.new(File.expand_path('docker-compose.yml', __dir__)) docker_run_instance = Aruba::DockerRunInstance.new(docker_compose_file, :base) builder = Aruba::DockerRunCommandLineBuilder.new( diff --git a/aruba.gemspec b/aruba.gemspec index d8df401c7..5d2779613 100644 --- a/aruba.gemspec +++ b/aruba.gemspec @@ -6,8 +6,10 @@ Gem::Specification.new do |spec| spec.name = 'aruba' spec.version = Aruba::VERSION spec.author = 'Aslak Hellesøy, Matt Wynne and other Aruba Contributors' - spec.description = 'Extension for popular TDD and BDD frameworks like "Cucumber", "RSpec" and "Minitest", -to make testing commandline applications meaningful, easy and fun.' + spec.description = <<~TEXT + Extension for popular TDD and BDD frameworks like "Cucumber", "RSpec" and "Minitest", + to make testing commandline applications meaningful, easy and fun. + TEXT spec.summary = "aruba-#{spec.version}" spec.license = 'MIT' spec.email = 'cukes@googlegroups.com' diff --git a/features/support/env.rb b/features/support/env.rb index 6e1b63741..5e4b5fb27 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -19,12 +19,15 @@ command_name = "#{scenario.feature.name} #{scenario.name}" - # Used in simplecov_setup so that each scenario has a different name and their coverage results are merged instead - # of overwriting each other as 'Cucumber Features' + # Used in simplecov_setup so that each scenario has a different name and + # their coverage results are merged instead of overwriting each other as + # 'Cucumber Features' ENV['SIMPLECOV_COMMAND_NAME'] = command_name.to_s - simplecov_setup_pathname = Pathname.new(__FILE__).expand_path.parent.join('simplecov_setup') + simplecov_setup_pathname = + Pathname.new(__FILE__).expand_path.parent.join('simplecov_setup') - # set environment variable so child processes will merge their coverage data with parent process's coverage data. + # set environment variable so child processes will merge their coverage data + # with parent process's coverage data. ENV['RUBYOPT'] = "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}" end diff --git a/fixtures/cli-app/cli-app.gemspec b/fixtures/cli-app/cli-app.gemspec index 98ae31abf..0de59afb8 100644 --- a/fixtures/cli-app/cli-app.gemspec +++ b/fixtures/cli-app/cli-app.gemspec @@ -15,7 +15,8 @@ Gem::Specification.new do |spec| # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or # delete this section to allow pushing this gem to any host. - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = `git ls-files -z`.split("\x0") + .reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] diff --git a/fixtures/cli-app/spec/spec_helper.rb b/fixtures/cli-app/spec/spec_helper.rb index b9fd64026..0646b6153 100644 --- a/fixtures/cli-app/spec/spec_helper.rb +++ b/fixtures/cli-app/spec/spec_helper.rb @@ -4,4 +4,5 @@ require_relative 'support/aruba' -::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f } +::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)) + .each { |f| require_relative f } diff --git a/fixtures/empty-app/cli-app.gemspec b/fixtures/empty-app/cli-app.gemspec index 98ae31abf..0de59afb8 100644 --- a/fixtures/empty-app/cli-app.gemspec +++ b/fixtures/empty-app/cli-app.gemspec @@ -15,7 +15,8 @@ Gem::Specification.new do |spec| # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or # delete this section to allow pushing this gem to any host. - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = `git ls-files -z`.split("\x0") + .reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] diff --git a/lib/aruba/api/bundler.rb b/lib/aruba/api/bundler.rb index 650acc3c3..af4563701 100644 --- a/lib/aruba/api/bundler.rb +++ b/lib/aruba/api/bundler.rb @@ -7,7 +7,7 @@ module Bundler # Unset variables used by bundler def unset_bundler_env_vars - %w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key| + %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key| delete_environment_variable(key) end end diff --git a/lib/aruba/api/commands.rb b/lib/aruba/api/commands.rb index bbdde93c8..a09d52ff7 100644 --- a/lib/aruba/api/commands.rb +++ b/lib/aruba/api/commands.rb @@ -221,10 +221,10 @@ def close_input private def prepare_command(cmd, opts) - exit_timeout = opts[:exit_timeout].nil? ? aruba.config.exit_timeout : opts[:exit_timeout] - io_wait_timeout = opts[:io_wait_timeout].nil? ? aruba.config.io_wait_timeout : opts[:io_wait_timeout] - stop_signal = opts[:stop_signal].nil? ? aruba.config.stop_signal : opts[:stop_signal] - startup_wait_time = opts[:startup_wait_time].nil? ? aruba.config.startup_wait_time : opts[:startup_wait_time] + exit_timeout = opts[:exit_timeout] || aruba.config.exit_timeout + io_wait_timeout = opts[:io_wait_timeout] || aruba.config.io_wait_timeout + stop_signal = opts[:stop_signal] || aruba.config.stop_signal + startup_wait_time = opts[:startup_wait_time] || aruba.config.startup_wait_time cmd = replace_variables(cmd) diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index 1a6d5f72f..c67f6354a 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -15,8 +15,10 @@ module Core # Aruba Runtime def aruba - # TODO: Check this variable being accessed inconsistently. Should only be using the memo! - # Renaming this to `aruba` causes 100's of rspec failures. Needs a deeper dive, approach with caution! + # TODO: Check this variable being accessed inconsistently. Should only + # be using the memo! + # Renaming this to `aruba` causes 100's of rspec failures. Needs a + # deeper dive, approach with caution! @_aruba_runtime ||= Runtime.new end @@ -58,18 +60,21 @@ def cd(dir, &block) if block_given? begin unless Aruba.platform.directory?(expand_path(dir)) - raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." + raise ArgumentError, + "#{expand_path(dir)} is not a directory or does not exist." end old_directory = expand_path('.') aruba.current_directory << dir new_directory = expand_path('.') - aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory) + aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, + new: new_directory) old_dir = Aruba.platform.getwd - real_new_directory = File.expand_path(aruba.current_directory, aruba.root_directory) + real_new_directory = File.expand_path(aruba.current_directory, + aruba.root_directory) Aruba.platform.chdir real_new_directory result = with_environment( @@ -85,16 +90,20 @@ def cd(dir, &block) return result end - raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory?(expand_path(dir)) + unless Aruba.platform.directory?(expand_path(dir)) + raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." + end old_directory = expand_path('.') aruba.current_directory << dir new_directory = expand_path('.') - aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory) + aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, + new: new_directory) self end + # Expand file name # # @param [String] file_name @@ -132,26 +141,32 @@ def cd(dir, &block) # expand_path('/foo/bar') # def expand_path(file_name, dir_string = nil) - message = "Filename #{file_name} needs to be a string. It cannot be nil or empty either. "\ + message = "Filename #{file_name} needs to be a string." \ + ' It cannot be nil or empty either. '\ "Please use `expand_path('.')` if you want the current directory to be expanded." - fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty? + raise ArgumentError, message unless file_name.is_a?(String) && !file_name.empty? - unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory) - fail %(Aruba's working directory does not exist. Maybe you forgot to run `setup_aruba` before using its API.) + unless Aruba.platform.directory? File.join(aruba.config.root_directory, + aruba.config.working_directory) + raise "Aruba's working directory does not exist." \ + ' Maybe you forgot to run `setup_aruba` before using its API.' end - prefix = file_name[0] rest = file_name[2..-1] if aruba.config.fixtures_path_prefix == prefix path = File.join(*[aruba.fixtures_directory, rest].compact) unless Aruba.platform.exist? path - aruba_fixture_candidates = aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ') - - raise ArgumentError, "Fixture \"#{rest}\" does not exist in fixtures directory \"#{aruba.fixtures_directory}\". "\ - "This was the one we found first on your system from all possible candidates: #{aruba_fixture_candidates}." + aruba_fixture_candidates = aruba.config.fixtures_directories + .map { |p| format('"%s"', p) }.join(', ') + + raise ArgumentError, + "Fixture \"#{rest}\" does not exist" \ + " in fixtures directory \"#{aruba.fixtures_directory}\"." \ + ' This was the one we found first on your system from all possible' \ + " candidates: #{aruba_fixture_candidates}." end path @@ -161,15 +176,21 @@ def expand_path(file_name, dir_string = nil) end raise ArgumentError, 'Expanding "~/" to "/" is not allowed' if path == '/' - raise ArgumentError, "Expanding \"~\" to a relative path \"#{path}\" is not allowed" unless Aruba.platform.absolute_path? path + + unless Aruba.platform.absolute_path? path + raise ArgumentError, + "Expanding \"~\" to a relative path \"#{path}\" is not allowed" + end path.to_s elsif absolute?(file_name) unless aruba.config.allow_absolute_paths caller_location = caller_locations(1, 1).first caller_file_line = "#{caller_location.path}:#{caller_location.lineno}" - aruba.logger.warn "Aruba's `expand_path` method was called with an absolute path at #{caller_file_line}"\ - ', which is not recommended. Change the call to pass a relative path or set '\ + aruba.logger.warn \ + "Aruba's `expand_path` method was called with an absolute path" \ + " at #{caller_file_line}, which is not recommended." \ + ' Change the call to pass a relative path or set '\ '`config.allow_absolute_paths = true` to silence this warning' end file_name @@ -182,7 +203,6 @@ def expand_path(file_name, dir_string = nil) end end - # Run block with environment # # @param [Hash] env (optional) diff --git a/lib/aruba/api/environment.rb b/lib/aruba/api/environment.rb index 2db0e6a2b..6ee0561b3 100644 --- a/lib/aruba/api/environment.rb +++ b/lib/aruba/api/environment.rb @@ -23,7 +23,9 @@ def set_environment_variable(name, value) aruba.environment[name] = value new_environment = aruba.environment.to_h - environment_change = { old: old_environment, new: new_environment, changed: { name: name, value: value } } + environment_change = { old: old_environment, + new: new_environment, + changed: { name: name, value: value } } aruba.event_bus.notify Events::AddedEnvironmentVariable.new(environment_change) self @@ -46,7 +48,9 @@ def append_environment_variable(name, value) aruba.environment.append name, value new_environment = aruba.environment.to_h - environment_change = { old: old_environment, new: new_environment, changed: { name: name, value: value } } + environment_change = { old: old_environment, + new: new_environment, + changed: { name: name, value: value } } aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change) self @@ -69,7 +73,9 @@ def prepend_environment_variable(name, value) aruba.environment.prepend name, value new_environment = aruba.environment.to_h - environment_change = { old: old_environment, new: new_environment, changed: { name: name, value: value } } + environment_change = { old: old_environment, + new: new_environment, + changed: { name: name, value: value } } aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change) self @@ -88,7 +94,9 @@ def delete_environment_variable(name) aruba.environment.delete name new_environment = aruba.environment.to_h - environment_change = { old: old_environment, new: new_environment, changed: { name: name, value: '' } } + environment_change = { old: old_environment, + new: new_environment, + changed: { name: name, value: '' } } aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change) self diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 12a924fc7..f8fc94721 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -92,7 +92,7 @@ def all_directories # @return [Dir] # The directory object def directory(path) - fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name + raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name Dir.new(expand_path(path)) end @@ -102,22 +102,31 @@ def directory(path) # @return [Array] # The content of directory def list(name) - fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name - fail ArgumentError, %(Only directories are supported. Path "#{name}" is not a directory.) unless directory? name + raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name + + unless directory? name + raise ArgumentError, + %(Only directories are supported. Path "#{name}" is not a directory.) + end existing_files = Dir.glob(expand_path(File.join(name, '**', '*'))) current_working_directory = Pathname.new(expand_path('.')) - existing_files.map { |d| Pathname.new(d).relative_path_from(current_working_directory).to_s } + existing_files.map do |d| + Pathname.new(d).relative_path_from(current_working_directory).to_s + end end # Return content of file # # @return [Array] - # The content of file, without "\n" or "\r\n" at the end. To rebuild the file use `content.join("\n")` + # The content of file, without "\n" or "\r\n" at the end. + # To rebuild the file use `content.join("\n")` def read(name) - fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name - fail ArgumentError, %(Only files are supported. Path "#{name}" is not a file.) unless file? name + raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name + unless file? name + raise ArgumentError, %(Only files are supported. Path "#{name}" is not a file.) + end File.readlines(expand_path(name)).map(&:chomp) end @@ -145,7 +154,7 @@ def write_file(name, content) def touch(*args) args = args.flatten - options = if args.last.kind_of? Hash + options = if args.last.is_a? Hash args.pop else {} @@ -178,7 +187,8 @@ def copy(*args) end if destination.start_with? aruba.config.fixtures_path_prefix - raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" + raise ArgumentError, + "Using a fixture as destination (#{destination}) is not supported" end if source.count > 1 && exist?(destination) && !directory?(destination) @@ -216,11 +226,14 @@ def move(*args) source = args source.each do |s| - raise ArgumentError, "Using a fixture as source (#{source}) is not supported" if s.start_with? aruba.config.fixtures_path_prefix + if s.start_with? aruba.config.fixtures_path_prefix + raise ArgumentError, "Using a fixture as source (#{source}) is not supported" + end end if destination.start_with? aruba.config.fixtures_path_prefix - raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" + raise ArgumentError, + "Using a fixture as destination (#{destination}) is not supported" end source.each do |s| @@ -283,14 +296,14 @@ def overwrite_file(name, content) def chmod(*args) args = args.flatten - options = if args.last.kind_of? Hash + options = if args.last.is_a? Hash args.pop else {} end mode = args.shift - mode = if mode.kind_of? String + mode = if mode.is_a? String mode.to_i(8) else mode @@ -335,7 +348,7 @@ def create_directory(directory_name) def remove(*args) args = args.flatten - options = if args.last.kind_of? Hash + options = if args.last.is_a? Hash args.pop else {} diff --git a/lib/aruba/api/text.rb b/lib/aruba/api/text.rb index 884b34958..2a0ddf200 100644 --- a/lib/aruba/api/text.rb +++ b/lib/aruba/api/text.rb @@ -14,7 +14,14 @@ module Text # @param [#to_s] text # Input def unescape_text(text) - text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t") + text + .gsub('\n', "\n") + .gsub('\"', '"') + .gsub('\e', "\e") + .gsub('\033', "\e") + .gsub('\016', "\016") + .gsub('\017', "\017") + .gsub('\t', "\t") end # Remove ansi characters from text @@ -22,7 +29,10 @@ def unescape_text(text) # @param [#to_s] text # Input def extract_text(text) - text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '') + text + .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '') + .gsub(/\\\[|\\\]/, '') + .gsub(/\007|\016|\017/, '') end # Unescape special characters and remove ANSI characters @@ -41,7 +51,9 @@ def sanitize_text(text) # @param [#to_s] text # The text to parse def replace_variables(text) - text = text.gsub(//, last_command_started.pid.to_s) if text.include? '' + if text.include? '' + text = text.gsub(//, last_command_started.pid.to_s) + end text end diff --git a/lib/aruba/basic_configuration.rb b/lib/aruba/basic_configuration.rb index da56adbcf..999b813c6 100644 --- a/lib/aruba/basic_configuration.rb +++ b/lib/aruba/basic_configuration.rb @@ -32,8 +32,8 @@ def option_reader(name, opts = {}) contract = opts[:contract] default = opts[:default] - fail ArgumentError, 'Either use block or default value' if block_given? && default - fail ArgumentError, 'contract-options is required' if contract.nil? + raise ArgumentError, 'Either use block or default value' if block_given? && default + raise ArgumentError, 'contract-options is required' if contract.nil? Contract contract add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default) @@ -61,9 +61,8 @@ def option_accessor(name, opts = {}) contract = opts[:contract] default = opts[:default] - fail ArgumentError, 'Either use block or default value' if block_given? && default - # fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.to_s.empty? - fail ArgumentError, 'contract-options is required' if contract.nil? + raise ArgumentError, 'Either use block or default value' if block_given? && default + raise ArgumentError, 'contract-options is required' if contract.nil? # Add writer add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default) @@ -210,7 +209,7 @@ def initialize_configuration end def find_option(name) - fail NotImplementedError, %(Unknown option "#{name}") unless option? name + raise NotImplementedError, %(Unknown option "#{name}") unless option? name local_options[name] end diff --git a/lib/aruba/basic_configuration/option.rb b/lib/aruba/basic_configuration/option.rb index a32e742eb..2b8b15e53 100644 --- a/lib/aruba/basic_configuration/option.rb +++ b/lib/aruba/basic_configuration/option.rb @@ -15,8 +15,8 @@ def initialize(opts = {}) name = opts[:name] value = opts[:value] - fail ArgumentError, '"name" is required' unless opts.key? :name - fail ArgumentError, '"value" is required' unless opts.key? :value + raise ArgumentError, '"name" is required' unless opts.key? :name + raise ArgumentError, '"value" is required' unless opts.key? :value @name = name @value = value diff --git a/lib/aruba/cli.rb b/lib/aruba/cli.rb index 895425a66..ce6bfdc62 100644 --- a/lib/aruba/cli.rb +++ b/lib/aruba/cli.rb @@ -18,7 +18,10 @@ def console end desc 'init', 'Initialize aruba' - option :test_framework, default: 'cucumber', enum: %w(cucumber rspec minitest), desc: 'Choose which test framework to use' + option :test_framework, + default: 'cucumber', + enum: %w(cucumber rspec minitest), + desc: 'Choose which test framework to use' def init Aruba::Initializer.new.call(options[:test_framework]) end diff --git a/lib/aruba/configuration.rb b/lib/aruba/configuration.rb index 5d85a1118..1fd4ed0fd 100644 --- a/lib/aruba/configuration.rb +++ b/lib/aruba/configuration.rb @@ -20,7 +20,8 @@ class Configuration < BasicConfiguration option_reader :root_directory, contract: { None => String }, default: Dir.getwd option_accessor :working_directory, - contract: { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath }, + contract: { Aruba::Contracts::RelativePath => + Aruba::Contracts::RelativePath }, default: 'tmp/aruba' option_reader :fixtures_path_prefix, contract: { None => String }, default: '%' @@ -36,7 +37,8 @@ class Configuration < BasicConfiguration option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {} option_accessor :command_search_paths, contract: { ArrayOf[String] => ArrayOf[String] } do |config| - [File.join(config.root_directory.value, 'bin'), File.join(config.root_directory.value, 'exe')] + [File.join(config.root_directory.value, 'bin'), + File.join(config.root_directory.value, 'exe')] end option_accessor :remove_ansi_escape_sequences, contract: { Bool => Bool }, default: true option_accessor :command_launcher, @@ -57,8 +59,10 @@ class Configuration < BasicConfiguration option_accessor :log_level, contract: { - Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, :error, :unknown, :silent] => - Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, :error, :unknown, :silent] + Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, + :error, :unknown, :silent] => + Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, + :error, :unknown, :silent] }, default: :info @@ -66,11 +70,15 @@ class Configuration < BasicConfiguration # equal to 4096 by default. "filesystem allocation unit" would represent # the actual MINIMUM space taken in bytes by a 1-byte file option_accessor :physical_block_size, - contract: { Aruba::Contracts::IsPowerOfTwo => Aruba::Contracts::IsPowerOfTwo }, + contract: { Aruba::Contracts::IsPowerOfTwo => + Aruba::Contracts::IsPowerOfTwo }, default: 512 - option_accessor :console_history_file, contract: { String => String }, default: '~/.aruba_history' + option_accessor :console_history_file, contract: { String => String }, + default: '~/.aruba_history' - option_accessor :activate_announcer_on_command_failure, contract: { ArrayOf[Symbol] => ArrayOf[Symbol] }, default: [] + option_accessor :activate_announcer_on_command_failure, + contract: { ArrayOf[Symbol] => ArrayOf[Symbol] }, + default: [] option_accessor :allow_absolute_paths, contract: { Bool => Bool }, default: false end end diff --git a/lib/aruba/console/help.rb b/lib/aruba/console/help.rb index a850c846b..3810204b1 100644 --- a/lib/aruba/console/help.rb +++ b/lib/aruba/console/help.rb @@ -10,7 +10,8 @@ module Help def aruba_help puts 'Aruba Version: ' + Aruba::VERSION puts 'Issue Tracker: ' + 'https://github.com/cucumber/aruba/issues' - puts "Documentation:\n" + %w(http://www.rubydoc.info/gems/aruba).map { |d| format('* %s', d) }.join("\n") + puts 'Documentation:' + puts '* http://www.rubydoc.info/gems/aruba' puts nil @@ -18,7 +19,9 @@ def aruba_help # List available methods in aruba def aruba_methods - ms = (Aruba::Api.instance_methods - Module.instance_methods).each_with_object([]) { |e, a| a << format('* %s', e) }.sort + ms = (Aruba::Api.instance_methods - Module.instance_methods) + .each_with_object([]) { |e, a| a << format('* %s', e) } + .sort puts "Available Methods:\n" + ms.join("\n") diff --git a/lib/aruba/contracts/absolute_path.rb b/lib/aruba/contracts/absolute_path.rb index 779cd488b..cb61ea81d 100644 --- a/lib/aruba/contracts/absolute_path.rb +++ b/lib/aruba/contracts/absolute_path.rb @@ -12,7 +12,7 @@ class AbsolutePath # The value to be checked def self.valid?(value) Aruba.platform.absolute_path? value - rescue + rescue StandardError false end end diff --git a/lib/aruba/contracts/is_power_of_two.rb b/lib/aruba/contracts/is_power_of_two.rb index dfa98e1ae..a6dbec263 100644 --- a/lib/aruba/contracts/is_power_of_two.rb +++ b/lib/aruba/contracts/is_power_of_two.rb @@ -14,7 +14,7 @@ def self.valid?(value) # explanation for algorithm can be found here: # http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/ value != 0 && (value & (value - 1)) == 0 ? true : false - rescue + rescue StandardError false end end diff --git a/lib/aruba/contracts/relative_path.rb b/lib/aruba/contracts/relative_path.rb index 12886c18e..b874171a4 100644 --- a/lib/aruba/contracts/relative_path.rb +++ b/lib/aruba/contracts/relative_path.rb @@ -12,7 +12,7 @@ class RelativePath # The path to be checked def self.valid?(value) Aruba.platform.relative_path? value - rescue + rescue StandardError false end end diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 8de4d0df5..a2b6876a2 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -12,7 +12,8 @@ run_command_and_stop(cmd, fail_on_error: true, exit_timeout: secs && secs.to_f) end -When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) do |shell, commands| +When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) \ + do |shell, commands| full_path = expand_path('bin/myscript') Aruba.platform.mkdir(expand_path('bin')) @@ -61,7 +62,8 @@ end end -When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) do |channel, expected| +When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) \ + do |channel, expected| begin Timeout.timeout(aruba.config.exit_timeout) do loop do @@ -119,7 +121,8 @@ end ## the stderr should contain "hello" -Then(/^(?:the )?(output|stderr|stdout) should( not)? contain( exactly)? "([^"]*)"$/) do |channel, negated, exactly, expected| +Then(/^(?:the )?(output|stderr|stdout) should( not)? contain( exactly)? "([^"]*)"$/) \ + do |channel, negated, exactly, expected| combined_output = send("all_#{channel}") output_string_matcher = if exactly @@ -136,7 +139,9 @@ end ## the stderr from "echo -n 'Hello'" should contain "hello" -Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)? "([^"]*)"$/) do |channel, cmd, exactly, expected| +Then( + /^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)? "([^"]*)"$/ +) do |channel, cmd, exactly, expected| matcher = case channel when 'output'; then :have_output when 'stderr'; then :have_output_on_stderr @@ -155,7 +160,9 @@ end ## the stderr from "echo -n 'Hello'" should not contain "hello" -Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)? "([^"]*)"$/) do |channel, cmd, exactly, expected| +Then( + /^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)? "([^"]*)"$/ +) do |channel, cmd, exactly, expected| matcher = case channel when 'output'; then :have_output when 'stderr'; then :have_output_on_stderr @@ -174,7 +181,8 @@ end ## the stderr should not contain exactly: -Then(/^(?:the )?(output|stderr|stdout) should not contain( exactly)?:$/) do |channel, exactly, expected| +Then(/^(?:the )?(output|stderr|stdout) should not contain( exactly)?:$/) \ + do |channel, exactly, expected| combined_output = send("all_#{channel}") output_string_matcher = if exactly @@ -187,7 +195,8 @@ end ## the stderr should contain exactly: -Then(/^(?:the )?(output|stderr|stdout) should contain( exactly)?:$/) do |channel, exactly, expected| +Then(/^(?:the )?(output|stderr|stdout) should contain( exactly)?:$/) \ + do |channel, exactly, expected| combined_output = send("all_#{channel}") output_string_matcher = if exactly @@ -200,7 +209,8 @@ end ## the stderr from "echo -n 'Hello'" should not contain exactly: -Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)?:$/) do |channel, cmd, exactly, expected| +Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)?:$/) \ + do |channel, cmd, exactly, expected| matcher = case channel when 'output'; then :have_output when 'stderr'; then :have_output_on_stderr @@ -219,7 +229,8 @@ end ## the stderr from "echo -n 'Hello'" should contain exactly: -Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)?:$/) do |channel, cmd, exactly, expected| +Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)?:$/) \ + do |channel, cmd, exactly, expected| matcher = case channel when 'output'; then :have_output when 'stderr'; then :have_output_on_stderr @@ -243,32 +254,36 @@ # appear naturally in the output Then(/^the output should( not)? match \/([^\/]*)\/$/) do |negated, expected| if negated - expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .not_to include_an_object have_output an_output_string_matching(expected) else - expect(all_commands).to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .to include_an_object have_output an_output_string_matching(expected) end end Then(/^the output should( not)? match %r<([^>]*)>$/) do |negated, expected| if negated - expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .not_to include_an_object have_output an_output_string_matching(expected) else - expect(all_commands).to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .to include_an_object have_output an_output_string_matching(expected) end end Then(/^the output should( not)? match:$/) do |negated, expected| if negated - expect(all_commands).not_to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .not_to include_an_object have_output an_output_string_matching(expected) else - expect(all_commands).to include_an_object have_output an_output_string_matching(expected) + expect(all_commands) + .to include_an_object have_output an_output_string_matching(expected) end end Then(/^the exit status should( not)? be (\d+)$/) do |negated, exit_status| - if last_command_stopped.nil? - last_command_started.stop - end + last_command_started.stop if last_command_stopped.nil? if negated expect(last_command_stopped).not_to have_exit_status exit_status.to_i @@ -383,7 +398,8 @@ expect(all_commands).to include_an_object send(matcher, be_nil.or(be_empty)) end -Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) do |channel, negated, table| +Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) \ + do |channel, negated, table| table.raw.flatten.each do |expected| _matcher = case channel when 'output'; then :have_output @@ -394,9 +410,11 @@ # TODO: This isn't actually using the above. It's hardcoded to use have_output only if negated - expect(all_commands).not_to include_an_object have_output an_output_string_including(expected) + expect(all_commands) + .not_to include_an_object have_output an_output_string_including(expected) else - expect(all_commands).to include_an_object have_output an_output_string_including(expected) + expect(all_commands) + .to include_an_object have_output an_output_string_including(expected) end end end @@ -417,10 +435,11 @@ aruba.config.startup_wait_time = seconds.to_f end -When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))$/) do |signal, command| +When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))$/) \ + do |signal, command| if command cmd = all_commands.find { |c| c.commandline == command } - fail ArgumentError, %(No command "#{command}" found) if cmd.nil? + raise ArgumentError, %(No command "#{command}" found) if cmd.nil? cmd.send_signal signal else diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index dbc234651..722b40d16 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -3,11 +3,13 @@ cd name end -Given(/^I copy (?:a|the) (?:file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) do |source, destination| +Given(/^I copy (?:a|the) (?:file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) \ + do |source, destination| copy source, destination end -Given(/^I move (?:a|the) (?:file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) do |source, destination| +Given(/^I move (?:a|the) (?:file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) \ + do |source, destination| move source, destination end @@ -15,7 +17,8 @@ create_directory(dir_name) end -Given(/^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/) do |dir_name, dir_mode| +Given(/^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/) \ + do |dir_name, dir_mode| create_directory(dir_name) chmod(dir_mode, dir_name) end @@ -32,7 +35,8 @@ write_file(file_name, unescape_text(file_content)) end -Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content| +Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) \ + do |file_name, file_mode, file_content| write_file(file_name, unescape_text(file_content)) chmod(file_mode, file_name) end @@ -45,7 +49,8 @@ write_file(file_name, '') end -Given(/^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/) do |file_name, file_mode| +Given(/^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/) \ + do |file_name, file_mode| write_file(file_name, '') chmod(file_mode, file_name) end @@ -54,7 +59,8 @@ write_file(file_name, file_content) end -When(/^I overwrite(?: (?:a|the) file(?: named)?)? "([^"]*)" with:$/) do |file_name, file_content| +When(/^I overwrite(?: (?:a|the) file(?: named)?)? "([^"]*)" with:$/) \ + do |file_name, file_content| overwrite_file(file_name, file_content) end @@ -66,7 +72,8 @@ append_to_file(file_name, file_content) end -When(/^I remove (?:a|the) (?:file|directory)(?: named)? "([^"]*)"( with full force)?$/) do |name, force_remove| +When(/^I remove (?:a|the) (?:file|directory)(?: named)? "([^"]*)"( with full force)?$/) \ + do |name, force_remove| remove(name, force: force_remove.nil? ? false : true) end @@ -88,7 +95,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist(?: anymore)?$/) do |path, expect_match| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist(?: anymore)?$/) \ + do |path, expect_match| if expect_match expect(path).not_to be_an_existing_file else @@ -96,7 +104,8 @@ end end -Then(/^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist(?: anymore)?$/) do |path, expect_match| +Then(/^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist(?: anymore)?$/) \ + do |path, expect_match| if expect_match expect(path).not_to be_an_existing_directory else @@ -112,7 +121,8 @@ end end -Then(/^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/) do |size, file, negated| +Then(/^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/) \ + do |size, file, negated| if negated expect(file).not_to have_file_size(size) else @@ -130,7 +140,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/) do |file, negated, content| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/) \ + do |file, negated, content| if negated expect(file).not_to have_file_content file_content_including(content.chomp) else @@ -138,7 +149,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/) do |file, negated, content| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/) \ + do |file, negated, content| if negated expect(file).not_to have_file_content file_content_including(content.chomp) else @@ -146,7 +158,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain exactly:$/) do |file, negated, content| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain exactly:$/) \ + do |file, negated, content| if negated expect(file).not_to have_file_content content else @@ -154,7 +167,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^>]*)>$/) do |file, negated, content| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^>]*)>$/) \ + do |file, negated, content| if negated expect(file).not_to have_file_content file_content_matching(content) else @@ -162,7 +176,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/) do |file, negated, content| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/) \ + do |file, negated, content| if negated expect(file).not_to have_file_content file_content_matching(content) else @@ -170,7 +185,8 @@ end end -Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/) do |file, negated, reference_file| +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/) \ + do |file, negated, reference_file| if negated expect(file).not_to have_same_file_content_as(reference_file) else @@ -178,10 +194,14 @@ end end -Then(/^(?:a|the) (?:file|directory)(?: named)? "([^"]*)" should( not)? have permissions "([^"]*)"$/) do |path, negated, permissions| - if negated - expect(path).not_to have_permissions(permissions) - else - expect(path).to have_permissions(permissions) - end +Then( + /^(?:a|the) (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$/ +) do |path, permissions| + expect(path).to have_permissions(permissions) +end + +Then( + /^(?:a|the) (?:file|directory)(?: named)? "([^"]*)" should not have permissions "([^"]*)"$/ +) do |path, permissions| + expect(path).not_to have_permissions(permissions) end diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb index 98fe4dcfa..138e47d3f 100644 --- a/lib/aruba/cucumber/hooks.rb +++ b/lib/aruba/cucumber/hooks.rb @@ -9,7 +9,10 @@ Before do # ... so every change needs to be done later - prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR + prepend_environment_variable( + 'PATH', + aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR + ) set_environment_variable 'HOME', aruba.config.home_directory end diff --git a/lib/aruba/cucumber/testing_frameworks.rb b/lib/aruba/cucumber/testing_frameworks.rb index ed5f76938..5ab7cf1f4 100644 --- a/lib/aruba/cucumber/testing_frameworks.rb +++ b/lib/aruba/cucumber/testing_frameworks.rb @@ -78,7 +78,8 @@ end # Minitest -Then /^the tests(?:s)? should not(?: all)? pass(?: with (\d+) failures?)?$/ do |count_failures| +Then /^the tests(?:s)? should not(?: all)? pass(?: with (\d+) failures?)?$/ \ +do |count_failures| if count_failures.nil? step 'the output should not contain "0 errors"' else diff --git a/lib/aruba/event_bus.rb b/lib/aruba/event_bus.rb index ef18face6..cd3baf03f 100644 --- a/lib/aruba/event_bus.rb +++ b/lib/aruba/event_bus.rb @@ -33,7 +33,9 @@ def initialize(resolver) def register(event_ids, handler_object = nil, &handler_proc) handler = handler_proc || handler_object - fail ArgumentError, 'Please pass either an object#call or a handler block' if handler.nil? || !handler.respond_to?(:call) + if handler.nil? || !handler.respond_to?(:call) + raise ArgumentError, 'Please pass either an object#call or a handler block' + end Array(event_ids).flatten.each do |id| @handlers[ @@ -51,7 +53,7 @@ def register(event_ids, handler_object = nil, &handler_proc) # handler. # def notify(event) - fail NoEventError, 'Please pass an event object, not a class' if event.is_a?(Class) + raise NoEventError, 'Please pass an event object, not a class' if event.is_a?(Class) @handlers[event.class.to_s].each { |handler| handler.call(event) } end diff --git a/lib/aruba/event_bus/name_resolver.rb b/lib/aruba/event_bus/name_resolver.rb index a9a3a8bee..7fe0145af 100644 --- a/lib/aruba/event_bus/name_resolver.rb +++ b/lib/aruba/event_bus/name_resolver.rb @@ -18,7 +18,8 @@ def camel_case(underscored_name) def constantize(camel_cased_word) names = camel_cased_word.split('::') - # Trigger a built-in NameError exception including the ill-formed constant in the message. + # Trigger a built-in NameError exception including the ill-formed + # constant in the message. Object.const_get(camel_cased_word) if names.empty? # Remove the first blank element in case of '::ClassName' notation. @@ -118,7 +119,8 @@ def transform(default_namespace, event_id) class FailingResolver class << self def match?(event_id) - fail ArgumentError, %(Input type "#{event_id.class}" of event_id "#{event_id}" is invalid) + raise ArgumentError, + %(Input type "#{event_id.class}" of event_id "#{event_id}" is invalid) end def supports @@ -145,9 +147,10 @@ def initialize(default_namespace) def transform(event_id) resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id) - rescue => e + rescue StandardError => e types = @resolvers.map(&:supports).flatten.join(', ') - message = %(Transforming "#{event_id}" into an event class failed. Supported types are: #{types}. #{e.message}.) + message = "Transforming \"#{event_id}\" into an event class failed." \ + " Supported types are: #{types}. #{e.message}." raise EventNameResolveError, message, cause: e end end diff --git a/lib/aruba/events.rb b/lib/aruba/events.rb index 5ea34f9d5..123465195 100644 --- a/lib/aruba/events.rb +++ b/lib/aruba/events.rb @@ -4,7 +4,8 @@ module Aruba module Events # Basic event # - # This is not meant for direct use - BasicEvent.new - by users. It is inherited by normal events + # This is not meant for direct use - BasicEvent.new - by users. It is + # inherited by normal events # # @private class BasicEvent diff --git a/lib/aruba/in_config_wrapper.rb b/lib/aruba/in_config_wrapper.rb index bf4479c31..c4c6ac21f 100644 --- a/lib/aruba/in_config_wrapper.rb +++ b/lib/aruba/in_config_wrapper.rb @@ -15,8 +15,12 @@ def initialize(config) end def method_missing(name, *args) - fail ArgumentError, 'Options take no argument' if args.any? - fail UnknownOptionError, %(Option "#{name}" is unknown. Please use only earlier defined options) unless config.key? name + raise ArgumentError, 'Options take no argument' if args.any? + + unless config.key? name + raise UnknownOptionError, + %(Option "#{name}" is unknown. Please use only earlier defined options) + end config[name] end diff --git a/lib/aruba/initializer.rb b/lib/aruba/initializer.rb index 1b6b4bff4..9d3f7306a 100644 --- a/lib/aruba/initializer.rb +++ b/lib/aruba/initializer.rb @@ -23,7 +23,8 @@ def add_gem end content = if File.exist? file - file_ends_with_carriage_return = File.open(file, 'r').readlines.last.match(/.*\n$/) + file_ends_with_carriage_return = + File.open(file, 'r').readlines.last.match(/.*\n$/) prefix = file_ends_with_carriage_return ? '' : "\n" @@ -53,7 +54,8 @@ def match?(*) end def start(*) - fail ArgumentError, %(Unknown test framework. Please use one of :rspec, :cucumber or :minitest) + raise ArgumentError, + %(Unknown test framework. Please use one of :rspec, :cucumber or :minitest) end end end @@ -206,7 +208,7 @@ def call(test_framework) begin initializers.find { |i| i.match? test_framework }.start [], {} rescue ArgumentError => e - $stderr.puts e.message + warn e.message exit 0 end diff --git a/lib/aruba/matchers/base/base_matcher.rb b/lib/aruba/matchers/base/base_matcher.rb index ed37ac786..a82948910 100644 --- a/lib/aruba/matchers/base/base_matcher.rb +++ b/lib/aruba/matchers/base/base_matcher.rb @@ -70,14 +70,6 @@ def failure_message def failure_message_when_negated "expected #{description_of @actual} not to #{description}" end - - # @private - def self.has_default_failure_messages?(matcher) - matcher.method(:failure_message).owner == self && - matcher.method(:failure_message_when_negated).owner == self - rescue NameError - false - end end include DefaultFailureMessages diff --git a/lib/aruba/matchers/collection/include_an_object.rb b/lib/aruba/matchers/collection/include_an_object.rb index b5e01bdf1..286c8e755 100644 --- a/lib/aruba/matchers/collection/include_an_object.rb +++ b/lib/aruba/matchers/collection/include_an_object.rb @@ -29,9 +29,7 @@ def initialize(matcher) # @api private # @return [String] def failure_message - unless iterable? - return "#{improve_hash_formatting(super)}, but was not iterable" - end + return "#{improve_hash_formatting(super)}, but was not iterable" unless iterable? return failed_objects.first if failed_objects.size == 1 @@ -91,7 +89,9 @@ def index_objects def failure_message_for_item(index, failure_message) failure_message = indent_multiline_message(add_new_line_if_needed(failure_message)) - indent_multiline_message("object at index #{index} failed to match:#{failure_message}") + indent_multiline_message( + "object at index #{index} failed to match:#{failure_message}" + ) end def add_new_line_if_needed(message) diff --git a/lib/aruba/matchers/command/be_successfully_executed.rb b/lib/aruba/matchers/command/be_successfully_executed.rb index 2f04b99d6..862f3f485 100644 --- a/lib/aruba/matchers/command/be_successfully_executed.rb +++ b/lib/aruba/matchers/command/be_successfully_executed.rb @@ -29,7 +29,9 @@ end failure_message do |_actual| - "Expected `#{@actual}` to succeed but got non-zero exit status and the following output:\n\n#{@old_actual.output}\n" + "Expected `#{@actual}` to succeed" \ + ' but got non-zero exit status and the following output:' \ + "\n\n#{@old_actual.output}\n" end end diff --git a/lib/aruba/matchers/command/have_exit_status.rb b/lib/aruba/matchers/command/have_exit_status.rb index 4b667fe8d..461c14af8 100644 --- a/lib/aruba/matchers/command/have_exit_status.rb +++ b/lib/aruba/matchers/command/have_exit_status.rb @@ -23,7 +23,9 @@ @old_actual.stop @actual = actual.exit_status - raise "Expected #{@old_actual} to respond to #exit_status" unless @old_actual.respond_to? :exit_status + unless @old_actual.respond_to? :exit_status + raise "Expected #{@old_actual} to respond to #exit_status" + end values_match? expected, @actual end diff --git a/lib/aruba/matchers/command/have_finished_in_time.rb b/lib/aruba/matchers/command/have_finished_in_time.rb index 9bd2d8276..3ffe04749 100644 --- a/lib/aruba/matchers/command/have_finished_in_time.rb +++ b/lib/aruba/matchers/command/have_finished_in_time.rb @@ -24,7 +24,9 @@ @old_actual = actual @actual = @old_actual.commandline - raise "Expected #{@old_actual} to respond to #timed_out?" unless @old_actual.respond_to? :timed_out? + unless @old_actual.respond_to? :timed_out? + raise "Expected #{@old_actual} to respond to #timed_out?" + end @old_actual.stop diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index fd62da7a3..ed786409f 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -19,7 +19,9 @@ match do |actual| @old_actual = actual - raise "Expected #{@old_actual} to respond to #output" unless @old_actual.respond_to? :output + unless @old_actual.respond_to? :output + raise "Expected #{@old_actual} to respond to #output" + end @old_actual.stop diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb index 991fe37c9..955808bfa 100644 --- a/lib/aruba/matchers/command/have_output_on_stderr.rb +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -17,7 +17,9 @@ match do |actual| @old_actual = actual - raise "Expected #{@old_actual} to respond to #stderr" unless @old_actual.respond_to? :stderr + unless @old_actual.respond_to? :stderr + raise "Expected #{@old_actual} to respond to #stderr" + end @old_actual.stop diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index 5018fc94e..30c6206b9 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -17,7 +17,9 @@ match do |actual| @old_actual = actual - raise "Expected #{@old_actual} to respond to #stdout" unless @old_actual.respond_to? :stdout + unless @old_actual.respond_to? :stdout + raise "Expected #{@old_actual} to respond to #stdout" + end @old_actual.stop diff --git a/lib/aruba/matchers/directory/have_sub_directory.rb b/lib/aruba/matchers/directory/have_sub_directory.rb index d367136b6..05000f771 100644 --- a/lib/aruba/matchers/directory/have_sub_directory.rb +++ b/lib/aruba/matchers/directory/have_sub_directory.rb @@ -23,7 +23,8 @@ # # RSpec.describe do # it { expect('dir1.d').to have_sub_directory(['subdir.1.d', 'subdir.2.d']) } -# it { expect(directories).to include a_directory_with_sub_directory(['subdir.1.d', 'subdir.2.d']) } +# it { expect(directories) +# . to include a_directory_with_sub_directory(['subdir.1.d', 'subdir.2.d']) } # end RSpec::Matchers.define :have_sub_directory do |expected| match do |actual| @@ -40,11 +41,15 @@ diffable failure_message do |actual| - format('expected that directory "%s" has the following sub-directories: %s.', actual.join(', '), expected) + format('expected that directory "%s" has the following sub-directories: %s.', + actual.join(', '), + expected) end failure_message_when_negated do |actual| - format('expected that directory "%s" does not have the following sub-directories: %s.', actual.join(', '), expected) + format('expected that directory "%s" does not have the following sub-directories: %s.', + actual.join(', '), + expected) end end diff --git a/lib/aruba/matchers/file/have_file_size.rb b/lib/aruba/matchers/file/have_file_size.rb index c26a9570d..a5d11fb0d 100644 --- a/lib/aruba/matchers/file/have_file_size.rb +++ b/lib/aruba/matchers/file/have_file_size.rb @@ -34,11 +34,13 @@ end failure_message do |_actual| - format('expected that file "%s" has size "%s", but has "%s"', @old_actual, @actual, @expected) + format('expected that file "%s" has size "%s", but has "%s"', + @old_actual, @actual, @expected) end failure_message_when_negated do |_actual| - format('expected that file "%s" does not have size "%s", but has "%s"', @old_actual, @actual, @expected) + format('expected that file "%s" does not have size "%s", but has "%s"', + @old_actual, @actual, @expected) end end diff --git a/lib/aruba/matchers/path/have_permissions.rb b/lib/aruba/matchers/path/have_permissions.rb index 0a3edad5e..1ff4bb7d1 100644 --- a/lib/aruba/matchers/path/have_permissions.rb +++ b/lib/aruba/matchers/path/have_permissions.rb @@ -51,11 +51,13 @@ def permissions(file) end failure_message do |_actual| - format('expected that path "%s" has permissions "%s", but has "%s".', @old_actual, @expected, @actual) + format('expected that path "%s" has permissions "%s", but has "%s".', + @old_actual, @expected, @actual) end failure_message_when_negated do |_actual| - format('expected that path "%s" does not have permissions "%s", but has "%s".', @old_actual, @expected, @actual) + format('expected that path "%s" does not have permissions "%s", but has "%s".', + @old_actual, @expected, @actual) end end diff --git a/lib/aruba/platforms/announcer.rb b/lib/aruba/platforms/announcer.rb index 5349ce5c8..03eb4c5d8 100644 --- a/lib/aruba/platforms/announcer.rb +++ b/lib/aruba/platforms/announcer.rb @@ -21,7 +21,9 @@ module Platforms # # before do # current_example = context.example - # aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel] + # if current_example.metadata[:announce_my_channel] + # aruba.announcer.activate :my_channel + # end # end # # Aruba.announcer.announce(:my_channel, 'my message') @@ -80,16 +82,26 @@ def initialize def after_init output_format :changed_configuration, proc { |n, v| format('# %s = %s', n, v) } - output_format :changed_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } + output_format :changed_environment, + proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } output_format :command, '$ %s' output_format :directory, '$ cd %s' - output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } - output_format :full_environment, proc { |h| format("<<-ENVIRONMENT\n%s\nENVIRONMENT", Aruba.platform.simple_table(h)) } - output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } + output_format :environment, + proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } + output_format :full_environment, + proc { |h| + format("<<-ENVIRONMENT\n%s\nENVIRONMENT", + Aruba.platform.simple_table(h)) + } + output_format :modified_environment, + proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } output_format :stderr, "<<-STDERR\n%s\nSTDERR" output_format :stdout, "<<-STDOUT\n%s\nSTDOUT" output_format :command_content, "<<-COMMAND\n%s\nCOMMAND" - output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) } + output_format :stop_signal, + proc { |p, s| + format('Command will be stopped with `kill -%s %s`', s, p) + } output_format :timeout, '# %s-timeout: %s seconds' output_format :wait_time, '# %s: %s seconds' output_format :command_filesystem_status, diff --git a/lib/aruba/platforms/aruba_file_creator.rb b/lib/aruba/platforms/aruba_file_creator.rb index d7377e2b9..845e2b532 100644 --- a/lib/aruba/platforms/aruba_file_creator.rb +++ b/lib/aruba/platforms/aruba_file_creator.rb @@ -18,7 +18,9 @@ class ArubaFileCreator # @param [Boolean] check_presence (false) # Check if file exist def call(path, content, check_presence = false) - fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path) + if check_presence && !Aruba.platform.file?(path) + raise "Expected #{path} to be present" + end Aruba.platform.mkdir(File.dirname(path)) diff --git a/lib/aruba/platforms/aruba_fixed_size_file_creator.rb b/lib/aruba/platforms/aruba_fixed_size_file_creator.rb index be7e11f04..c76b195ac 100644 --- a/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +++ b/lib/aruba/platforms/aruba_fixed_size_file_creator.rb @@ -22,11 +22,16 @@ class ArubaFixedSizeFileCreator # @param [Boolean] check_presence (false) # Check if file exist def call(path, size, check_presence) - fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path) + if check_presence && !Aruba.platform.file?(path) + raise "Expected #{path} to be present" + end Aruba.platform.mkdir(File.dirname(path)) - File.open(path, 'wb') { |f| f.seek(size - 1); f.write("\0") } + File.open(path, 'wb') do |f| + f.seek(size - 1) + f.write("\0") + end self end diff --git a/lib/aruba/platforms/command_monitor.rb b/lib/aruba/platforms/command_monitor.rb index 32cc4899f..336af09a9 100644 --- a/lib/aruba/platforms/command_monitor.rb +++ b/lib/aruba/platforms/command_monitor.rb @@ -20,7 +20,7 @@ def nil? end def method_missing(*) - fail NoCommandHasBeenStoppedError, 'No last command stopped available' + raise NoCommandHasBeenStoppedError, 'No last command stopped available' end def respond_to_missing?(*) @@ -34,7 +34,7 @@ def nil? end def method_missing(*) - fail NoCommandHasBeenStartedError, 'No last command started available' + raise NoCommandHasBeenStartedError, 'No last command started available' end def respond_to_missing?(*) @@ -78,7 +78,7 @@ def find(cmd) cmd = cmd.commandline if cmd.respond_to? :commandline command = registered_commands.reverse.find { |c| c.commandline == cmd } - fail CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil? + raise CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil? command end diff --git a/lib/aruba/platforms/unix_environment_variables.rb b/lib/aruba/platforms/unix_environment_variables.rb index 7f6820d78..5843a2b10 100644 --- a/lib/aruba/platforms/unix_environment_variables.rb +++ b/lib/aruba/platforms/unix_environment_variables.rb @@ -11,9 +11,7 @@ class UpdateAction def initialize(other_env, &block) @other_env = other_env.to_h.each_with_object({}) { |(k, v), a| a[k] = v.to_s } - @block = if block_given? - block - end + @block = (block if block_given?) end def call(env) diff --git a/lib/aruba/platforms/unix_which.rb b/lib/aruba/platforms/unix_which.rb index 01c657f1e..65f7092f6 100644 --- a/lib/aruba/platforms/unix_which.rb +++ b/lib/aruba/platforms/unix_which.rb @@ -13,7 +13,7 @@ def self.match?(*) end def call(program, path) - fail %(Invalid input program "#{program}" and/or path "#{path}".) + raise %(Invalid input program "#{program}" and/or path "#{path}".) end end diff --git a/lib/aruba/platforms/windows_environment_variables.rb b/lib/aruba/platforms/windows_environment_variables.rb index cc1655181..de3d4084d 100644 --- a/lib/aruba/platforms/windows_environment_variables.rb +++ b/lib/aruba/platforms/windows_environment_variables.rb @@ -16,7 +16,8 @@ module Platforms # C:>set PATH # C:>Path=.;.\bin;c:\rubys\ruby-2.1.6-p336\bin; # - # @example If you access environment variables through ENV, you can access values no matter the case of the key: + # @example If you access environment variables through ENV, you can access + # values no matter the case of the key: # ENV["Path"] # => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;" # ENV["PATH"] # => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;" # diff --git a/lib/aruba/platforms/windows_which.rb b/lib/aruba/platforms/windows_which.rb index 78478bd87..3b342a907 100644 --- a/lib/aruba/platforms/windows_which.rb +++ b/lib/aruba/platforms/windows_which.rb @@ -13,7 +13,7 @@ def self.match?(*) end def call(program, path) - fail %(Invalid input program "#{program}" and/or path "#{path}".) + raise %(Invalid input program "#{program}" and/or path "#{path}".) end end @@ -96,7 +96,11 @@ def call(program, path = ENV['PATH']) private def windows_executable_extentions - ENV['PATHEXT'] ? format('.{%s}', ENV['PATHEXT'].tr(';', ',').tr('.', '')).downcase : '.{exe,com,bat}' + if ENV['PATHEXT'] + format('.{%s}', ENV['PATHEXT'].tr(';', ',').tr('.', '')).downcase + else + '.{exe,com,bat}' + end end end end diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index e96a9c9fb..e1d2f1eec 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -41,7 +41,8 @@ def stdin(*); end # @return [String] # A predefined string to make users aware they are using the DebugProcess def stdout(*) - 'This is the debug launcher on STDOUT. If this output is unexpected, please check your setup.' + 'This is the debug launcher on STDOUT.' \ + ' If this output is unexpected, please check your setup.' end # Return stderr @@ -49,7 +50,8 @@ def stdout(*) # @return [String] # A predefined string to make users aware they are using the DebugProcess def stderr(*) - 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.' + 'This is the debug launcher on STDERR.' \ + ' If this output is unexpected, please check your setup.' end # Write to nothing diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 3d0fae2c5..3042c31a7 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -61,7 +61,7 @@ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, # Start command def start - fail 'You need to call aruba.config.main_class = YourMainClass' unless main_class + raise 'You need to call aruba.config.main_class = YourMainClass' unless main_class @started = true @@ -109,7 +109,9 @@ def write(input) # Close io def close_io(name) - fail ArgumentError, 'Only stdin stdout and stderr are allowed to close' unless [:stdin, :stdout, :stderr].include? name + unless [:stdin, :stdout, :stderr].include? name + raise ArgumentError, 'Only stdin stdout and stderr are allowed to close' + end get_instance_variable(name.to_sym).close end diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index b3149acd1..0f18e9e68 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -65,9 +65,11 @@ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, # def start if started? - error_message = "Command \"#{commandline}\" has already been started." \ - ' Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.' - fail CommandAlreadyStartedError, error_message + error_message = + "Command \"#{commandline}\" has already been started." \ + ' Please `#stop` the command first and `#start` it again.' \ + ' Alternatively use `#restart`.' + raise CommandAlreadyStartedError, error_message end @started = true @@ -232,7 +234,7 @@ def pid # The signal, i.e. 'TERM' def send_signal(signal) error_message = %(Command "#{commandline}" with PID "#{pid}" has already stopped.) - fail CommandAlreadyStoppedError, error_message if @process.exited? + raise CommandAlreadyStoppedError, error_message if @process.exited? Process.kill signal, pid rescue Errno::ESRCH @@ -263,7 +265,10 @@ def interactive? private def command_string - fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if command_path.nil? + if command_path.nil? + raise LaunchError, + %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) + end Aruba.platform.command_string.new(command_path, *arguments) end diff --git a/lib/aruba/rspec.rb b/lib/aruba/rspec.rb index eaed6c868..7c8bd864b 100644 --- a/lib/aruba/rspec.rb +++ b/lib/aruba/rspec.rb @@ -13,8 +13,10 @@ setup_aruba # Modify PATH to include project/bin - prepend_environment_variable 'PATH', - aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR + prepend_environment_variable( + 'PATH', + aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR + ) # Use configured home directory as HOME set_environment_variable 'HOME', aruba.config.home_directory @@ -47,19 +49,27 @@ config.before :each do |example| next unless self.class.include?(Aruba::Api) - aruba.announcer.activate(:full_environment) if example.metadata[:announce_full_environment] - aruba.announcer.activate(:changed_environment) if example.metadata[:announce_changed_environment] - - aruba.announcer.activate(:command) if example.metadata[:announce_command] - aruba.announcer.activate(:directory) if example.metadata[:announce_directory] - aruba.announcer.activate(:full_environment) if example.metadata[:announce_full_environment] - aruba.announcer.activate(:stderr) if example.metadata[:announce_stderr] - aruba.announcer.activate(:stdout) if example.metadata[:announce_stdout] - aruba.announcer.activate(:stop_signal) if example.metadata[:announce_stop_signal] - aruba.announcer.activate(:timeout) if example.metadata[:announce_timeout] - aruba.announcer.activate(:wait_time) if example.metadata[:announce_wait_time] - aruba.announcer.activate(:command_content) if example.metadata[:announce_command_content] - aruba.announcer.activate(:command_filesystem_status) if example.metadata[:announce_command_filesystem_status] + if example.metadata[:announce_full_environment] + aruba.announcer.activate(:full_environment) + end + if example.metadata[:announce_changed_environment] + aruba.announcer.activate(:changed_environment) + end + + aruba.announcer.activate(:command) if example.metadata[:announce_command] + aruba.announcer.activate(:directory) if example.metadata[:announce_directory] + if example.metadata[:announce_full_environment] + aruba.announcer.activate(:full_environment) + end + aruba.announcer.activate(:stderr) if example.metadata[:announce_stderr] + aruba.announcer.activate(:stdout) if example.metadata[:announce_stdout] + aruba.announcer.activate(:stop_signal) if example.metadata[:announce_stop_signal] + aruba.announcer.activate(:timeout) if example.metadata[:announce_timeout] + aruba.announcer.activate(:wait_time) if example.metadata[:announce_wait_time] + aruba.announcer.activate(:command_content) if example.metadata[:announce_command_content] + if example.metadata[:announce_command_filesystem_status] + aruba.announcer.activate(:command_filesystem_status) + end if example.metadata[:announce_output] aruba.announcer.activate(:stderr) diff --git a/lib/aruba/runtime.rb b/lib/aruba/runtime.rb index 42d90b24a..68c28270f 100644 --- a/lib/aruba/runtime.rb +++ b/lib/aruba/runtime.rb @@ -42,14 +42,16 @@ class Runtime def initialize(opts = {}) @event_bus = EventBus.new(EventBus::NameResolver.new(Aruba::Events)) @announcer = opts.fetch(:announcer, Aruba.platform.announcer.new) - @config = opts.fetch(:config, ConfigWrapper.new(Aruba.config.make_copy, @event_bus)) + @config = opts.fetch(:config, + ConfigWrapper.new(Aruba.config.make_copy, @event_bus)) @environment = opts.fetch(:environment, Aruba.platform.environment_variables.new) @current_directory = ArubaPath.new(@config.working_directory) @root_directory = ArubaPath.new(@config.root_directory) @environment.update(@config.command_runtime_environment) - @command_monitor = opts.fetch(:command_monitor, Aruba.platform.command_monitor.new(announcer: @announcer)) + @command_monitor = opts.fetch(:command_monitor, + Aruba.platform.command_monitor.new(announcer: @announcer)) @logger = opts.fetch(:logger, Aruba.platform.logger.new) @logger.mode = @config.log_level @@ -81,12 +83,17 @@ def fixtures_directory candidates = config.fixtures_directories.map { |dir| File.join(root_directory, dir) } directory = candidates.find { |d| Aruba.platform.directory? d } - fail "No existing fixtures directory found in #{candidates.map { |d| format('"%s"', d) }.join(', ')}." unless directory + unless directory + canditates_display = candidates.map { |d| format('"%s"', d) }.join(', ') + raise "No existing fixtures directory found in #{canditates_display}." + end directory end - fail %(Fixtures directory "#{@fixtures_directory}" is not a directory) unless Aruba.platform.directory?(@fixtures_directory) + unless Aruba.platform.directory?(@fixtures_directory) + raise %(Fixtures directory "#{@fixtures_directory}" is not a directory) + end ArubaPath.new(@fixtures_directory) end diff --git a/lib/aruba/setup.rb b/lib/aruba/setup.rb index 258d7fe11..4204008a3 100644 --- a/lib/aruba/setup.rb +++ b/lib/aruba/setup.rb @@ -25,9 +25,12 @@ def call(clobber = true) def working_directory(clobber = true) if clobber - Aruba.platform.rm File.join(runtime.config.root_directory, runtime.config.working_directory), force: true + Aruba.platform.rm File.join(runtime.config.root_directory, + runtime.config.working_directory), + force: true end - Aruba.platform.mkdir File.join(runtime.config.root_directory, runtime.config.working_directory) + Aruba.platform.mkdir File.join(runtime.config.root_directory, + runtime.config.working_directory) Aruba.platform.chdir runtime.config.root_directory end @@ -38,7 +41,8 @@ def events runtime.announcer.announce(:command) { event.entity.commandline } runtime.announcer.announce(:timeout, 'exit') { event.entity.exit_timeout } runtime.announcer.announce(:timeout, 'io wait') { event.entity.io_wait_timeout } - runtime.announcer.announce(:wait_time, 'startup wait time') { event.entity.startup_wait_time } + runtime.announcer + .announce(:wait_time, 'startup wait time') { event.entity.startup_wait_time } runtime.announcer.announce(:full_environment) { event.entity.environment } end ) @@ -57,7 +61,8 @@ def events runtime.announcer.announce(:stdout) { event.entity.stdout } runtime.announcer.announce(:stderr) { event.entity.stderr } runtime.announcer.announce(:command_content) { event.entity.content } - runtime.announcer.announce(:command_filesystem_status) { event.entity.filesystem_status } + runtime.announcer + .announce(:command_filesystem_status) { event.entity.filesystem_status } end ) @@ -69,10 +74,16 @@ def events ) runtime.event_bus.register( - [:changed_environment_variable, :added_environment_variable, :deleted_environment_variable], + [:changed_environment_variable, + :added_environment_variable, + :deleted_environment_variable], proc do |event| - runtime.announcer.announce :changed_environment, event.entity[:changed][:name], event.entity[:changed][:value] - runtime.announcer.announce :environment, event.entity[:changed][:name], event.entity[:changed][:value] + runtime.announcer.announce :changed_environment, + event.entity[:changed][:name], + event.entity[:changed][:value] + runtime.announcer.announce :environment, + event.entity[:changed][:name], + event.entity[:changed][:value] end ) @@ -83,7 +94,11 @@ def events runtime.event_bus.register( :changed_configuration, - proc { |event| runtime.announcer.announce :configuration, event.entity[:changed][:name], event.entity[:changed][:value] } + proc { |event| + runtime.announcer.announce :configuration, + event.entity[:changed][:name], + event.entity[:changed][:value] + } ) end end diff --git a/spec/aruba/api/core_spec.rb b/spec/aruba/api/core_spec.rb index 903e2398f..262d2ebb3 100644 --- a/spec/aruba/api/core_spec.rb +++ b/spec/aruba/api/core_spec.rb @@ -89,9 +89,8 @@ it 'warns about it' do @aruba.expand_path(@file_path) - expect(logger).to have_received(:warn).with( - /Aruba's `expand_path` method was called with an absolute path at .*:\d+, which is not recommended/ - ) + expect(logger).to have_received(:warn) + .with(/Aruba's `expand_path` method was called with an absolute path/) end it 'does not warn about it if told not to' do @@ -106,7 +105,10 @@ end context 'when path contains ".."' do - it { expect(@aruba.expand_path('path/..')).to eq File.expand_path(File.join(aruba.current_directory)) } + it { + expect(@aruba.expand_path('path/..')) + .to eq File.expand_path(File.join(aruba.current_directory)) + } end context 'when path is nil' do diff --git a/spec/aruba/api/filesystem_spec.rb b/spec/aruba/api/filesystem_spec.rb index 5c38606e5..30c2e1bef 100644 --- a/spec/aruba/api/filesystem_spec.rb +++ b/spec/aruba/api/filesystem_spec.rb @@ -151,7 +151,9 @@ context 'and multiple file names are given' do let(:name) { %w(file1 file2 file3) } - let(:path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } } + let(:path) do + %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } + end it_behaves_like 'an existing file' end end @@ -398,7 +400,10 @@ before(:each) { create_test_files(destination) } - it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, error_message } + it 'raises an appropriate error' do + expect { @aruba.copy source, destination } + .to raise_error ArgumentError, error_message + end end context 'when a source is the same like destination' do @@ -409,7 +414,8 @@ it 'raises an appropriate error' do src_path = File.expand_path(File.join(@aruba.aruba.current_directory, source)) - dest_path = File.expand_path(File.join(@aruba.aruba.current_directory, destination)) + dest_path = File.expand_path(File.join(@aruba.aruba.current_directory, + destination)) expected_message = %(same file: #{src_path} and #{dest_path}) expect { @aruba.copy source, destination } .to raise_error ArgumentError, expected_message @@ -419,9 +425,14 @@ context 'when a fixture is destination' do let(:source) { '%/copy/file.txt' } let(:destination) { '%/copy/file.txt' } - let(:error_message) { "Using a fixture as destination (#{destination}) is not supported" } + let(:error_message) do + "Using a fixture as destination (#{destination}) is not supported" + end - it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, error_message } + it 'raises an appropriate error' do + expect { @aruba.copy source, destination } + .to raise_error ArgumentError, error_message + end end end end @@ -533,7 +544,7 @@ def actual_permissions end . not_to raise_error end - it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do + it "raises ExpectationNotMetError when the inner expectations don't match" do expect do @aruba.with_file_content @file_name do |full_content| expect(full_content).to match(/zoo/) diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index e7da9ae15..002e730a4 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -13,7 +13,8 @@ context 'enabled' do before :each do @aruba.aruba.announcer = instance_double 'Aruba::Platforms::Announcer' - expect(@aruba.aruba.announcer).to receive(:announce).with(:stdout) { "hello world\n" } + expect(@aruba.aruba.announcer) + .to receive(:announce).with(:stdout) { "hello world\n" } allow(@aruba.aruba.announcer).to receive(:announce) end diff --git a/spec/aruba/hooks_spec.rb b/spec/aruba/hooks_spec.rb index c8db095ed..a56137f4f 100644 --- a/spec/aruba/hooks_spec.rb +++ b/spec/aruba/hooks_spec.rb @@ -3,14 +3,14 @@ describe Aruba::Hooks do it 'executes a stored hook' do hook_was_run = false - subject.append :hook_label, lambda { hook_was_run = true } + subject.append :hook_label, -> { hook_was_run = true } subject.execute :hook_label, self expect(hook_was_run).to be_truthy end it 'executes a stored hook that takes multiple arguments' do hook_values = [] - subject.append :hook_label, lambda { |a, b, c| hook_values = [a, b, c] } + subject.append :hook_label, ->(a, b, c) { hook_values = [a, b, c] } subject.execute :hook_label, self, 1, 2, 3 expect(hook_values).to eq [1, 2, 3] end diff --git a/spec/aruba/in_config_wrapper_spec.rb b/spec/aruba/in_config_wrapper_spec.rb index fe38492d7..9161b1a19 100644 --- a/spec/aruba/in_config_wrapper_spec.rb +++ b/spec/aruba/in_config_wrapper_spec.rb @@ -15,11 +15,18 @@ end context 'when one tries to pass arguments to option' do - it { expect { wrapper.opt('arg') }.to raise_error ArgumentError, 'Options take no argument' } + it { + expect { wrapper.opt('arg') } + .to raise_error ArgumentError, 'Options take no argument' + } end end context 'when option is not defined' do - it { expect { wrapper.opt }.to raise_error ArgumentError, 'Option "opt" is unknown. Please use only earlier defined options' } + it 'raises an error' do + expect { wrapper.opt } + .to raise_error ArgumentError, + 'Option "opt" is unknown. Please use only earlier defined options' + end end end diff --git a/spec/aruba/matchers/collection_spec.rb b/spec/aruba/matchers/collection_spec.rb index 61980e64e..fdb1b7b07 100644 --- a/spec/aruba/matchers/collection_spec.rb +++ b/spec/aruba/matchers/collection_spec.rb @@ -41,10 +41,10 @@ context 'when succeeding with compound matchers' do describe [1, 'anything', 'something'] do - it { is_expected.to include_an_object(be_a(String).and include('thing')) } - it { is_expected.to include_an_object(be_a(String).and end_with('g')) } - it { is_expected.to include_an_object(start_with('q').or include('y')) } - it { is_expected.not_to include_an_object(start_with('b').or include('b')) } + it { is_expected.to include_an_object(be_a(String).and(include('thing'))) } + it { is_expected.to include_an_object(be_a(String).and(end_with('g'))) } + it { is_expected.to include_an_object(start_with('q').or(include('y'))) } + it { is_expected.not_to include_an_object(start_with('b').or(include('b'))) } end end end diff --git a/spec/aruba/matchers/file_spec.rb b/spec/aruba/matchers/file_spec.rb index 2026efcf7..eab25e52e 100644 --- a/spec/aruba/matchers/file_spec.rb +++ b/spec/aruba/matchers/file_spec.rb @@ -75,8 +75,9 @@ it { expect(have_file_content(/a/).description).to eq('have file content: /a/') } end - context 'when matcher' do - it { expect(have_file_content(a_string_starting_with('a')).description).to eq('have file content: a string starting with "a"') } + it 'is correct when using a matcher' do + expect(have_file_content(a_string_starting_with('a')).description) + .to eq('have file content: a string starting with "a"') end end @@ -98,9 +99,10 @@ def fail_with(message) end example 'for a matcher' do - expect do - expect(@file_name).to have_file_content(a_string_starting_with('z')) - end.to fail_with('expected "test.txt" to have file content: a string starting with "z"') + expect { expect(@file_name).to have_file_content(a_string_starting_with('z')) } + .to fail_with( + 'expected "test.txt" to have file content: a string starting with "z"' + ) end end end diff --git a/spec/aruba/matchers/path_spec.rb b/spec/aruba/matchers/path_spec.rb index d0449f3de..367c49418 100644 --- a/spec/aruba/matchers/path_spec.rb +++ b/spec/aruba/matchers/path_spec.rb @@ -75,7 +75,7 @@ def expand_path(*args) end context 'when file exists' do - context 'and should have permissions' do + context 'and should have the same permissions' do context 'and permissions are given as string' do it { expect(file_name).to have_permissions permissions } end @@ -94,7 +94,7 @@ def expand_path(*args) it { expect(file_name).to have_permissions permissions } end - context 'but fails because the permissions are different' do + context 'but the permissions are different' do let(:expected_permissions) { 0o666 } it do @@ -104,14 +104,14 @@ def expand_path(*args) end end - context 'and should not have permissions' do - context 'and succeeds when the difference is expected and permissions are different' do + context 'and should not have the same permissions' do + context 'and permissions are different' do let(:different_permissions) { 0o666 } it { expect(file_name).not_to have_permissions different_permissions } end - context 'and fails because the permissions are the same although they should be different' do + context 'but permissions are the same' do let(:different_permissions) { 0o644 } it do diff --git a/spec/aruba/platform/windows_environment_variables_spec.rb b/spec/aruba/platform/windows_environment_variables_spec.rb index 918525017..82ab1a526 100644 --- a/spec/aruba/platform/windows_environment_variables_spec.rb +++ b/spec/aruba/platform/windows_environment_variables_spec.rb @@ -116,9 +116,7 @@ let(:variable) { 'unknown' } context 'and no default is given' do - unless defined? KeyError - class KeyError < StandardError; end - end + class KeyError < StandardError; end unless defined? KeyError it { expect { environment.fetch(variable) }.to raise_error KeyError } end @@ -156,9 +154,7 @@ class KeyError < StandardError; end let(:variable) { 'unknown' } context 'and no default is given' do - unless defined? KeyError - class KeyError < StandardError; end - end + class KeyError < StandardError; end unless defined? KeyError it { expect { environment.fetch(variable) }.to raise_error KeyError } end @@ -196,9 +192,7 @@ class KeyError < StandardError; end let(:variable) { 'unknown' } context 'and no default is given' do - unless defined? KeyError - class KeyError < StandardError; end - end + class KeyError < StandardError; end unless defined? KeyError it { expect { environment.fetch(variable) }.to raise_error KeyError } end diff --git a/spec/aruba/platforms/windows_command_string_spec.rb b/spec/aruba/platforms/windows_command_string_spec.rb index 88141d0a0..92ee71266 100644 --- a/spec/aruba/platforms/windows_command_string_spec.rb +++ b/spec/aruba/platforms/windows_command_string_spec.rb @@ -23,7 +23,10 @@ context 'with a command and arguments' do let(:base_command) { 'C:\Foo\Bar' } let(:arguments) { ['-w', 'baz quux'] } - it { expect(command_string.to_a).to eq [cmd_path, '/c', "#{base_command} -w \"baz quux\""] } + it { + expect(command_string.to_a) + .to eq [cmd_path, '/c', "#{base_command} -w \"baz quux\""] + } end end end diff --git a/spec/aruba/processes/basic_process_spec.rb b/spec/aruba/processes/basic_process_spec.rb index a10e7da13..a73ea86e3 100644 --- a/spec/aruba/processes/basic_process_spec.rb +++ b/spec/aruba/processes/basic_process_spec.rb @@ -28,7 +28,7 @@ def stderr(*_args) describe '#inspect' do it 'it shows useful info' do - expected = /#<#:\d+ commandline="foobar": stdout="foo output" stderr="foo error output"/ + expected = /commandline="foobar": stdout="foo output" stderr="foo error output"/ expect(subject.inspect).to match(expected) end @@ -36,7 +36,7 @@ def stderr(*_args) let(:stdout) { nil } it 'it shows useful info' do - expected = /#<#:\d+ commandline="foobar": stdout=nil stderr="foo error output"/ + expected = /commandline="foobar": stdout=nil stderr="foo error output"/ expect(subject.inspect).to match(expected) end end @@ -45,7 +45,7 @@ def stderr(*_args) let(:stderr) { nil } it 'it shows useful info' do - expected = /#<#:\d+ commandline="foobar": stdout="foo output" stderr=nil/ + expected = /commandline="foobar": stdout="foo output" stderr=nil/ expect(subject.inspect).to match(expected) end end @@ -55,7 +55,7 @@ def stderr(*_args) let(:stdout) { nil } it 'it shows useful info' do - expected = /#<#:\d+ commandline="foobar": stdout=nil stderr=nil/ + expected = /commandline="foobar": stdout=nil stderr=nil/ expect(subject.inspect).to match(expected) end end diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index efc1aa37b..9b2df4a89 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -1,7 +1,9 @@ require 'spec_helper' RSpec.describe Aruba::Processes::SpawnProcess do - subject(:process) { described_class.new(command_line, exit_timeout, io_wait, working_directory) } + subject(:process) do + described_class.new(command_line, exit_timeout, io_wait, working_directory) + end let(:command_line) { 'echo "yo"' } let(:exit_timeout) { 30 } @@ -76,8 +78,10 @@ let(:command_path) { '/bar/foo' } before do - allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString - allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(Aruba.platform).to receive(:command_string) + .and_return Aruba::Platforms::UnixCommandString + allow(Aruba.platform) + .to receive(:which).with(command, anything).and_return(command_path) allow(ChildProcess).to receive(:build).and_return(child) allow(child).to receive(:io).and_return(io) @@ -99,8 +103,10 @@ let(:command_path) { '/path with space/foo' } before do - allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString - allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(Aruba.platform).to receive(:command_string) + .and_return Aruba::Platforms::UnixCommandString + allow(Aruba.platform) + .to receive(:which).with(command, anything).and_return(command_path) allow(ChildProcess).to receive(:build).with(command_path).and_return(child) allow(child).to receive(:io).and_return io allow(child).to receive(:environment).and_return({}) @@ -132,9 +138,11 @@ let(:command_path) { 'D:\Foo\foo' } before do - allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::WindowsCommandString + allow(Aruba.platform).to receive(:command_string) + .and_return Aruba::Platforms::WindowsCommandString allow(Aruba.platform).to receive(:which).with('cmd.exe').and_return(cmd_path) - allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(Aruba.platform) + .to receive(:which).with(command, anything).and_return(command_path) allow(ChildProcess).to receive(:build).and_return(child) allow(child).to receive(:io).and_return(io) @@ -164,14 +172,15 @@ it 'escapes the spaces using excessive double quotes' do process.start - expect(ChildProcess).to have_received(:build).with(cmd_path, '/c', 'D:\Bar""" """Baz\foo') + expect(ChildProcess) + .to have_received(:build).with(cmd_path, '/c', 'D:\Bar""" """Baz\foo') end end context 'with a command with arguments' do let(:command_line) { "foo -x 'bar \"baz\"'" } - it 'passes the command and arguments as one string to ChildProcess.build, with escaped quotes' do + it 'passes the command and arguments as one string with escaped quotes' do process.start expect(ChildProcess).to have_received(:build) .with(cmd_path, '/c', "#{command_path} -x \"bar \"\"\"baz\"\"\"\"") diff --git a/spec/aruba/rspec_spec.rb b/spec/aruba/rspec_spec.rb index b36c3845b..59756987a 100644 --- a/spec/aruba/rspec_spec.rb +++ b/spec/aruba/rspec_spec.rb @@ -19,7 +19,8 @@ end it 'includes configured command search paths in PATH' do - expect(ENV['PATH']).to include aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + expect(ENV['PATH']) + .to include aruba.config.command_search_paths.join(File::PATH_SEPARATOR) end end end diff --git a/spec/event_bus/name_resolver_spec.rb b/spec/event_bus/name_resolver_spec.rb index b24063da6..cf2e53828 100644 --- a/spec/event_bus/name_resolver_spec.rb +++ b/spec/event_bus/name_resolver_spec.rb @@ -62,7 +62,10 @@ context 'when invalid' do let(:original_name) { 1 } - it { expect { resolved_name }.to raise_error Aruba::EventNameResolveError, /Transforming "1"/ } + it { + expect { resolved_name } + .to raise_error Aruba::EventNameResolveError, /Transforming "1"/ + } end end end diff --git a/spec/event_bus_spec.rb b/spec/event_bus_spec.rb index 093e5fb31..e3869ebb5 100644 --- a/spec/event_bus_spec.rb +++ b/spec/event_bus_spec.rb @@ -31,7 +31,7 @@ class MyMalformedHandler; end .to receive(:transform).with(event_name).and_return(event_klass) end - context 'when subscriber to event, the block is called and gets an instance of the event passed as payload' do + context 'when subscribed to the event' do before :each do bus.register(event_klass) do |event| @received_payload = event @@ -40,7 +40,9 @@ class MyMalformedHandler; end bus.notify event_instance end - it { expect(@received_payload).to eq(event_instance) } + it 'calls the block with an instance of the event passed as payload' do + expect(@received_payload).to eq(event_instance) + end end context 'when not subscriber to event' do @@ -105,7 +107,7 @@ class MyMalformedHandler; end it { expect(received_payload).to include event_instance } end - context 'when is symbol and event is defined in the default namespace given to NameResolver.new' do + context 'when is symbol and event is defined in the default namespace' do let!(:event_name) { :test_event } let(:received_payload) { [] } diff --git a/spec/support/shared_contexts/aruba.rb b/spec/support/shared_contexts/aruba.rb index 30a61244a..374b27ebd 100644 --- a/spec/support/shared_contexts/aruba.rb +++ b/spec/support/shared_contexts/aruba.rb @@ -33,7 +33,9 @@ def set_tag(tag_name, value) @file_path = @aruba.expand_path(@file_name) @aruba.setup_aruba - raise 'We must work with relative paths, everything else is dangerous' if @aruba.aruba.current_directory[0] == ?/ + if @aruba.aruba.current_directory[0] == '/' + raise 'We must work with relative paths, everything else is dangerous' + end end end diff --git a/spec/support/shared_examples/configuration.rb b/spec/support/shared_examples/configuration.rb index 0094ff3bd..f44a93240 100644 --- a/spec/support/shared_examples/configuration.rb +++ b/spec/support/shared_examples/configuration.rb @@ -1,7 +1,8 @@ RSpec.shared_examples 'a basic configuration' do subject(:config) do Class.new(described_class) do - option_accessor :use_test, contract: { Contracts::Bool => Contracts::Bool }, default: false + option_accessor :use_test, contract: { Contracts::Bool => Contracts::Bool }, + default: false end.new end @@ -13,7 +14,8 @@ subject(:config) { config_klass.new } before :each do - config_klass.option_reader :new_opt, contract: { Contracts::Num => Contracts::Num }, default: 1 + config_klass.option_reader :new_opt, contract: { Contracts::Num => Contracts::Num }, + default: 1 end context 'when value is read' do @@ -26,20 +28,23 @@ context 'when block is defined' do before :each do - config_klass.option_reader :new_opt2, contract: { Contracts::Num => Contracts::Num } do |c| - c.new_opt.value + 1 - end + config_klass.option_reader( + :new_opt2, + contract: { Contracts::Num => Contracts::Num } + ) { |c| c.new_opt.value + 1 } end - it { expect(config.new_opt2).to eq 2 } + it 'uses the block to set the value' do + expect(config.new_opt2).to eq 2 + end end context 'when block and default value is defined' do - it do + it 'complains that only one or the other can be specified' do expect do - config_klass.option_accessor :new_opt2, contract: { Contracts::Num => Contracts::Num }, default: 2 do |c| - c.new_opt.value + 1 - end + config_klass + .option_accessor(:new_opt2, contract: { Contracts::Num => Contracts::Num }, + default: 2) { |c| c.new_opt.value + 1 } end.to raise_error ArgumentError, 'Either use block or default value' end end @@ -51,7 +56,8 @@ subject(:config) { config_klass.new } before :each do - config_klass.option_accessor :new_opt, contract: { Contracts::Num => Contracts::Num }, default: 1 + config_klass.option_accessor :new_opt, contract: { Contracts::Num => Contracts::Num }, + default: 1 end context 'when default is used' do @@ -66,20 +72,24 @@ context 'when block is defined' do before :each do - config_klass.option_accessor :new_opt2, contract: { Contracts::Num => Contracts::Num } do |c| + config_klass.option_accessor( + :new_opt2, contract: { Contracts::Num => Contracts::Num } + ) do |c| c.new_opt.value + 1 end end - it { expect(config.new_opt2).to eq 2 } + it 'uses the block to set the default value' do + expect(config.new_opt2).to eq 2 + end end context 'when block and default value is defined' do - it do + it 'complains that only one or the other can be specified' do expect do - config_klass.option_accessor :new_opt2, contract: { Contracts::Num => Contracts::Num }, default: 2 do |c| - c.new_opt1 + 1 - end + config_klass.option_accessor(:new_opt2, + contract: { Contracts::Num => Contracts::Num }, + default: 2) { |c| c.new_opt1 + 1 } end.to raise_error ArgumentError, 'Either use block or default value' end end