Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up a few of the LineLength cops #659

Merged
merged 1 commit into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ Style/PercentLiteralDelimiters:
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
Metrics/LineLength:
Max: 150

inherit_from: .rubocop_todo.yml
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,3 @@ Style/StderrPuts:
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 411
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 174
3 changes: 2 additions & 1 deletion aruba.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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 = 'Extension for popular TDD and BDD frameworks like "Cucumber", "RSpec" and "Minitest",
to make testing commandline applications meaningful, easy and fun.'
spec.summary = "aruba-#{spec.version}"
spec.license = 'MIT'
spec.email = '[email protected]'
Expand Down
8 changes: 6 additions & 2 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def in_current_directory(&block)
def cd(dir, &block)
if block_given?
begin
fail 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)
fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist."
end

old_directory = expand_path('.')
aruba.current_directory << dir
Expand All @@ -83,7 +85,9 @@ def cd(dir, &block)
return result
end

fail 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)
fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist."
end

old_directory = expand_path('.')
aruba.current_directory << dir
Expand Down
12 changes: 8 additions & 4 deletions lib/aruba/api/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def set_environment_variable(name, value)
aruba.environment[name] = value
new_environment = aruba.environment.to_h

aruba.event_bus.notify Events::AddedEnvironmentVariable.new(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
end
Expand All @@ -45,7 +46,8 @@ def append_environment_variable(name, value)
aruba.environment.append name, value
new_environment = aruba.environment.to_h

aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(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
end
Expand All @@ -67,7 +69,8 @@ def prepend_environment_variable(name, value)
aruba.environment.prepend name, value
new_environment = aruba.environment.to_h

aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(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
end
Expand All @@ -85,7 +88,8 @@ def delete_environment_variable(name)
aruba.environment.delete name
new_environment = aruba.environment.to_h

aruba.event_bus.notify Events::DeletedEnvironmentVariable.new(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
end
Expand Down
25 changes: 19 additions & 6 deletions lib/aruba/api/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def directory(path)
# 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
unless directory? name
fail ArgumentError, %(Only directories are supported. Path "#{name}" is not a directory.)
end

existing_files = Dir.glob(expand_path(File.join(name, '**', '*')))
current_working_directory = ArubaPath.new(expand_path('.'))
Expand Down Expand Up @@ -181,8 +183,13 @@ def copy(*args)
raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
end

raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? aruba.config.fixtures_path_prefix
raise ArgumentError, 'Multiples sources can only be copied to a directory' if source.count > 1 && exist?(destination) && !directory?(destination)
if destination.start_with? aruba.config.fixtures_path_prefix
raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported"
end

if source.count > 1 && exist?(destination) && !directory?(destination)
raise ArgumentError, 'Multiples sources can only be copied to a directory'
end

source_paths = source.map { |f| expand_path(f) }
destination_path = expand_path(destination)
Expand Down Expand Up @@ -219,16 +226,22 @@ 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

raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? aruba.config.fixtures_path_prefix
if destination.start_with? aruba.config.fixtures_path_prefix
raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported"
end

source.each do |s|
raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
end

raise ArgumentError, 'Multiple sources can only be copied to a directory' if source.count > 1 && exist?(destination) && !directory?(destination)
if source.count > 1 && exist?(destination) && !directory?(destination)
raise ArgumentError, 'Multiple sources can only be copied to a directory'
end

source_paths = source.map { |f| expand_path(f) }
destination_path = expand_path(destination)
Expand Down
4 changes: 3 additions & 1 deletion lib/aruba/config_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def initialize(config, event_bus)
# If one method ends with "=", e.g. ":option1=", then notify the event
# queue, that the user changes the value of "option1"
def method_missing(name, *args, &block)
event_bus.notify Events::ChangedConfiguration.new(changed: { name: name.to_s.gsub(/=$/, ''), value: args.first }) if name.to_s.end_with? '='
if name.to_s.end_with? '='
event_bus.notify Events::ChangedConfiguration.new(changed: { name: name.to_s.gsub(/=$/, ''), value: args.first })
end

config.send(name, *args, &block)
end
Expand Down
36 changes: 24 additions & 12 deletions lib/aruba/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,46 @@ module Aruba
class Configuration < BasicConfiguration
option_reader :root_directory, contract: { None => String }, default: Dir.getwd

option_accessor :working_directory, contract: { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath }, default: 'tmp/aruba'
option_accessor :working_directory,
contract: { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath },
default: 'tmp/aruba'

option_reader :fixtures_path_prefix, contract: { None => String }, default: '%'

option_accessor :exit_timeout, contract: { Num => Num }, default: 15
option_accessor :stop_signal, contract: { Maybe[String] => Maybe[String] }, default: nil
option_accessor :io_wait_timeout, contract: { Num => Num }, default: 0.1
option_accessor :startup_wait_time, contract: { Num => Num }, default: 0
option_accessor :fixtures_directories, contract: { Array => ArrayOf[String] }, default: %w(features/fixtures spec/fixtures test/fixtures fixtures)
option_accessor :fixtures_directories,
contract: { Array => ArrayOf[String] },
default: %w(features/fixtures spec/fixtures test/fixtures fixtures)

option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {}
# rubocop:disable Metrics/LineLength
option_accessor(:command_search_paths, contract: { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin'), File.join(config.root_directory.value, 'exe')] }
# rubocop:enable Metrics/LineLength
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')]
end
option_accessor :remove_ansi_escape_sequences, contract: { Bool => Bool }, default: true
# rubocop:disable Metrics/LineLength
option_accessor :command_launcher, contract: { Aruba::Contracts::Enum[:in_process, :spawn, :debug] => Aruba::Contracts::Enum[:in_process, :spawn, :debug] }, default: :spawn
option_accessor :command_launcher,
contract: { Aruba::Contracts::Enum[:in_process, :spawn, :debug] => Aruba::Contracts::Enum[:in_process, :spawn, :debug] },
default: :spawn
option_accessor :main_class, contract: { Class => Maybe[Class] }, default: nil

option_accessor :home_directory, contract: { Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] => Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] } do |config|
File.join(config.root_directory.value, config.working_directory.value)
end
option_accessor :home_directory,
contract: { Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] => Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] } do |config|
File.join(config.root_directory.value, config.working_directory.value)
end

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] }, default: :info
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] },
default: :info

