Skip to content

Commit 53e0f6e

Browse files
authored
Merge pull request #122 from bastelfreak/rubocop
Rubocop: Fix Style cops
2 parents 55bad9a + e88e7c6 commit 53e0f6e

11 files changed

Lines changed: 157 additions & 105 deletions

File tree

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,5 @@ Style/TrailingCommaInArguments:
3232
Metrics:
3333
Enabled: false
3434

35-
Style:
36-
Enabled: false
37-
3835
Layout:
3936
Enabled: false

.rubocop_todo.yml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-03-17 13:00:57 UTC using RuboCop version 1.48.1.
3+
# on 2023-03-24 13:46:36 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -63,3 +63,75 @@ RSpec/DescribeClass:
6363
RSpec/NoExpectationExample:
6464
Exclude:
6565
- 'spec/acceptance/example_spec.rb'
66+
67+
# Offense count: 1
68+
# This cop supports unsafe autocorrection (--autocorrect-all).
69+
# Configuration parameters: EnforcedStyle.
70+
# SupportedStyles: always, conditionals
71+
Style/AndOr:
72+
Exclude:
73+
- 'lib/beaker-rspec/helpers/serverspec.rb'
74+
75+
# Offense count: 7
76+
# This cop supports unsafe autocorrection (--autocorrect-all).
77+
# Configuration parameters: EnforcedStyle.
78+
# SupportedStyles: nested, compact
79+
Style/ClassAndModuleChildren:
80+
Exclude:
81+
- 'lib/beaker-rspec/helpers/serverspec.rb'
82+
83+
# Offense count: 1
84+
Style/ClassVars:
85+
Exclude:
86+
- 'lib/beaker-rspec/helpers/serverspec.rb'
87+
88+
# Offense count: 10
89+
# Configuration parameters: AllowedConstants.
90+
Style/Documentation:
91+
Exclude:
92+
- 'spec/**/*'
93+
- 'test/**/*'
94+
- 'lib/beaker-rspec.rb'
95+
- 'lib/beaker-rspec/helpers/serverspec.rb'
96+
97+
# Offense count: 10
98+
# This cop supports unsafe autocorrection (--autocorrect-all).
99+
# Configuration parameters: EnforcedStyle.
100+
# SupportedStyles: always, always_true, never
101+
Style/FrozenStringLiteralComment:
102+
Exclude:
103+
- 'Gemfile'
104+
- 'beaker-rspec.gemspec'
105+
- 'lib/beaker-rspec.rb'
106+
- 'lib/beaker-rspec/beaker_shim.rb'
107+
- 'lib/beaker-rspec/helpers/serverspec.rb'
108+
- 'lib/beaker-rspec/rake_task.rb'
109+
- 'lib/beaker-rspec/spec_helper.rb'
110+
- 'lib/beaker-rspec/version.rb'
111+
- 'spec/acceptance/example_spec.rb'
112+
- 'spec/spec_helper.rb'
113+
114+
# Offense count: 1
115+
Style/MissingRespondToMissing:
116+
Exclude:
117+
- 'lib/beaker-rspec/helpers/serverspec.rb'
118+
119+
# Offense count: 1
120+
Style/MixinUsage:
121+
Exclude:
122+
- 'lib/beaker-rspec/spec_helper.rb'
123+
124+
# Offense count: 1
125+
# This cop supports unsafe autocorrection (--autocorrect-all).
126+
# Configuration parameters: EnforcedStyle.
127+
# SupportedStyles: literals, strict
128+
Style/MutableConstant:
129+
Exclude:
130+
- 'lib/beaker-rspec/version.rb'
131+
132+
# Offense count: 1
133+
# This cop supports unsafe autocorrection (--autocorrect-all).
134+
# Configuration parameters: RequireEnglish.
135+
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
136+
Style/SpecialGlobalVars:
137+
EnforcedStyle: use_perl_names

Gemfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
source ENV['GEM_SOURCE'] || "https://rubygems.org"
1+
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
22

