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

Rubocop: Fix more Style cops #1791

Merged
merged 15 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 0 additions & 2 deletions beaker.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- encoding: utf-8 -*-

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'beaker/version'
Expand Down
6 changes: 3 additions & 3 deletions lib/beaker/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def args_string args = @args
class PuppetCommand < Command
def initialize *args
command = "puppet #{args.shift}"
opts = args.last.is_a?(Hash) ? args.pop : Hash.new
opts['ENV'] ||= Hash.new
opts = args.last.is_a?(Hash) ? args.pop : {}
opts['ENV'] ||= {}
opts[:cmdexe] = true
super(command, args, opts)
end
Expand Down Expand Up @@ -162,7 +162,7 @@ def initialize platform, expression, filename, opts = {}
command << " > #{temp_file} && mv #{temp_file} #{filename} && rm -f #{temp_file}"
end
args = []
opts['ENV'] ||= Hash.new
opts['ENV'] ||= {}
super(command, args, opts)
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/beaker/dsl/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

['host', 'test', 'web', 'hocon'].each do |lib|
require "beaker/dsl/helpers/#{lib}_helpers"
end
Expand Down
2 changes: 0 additions & 2 deletions lib/beaker/dsl/helpers/hocon_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

require 'hocon/parser/config_document_factory'
require 'hocon/config_value_factory'

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/host/mac/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def group_list
def group_get(name)
execute("dscacheutil -q group -a name #{name}") do |result|
fail_test "failed to get group #{name}" unless /^name: #{name}/.match?(result.stdout)
gi = Hash.new # group info
gi = {} # group info
result.stdout.each_line do |line|
pieces = line.split(': ')
gi[pieces[0].to_sym] = pieces[1].strip if pieces[1] != nil
Expand Down
3 changes: 1 addition & 2 deletions lib/beaker/host/pswindows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ def environment_variable_string_pair_array env
# Overrides the {Windows::Exec#ssh_permit_user_environment} method,
# since no steps are needed in this setup to allow user ssh environments
# to work.
def ssh_permit_user_environment
end
def ssh_permit_user_environment; end

# Sets the user SSH environment.
#
Expand Down
2 changes: 0 additions & 2 deletions lib/beaker/host/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def skip_set_env?
case self['platform'].variant
when /^(f5|netscaler)$/
"no puppet-agent package for network device platform '#{self['platform'].variant}'"
else
nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/tasks/quick_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
task :run_test, [:hypervisor] => ["beaker_quickstart:gen_hosts", 'beaker_quickstart:gen_pre_suite',
'beaker_quickstart:gen_smoke_test',] do |_t, args|
hypervisor = args[:hypervisor] ||= 'vagrant'
system_args = Hash.new
system_args = {}
system_args[:hosts] = "acceptance/config/default_#{hypervisor}_hosts.yaml"
system_args[:pre_suite] = 'acceptance/setup/default_pre_suite.rb'
system_args[:tests] = 'acceptance/tests/default_smoke_test.rb'
Expand Down
2 changes: 0 additions & 2 deletions lib/beaker/test_suite.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

require 'fileutils'
['test_case', 'logger', 'test_suite_result'].each do |lib|
require "beaker/#{lib}"
Expand Down
2 changes: 0 additions & 2 deletions lib/beaker/test_suite_result.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

require 'fileutils'
['test_case', 'logger', 'test_suite', 'logger_junit'].each do |lib|
require "beaker/#{lib}"
Expand Down
16 changes: 8 additions & 8 deletions spec/beaker/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Beaker
subject(:cmd) { described_class.new(command, args, options) }

let(:command) { @command || '/bin/ls' }
let(:args) { @args || Array.new }
let(:options) { @options || Hash.new }
let(:args) { @args || [] }
let(:options) { @options || {} }

let(:host) do
h = Hash.new
h = {}
allow(h).to receive(:environment_string).and_return('')
h
end
Expand Down Expand Up @@ -94,10 +94,10 @@ module Beaker
subject(:cmd) { described_class.new(command, args, options) }

let(:command) { @command || '/bin/ls' }
let(:args) { @args || Array.new }
let(:options) { @options || Hash.new }
let(:args) { @args || [] }
let(:options) { @options || {} }

let(:host) { Hash.new }
let(:host) { {} }

it 'returns a simple string passed in' do
@command = "pants"
Expand All @@ -119,7 +119,7 @@ module Beaker
subject(:cmd) { described_class.new(platform, expression, filename, options) }

let(:host) do
h = Hash.new
h = {}
allow(h).to receive(:environment_string).and_return('')
allow(h).to receive(:prepend_commands).and_return('')
allow(h).to receive(:append_commands).and_return('')
Expand All @@ -128,7 +128,7 @@ module Beaker
let(:platform) { @platform || 'unix' }
let(:expression) { @expression || 's/b/s/' }
let(:filename) { @filename || '/fakefile' }
let(:options) { @options || Hash.new }
let(:options) { @options || {} }

it 'forms a basic sed command correctly' do
expect(cmd.cmd_line host).to be === "sed -i -e \"#{expression}\" #{filename}"
Expand Down
4 changes: 2 additions & 2 deletions spec/beaker/dsl/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ClassMixedWithDSLRoles
end

describe ClassMixedWithDSLRoles do
let(:hosts) { @hosts || Hash.new }
let(:options) { @options || Hash.new }
let(:hosts) { @hosts || {} }
let(:options) { @options || {} }
let(:agent1) { make_host('agent1', { :roles => ['agent'] }) }
let(:agent2) { make_host('agent2', { :roles => ['agent'] }) }
let(:a_and_dash) { make_host('a_and_dash', { :roles => ['agent', 'dashboard'] }) }
Expand Down
2 changes: 0 additions & 2 deletions spec/beaker/logger_junit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

module Beaker
Expand Down
2 changes: 0 additions & 2 deletions spec/beaker/logger_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

module Beaker
Expand Down
2 changes: 0 additions & 2 deletions spec/beaker/network_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

module Beaker
Expand Down
4 changes: 2 additions & 2 deletions spec/beaker/perf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Beaker
end

it 'creates a new Perf object' do
hosts = Array.new
options = Hash.new
hosts = []
options = {}
options[:log_level] = :debug
my_logger = Beaker::Logger.new(options)
options[:logger] = my_logger
Expand Down
2 changes: 1 addition & 1 deletion spec/beaker/shared/host_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module Shared
myhosts = host_handler.run_block_on(hosts, nil, { :run_in_parallel => true }) do |host|
# kind of hacky workaround to remove logger which contains a singleton method injected by rspec

host.instance_eval("remove_instance_variable(:@logger)")
host.instance_eval("remove_instance_variable(:@logger)", __FILE__, __LINE__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be way simpler:

Suggested change
host.instance_eval("remove_instance_variable(:@logger)", __FILE__, __LINE__)
host.send(:remove_instance_variable, :@logger)

#1793

host
end

Expand Down
2 changes: 1 addition & 1 deletion spec/beaker/test_suite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Beaker
let(:sh_test) { File.expand_path(test_dir + '/my_shell_file.sh') }

it 'fails without test files' do
expect { described_class.new('name', 'hosts', Hash.new, Time.now, :stop_on_error) }.to raise_error
expect { described_class.new('name', 'hosts', {}, Time.now, :stop_on_error) }.to raise_error
end

it 'includes specific files as test file when explicitly passed' do
Expand Down