# TODO: deprecate this value and replace with "filesystem allocation unit"
# 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 }, default: 512
option_accessor :physical_block_size,
contract: { Aruba::Contracts::IsPowerOfTwo => Aruba::Contracts::IsPowerOfTwo },
default: 512
option_accessor :console_history_file, contract: { String => String }, default: '~/.aruba_history'

option_accessor :activate_announcer_on_command_failure, contract: { ArrayOf[Symbol] => ArrayOf[Symbol] }, default: []
Expand Down
14 changes: 12 additions & 2 deletions lib/aruba/matchers/command/have_exit_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@
end

failure_message do |actual|
format(%(expected that command "%s" has exit status of "%s", but has "%s".), @old_actual.commandline, expected.to_s, actual.to_s)
format(
%(expected that command "%s" has exit status of "%s", but has "%s".),
@old_actual.commandline,
expected.to_s,
actual.to_s
)
end

failure_message_when_negated do |actual|
format(%(expected that command "%s" does not have exit status of "%s", but has "%s".), @old_actual.commandline, expected.to_s, actual.to_s)
format(
%(expected that command "%s" does not have exit status of "%s", but has "%s".),
@old_actual.commandline,
expected.to_s,
actual.to_s
)
end
end
8 changes: 7 additions & 1 deletion lib/aruba/platforms/windows_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ module Platforms
#
# @example But if you copy the ENV to a hash, Ruby treats the keys as case sensitive:
# env_copy = ENV.to_hash
# # => {"ALLUSERSPROFILE"=>"C:\\ProgramData", "ANSICON"=>"119x1000 (119x58)", "ANSICON_DEF"=>"7", APPDATA"=>"C:\\Users\\blorf\\AppData\\Roaming", ....}
# # => {
# "ALLUSERSPROFILE"=>
# "C:\\ProgramData",
# "ANSICON"=>"119x1000 (119x58)",
# "ANSICON_DEF"=>"7",
# APPDATA" => "C:\\Users\\blorf\\AppData\\Roaming", ....
# }
# env["Path"]
# # => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;"
# env["PATH"]
Expand Down
10 changes: 7 additions & 3 deletions lib/aruba/processes/spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
# rubocop:disable Metrics/MethodLength
def start
# rubocop:disable Metrics/LineLength
fail CommandAlreadyStartedError, %(Command "#{commandline}" has already been started. Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.\n#{caller.join("\n")}) if started?
if started?
error_message = %(Command "#{commandline}" has already been started. Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.\n#{caller.join("\n")})
fail CommandAlreadyStartedError, error_message
end

# rubocop:enable Metrics/LineLength

Expand Down Expand Up @@ -230,11 +233,12 @@ def pid
# @param [String] signal
# The signal, i.e. 'TERM'
def send_signal(signal)
fail CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.) if @process.exited?
error_message = %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
fail CommandAlreadyStoppedError, error_message if @process.exited?

Process.kill signal, pid
rescue Errno::ESRCH
raise CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
raise CommandAlreadyStoppedError, error_message
end

# Return file system stats for the given command
Expand Down
6 changes: 4 additions & 2 deletions spec/aruba/api/filesystem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@
context 'when destination is not a directory' do
let(:source) { %w(file1.txt file2.txt file3.txt) }
let(:destination) { 'file.txt' }
let(:error_message) { 'Multiples sources can only be copied to a directory' }

before(:each) { create_test_files(destination) }

it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, 'Multiples sources can only be copied to a directory' }
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, error_message }
end

context 'when a source is the same like destination' do
Expand All @@ -414,8 +415,9 @@
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" }

it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Using a fixture as destination (#{destination}) is not supported" }
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, error_message }
end
end
end
Expand Down