33
def location_for(place, fake_version = nil)
44
if place =~ /^(git:[^#]*)#(.*)/
5-
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
6-
elsif place =~ /^file:\/\/(.*)/
7-
['>= 0', { :path => File.expand_path($1), :require => false }]
5+
[fake_version, { git: Regexp.last_match(1), branch: Regexp.last_match(2), require: false }].compact
6+
elsif place =~ %r{^file://(.*)}
7+
['>= 0', { path: File.expand_path(Regexp.last_match(1)), require: false }]
88
else
9-
[place, { :require => false }]
9+
[place, { require: false }]
1010
end
1111
end
1212

13-
if (beaker_version = ENV['BEAKER_VERSION'])
13+
if (beaker_version = ENV.fetch('BEAKER_VERSION', nil))
1414
gem 'beaker', *location_for(beaker_version)
1515
end
1616

17-
case ENV['BEAKER_HYPERVISOR']
17+
case ENV.fetch('BEAKER_HYPERVISOR', nil)
1818
when 'docker'
1919
gem 'beaker-docker'
2020
when 'vagrant', 'vagrant_libvirt'

Rakefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ else
2828
# These make the rubocop experience maybe slightly less terrible
2929
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
3030
# Use Rubocop's Github Actions formatter if possible
31-
if ENV['GITHUB_ACTIONS'] == 'true'
32-
task.formatters << 'github'
33-
end
31+
task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
3432
end
3533
end

beaker-rspec.gemspec

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
# -*- encoding: utf-8 -*-
2-
$:.push File.expand_path("../lib", __FILE__)
1+
$:.push File.expand_path('lib', __dir__)
32
require 'beaker-rspec/version'
43

54
Gem::Specification.new do |s|
6-
s.name = "beaker-rspec"
5+
s.name = 'beaker-rspec'
76
s.version = BeakerRSpec::Version::STRING
8-
s.authors = ["Vox Pupuli"]
9-
s.email = ["voxpupuli@groups.io"]
10-
s.homepage = "https://github.com/voxpupuli/beaker-rspec"
11-
s.summary = %q{RSpec bindings for beaker}
12-
s.description = %q{RSpec bindings for beaker, see https://github.com/voxpupuli/beaker}
7+
s.authors = ['Vox Pupuli']
8+
s.email = ['voxpupuli@groups.io']
9+
s.homepage = 'https://github.com/voxpupuli/beaker-rspec'
10+
s.summary = 'RSpec bindings for beaker'
11+
s.description = 'RSpec bindings for beaker, see https://github.com/voxpupuli/beaker'
1312
s.license = 'Apache-2.0'
1413

1514
s.required_ruby_version = '>= 2.7.0', '<4.0.0'
1615

1716
s.files = `git ls-files`.split("\n")
1817
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19-
s.require_paths = ["lib"]
18+
s.require_paths = ['lib']
2019

2120
# Testing dependencies
2221
s.add_development_dependency 'fakefs', '>= 0.6', '< 2'

lib/beaker-rspec/beaker_shim.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def hosts
7070
end
7171

7272
# Setter for hosts object
73-
def hosts= v
73+
def hosts=(v)
7474
RSpec.configuration.hosts = v
7575
end
7676

lib/beaker-rspec/helpers/serverspec.rb

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ def cur_example
1515
def get_working_node
1616
example = cur_example
1717
if example and example.metadata[:node]
18-
node = example.metadata[:node]
18+
example.metadata[:node]
1919
else
20-
node = default_node
20+
default_node
2121
end
22-
node
2322
end
2423

2524
# The cygwin backend
@@ -40,20 +39,20 @@ def exec_backend
4039
module Specinfra
4140
module Configuration
4241
class << self
43-
VALID_OPTIONS_KEYS = [
44-
:backend,
45-
:env,
46-
:path,
47-
:pre_command,
48-
:sudo_path,
49-
:disable_sudo,
50-
:sudo_options,
51-
:docker_image,
52-
:docker_url,
53-
:lxc,
54-
:request_pty,
55-
:ssh_options,
56-
:dockerfile_finalizer,
42+
VALID_OPTIONS_KEYS = %i[
43+
backend
44+
env
45+
path
46+
pre_command
47+
sudo_path
48+
disable_sudo
49+
sudo_options
50+
docker_image
51+
docker_url
52+
lxc
53+
request_pty
54+
ssh_options
55+
dockerfile_finalizer
5756
].freeze
5857
end
5958

@@ -66,9 +65,7 @@ module Specinfra::Helper::Os
6665

6766
def os
6867
working_node_name = get_working_node.to_s
69-
if !@@known_nodes[working_node_name] # haven't seen this yet, better detect the os
70-
@@known_nodes[working_node_name] = property[:os] = detect_os
71-
end
68+
@@known_nodes[working_node_name] = property[:os] = detect_os unless @@known_nodes[working_node_name] # haven't seen this yet, better detect the os
7269
@@known_nodes[working_node_name]
7370
end
7471

@@ -80,9 +77,7 @@ def detect_os
8077
return Specinfra.configuration.os if Specinfra.configuration.os
8178
backend = Specinfra.backend
8279
node = get_working_node
83-
if node['platform'].include?('windows')
84-
return {:family => 'windows'}
85-
end
80+
return {family: 'windows'} if node['platform'].include?('windows')
8681
Specinfra::Helper::DetectOs.subclasses.each do |c|
8782
res = c.detect
8883
if res
@@ -109,11 +104,8 @@ def get_windows_cmd(meth, *args)
109104
command_class = version_class.const_get(resource_type.to_camel_case)
110105

111106
command_class = command_class.create
112-
if command_class.respond_to?(method)
113-
command_class.send(method, *args)
114-
else
115-
raise NotImplementedError.new("#{method} is not implemented in #{command_class}")
116-
end
107+
raise NotImplementedError, "#{method} is not implemented in #{command_class}" unless command_class.respond_to?(method)
108+
command_class.send(method, *args)
117109
end
118110

119111
end
@@ -135,12 +127,10 @@ def self.method_missing(meth, *args)
135127
else
136128
run(meth, *args)
137129
end
130+
elsif backend.respond_to?(meth)
131+
backend.send(meth, *args)
138132
else
139-
if backend.respond_to?(meth)
140-
backend.send(meth, *args)
141-
else
142-
run(meth, *args)
143-
end
133+
run(meth, *args)
144134
end
145135
end
146136

@@ -167,7 +157,7 @@ def convert_regexp(target)
167157
when Regexp
168158
target.source
169159
else
170-
Regexp.escape(target.to_s.gsub '/', '\/').gsub('\n', '(\r\n|\n)')
160+
Regexp.escape(target.to_s.gsub('/', '\/')).gsub('\n', '(\r\n|\n)')
171161
end
172162
end
173163
end
@@ -176,19 +166,17 @@ def convert_regexp(target)
176166
module Specinfra::Backend
177167
class BeakerBase < Specinfra::Backend::Base
178168
# Example accessor
179-
def example
180-
@example
181-
end
169+
attr_reader :example
182170

183171
# Execute the provided ssh command
184172
# @param [String] command The command to be executed
185173
# @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
186174
def ssh_exec!(node, command)
187-
r = on node, command, { :acceptable_exit_codes => (0..127) }
175+
r = on node, command, { acceptable_exit_codes: (0..127) }
188176
{
189-
:exit_status => r.exit_code,
190-
:stdout => r.stdout,
191-
:stderr => r.stderr,
177+
exit_status: r.exit_code,
178+
stdout: r.stdout,
179+
stderr: r.stderr,
192180
}
193181
end
194182

@@ -237,11 +225,11 @@ def run_command(cmd, _opt = {})
237225
#when node is not cygwin rm -rf will fail so lets use native del instead
238226
#There should be a better way to do this, but for now , this works
239227
if node.is_cygwin?
240-
delete_command = "rm -rf"
241-
redirection = "< /dev/null"
228+
delete_command = 'rm -rf'
229+
redirection = '< /dev/null'
242230
else
243-
delete_command = "del"
244-
redirection = "< NUL"
231+
delete_command = 'del'
232+
redirection = '< NUL'
245233
end
246234
on node, "#{delete_command} script.ps1"
247235
create_remote_file(node, 'script.ps1', script)
@@ -288,9 +276,7 @@ def build_command(cmd)
288276
cmd = "#{String(useshell).shellescape} -c #{String(cmd).shellescape}"
289277

290278
path = Specinfra.configuration.path
291-
if path
292-
cmd = %Q{env PATH="#{path}" #{cmd}}
293-
end
279+
cmd = %(env PATH="#{path}" #{cmd}) if path
294280

295281
cmd
296282
end

lib/beaker-rspec/rake_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'rspec/core/rake_task'
22

33
RSpec::Core::RakeTask.new(:beaker) do |c|
4-
c.pattern = "spec/acceptance/**/*_spec.rb"
4+
c.pattern = 'spec/acceptance/**/*_spec.rb'
55
end

0 commit comments

Comments
 (0)