Skip to content

Commit a70ede4

Browse files
committed
RuboCop fixes
1 parent 45509a5 commit a70ede4

14 files changed

+424
-339
lines changed

.rubocop.yml

+230-177
Large diffs are not rendered by default.

Gemfile

+61-26
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,71 @@
11
source ENV['GEM_SOURCE'] || "https://rubygems.org"
22

3+
def location_for(place, fake_version = nil)
4+
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 }]
8+
else
9+
[place, { :require => false }]
10+
end
11+
end
12+
313
group :test do
4-
gem "ci_reporter_rspec"
5-
gem "metadata-json-lint"
6-
gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 4.7.0'
7-
gem "puppet-lint-absolute_classname-check"
8-
gem "puppet-lint-classes_and_types_beginning_with_digits-check"
9-
gem "puppet-lint-leading_zero-check"
10-
gem "puppet-lint-resource_reference_syntax"
11-
gem "puppet-lint-trailing_comma-check"
12-
gem "puppet-lint-unquoted_string-check"
13-
gem "puppet-lint-version_comparison-check"
14-
gem "puppetlabs_spec_helper"
15-
gem "rake"
16-
gem "rspec"
17-
gem "rspec-puppet"
18-
gem "rspec-puppet-facts"
19-
gem "rubocop"
20-
gem "simplecov"
21-
gem "simplecov-console"
22-
gem "webmock"
14+
gem 'puppetlabs_spec_helper', '~> 1.2.2', :require => false
15+
gem 'rspec-puppet', '~> 2.5', :require => false
16+
gem 'rspec-puppet-facts', :require => false
17+
gem 'rspec-puppet-utils', :require => false
18+
gem 'puppet-lint-absolute_classname-check', :require => false
19+
gem 'puppet-lint-leading_zero-check', :require => false
20+
gem 'puppet-lint-trailing_comma-check', :require => false
21+
gem 'puppet-lint-version_comparison-check', :require => false
22+
gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false
23+
gem 'puppet-lint-unquoted_string-check', :require => false
24+
gem 'puppet-lint-variable_contains_upcase', :require => false
25+
gem 'metadata-json-lint', :require => false
26+
gem 'puppet-blacksmith', :require => false
27+
gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git'
28+
gem 'puppet-strings', '~> 1.0.0', :require => false
29+
gem 'redcarpet', :require => false
30+
gem 'rubocop', '~> 0.47.0', :require => false if RUBY_VERSION >= '2.3.0'
31+
gem 'rubocop-rspec', '~> 1.10.0', :require => false if RUBY_VERSION >= '2.3.0'
32+
gem 'mocha', '>= 1.2.1', :require => false
33+
gem 'coveralls', :require => false
34+
gem 'simplecov-console', :require => false
35+
gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2'
36+
gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2'
37+
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
38+
gem 'webmock', :require => false
2339
end
2440

2541
group :development do
26-
gem "puppet-blacksmith"
27-
gem "travis"
28-
gem "travis-lint"
29-
gem "vagrant-wrapper"
42+
gem 'travis', :require => false
43+
gem 'travis-lint', :require => false
44+
gem 'guard-rake', :require => false
3045
end
3146

3247
group :system_tests do
33-
gem "beaker", '~> 2'
34-
gem "beaker-puppet_install_helper"
35-
gem "beaker-rspec"
48+
if beaker_version = ENV['BEAKER_VERSION']
49+
gem 'beaker', *location_for(beaker_version)
50+
end
51+
if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
52+
gem 'beaker-rspec', *location_for(beaker_rspec_version)
53+
else
54+
gem 'beaker-rspec', :require => false
55+
end
56+
gem 'serverspec', :require => false
57+
gem 'beaker-puppet_install_helper', :require => false
58+
end
59+
60+
61+
62+
if facterversion = ENV['FACTER_GEM_VERSION']
63+
gem 'facter', facterversion.to_s, :require => false, :groups => [:test]
64+
else
65+
gem 'facter', :require => false, :groups => [:test]
3666
end
67+
68+
ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 4.0' : puppetversion = ENV['PUPPET_VERSION'].to_s
69+
gem 'puppet', puppetversion, :require => false, :groups => [:test]
70+
71+
# vim: syntax=ruby

Rakefile

+32-44
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,44 @@
1-
require 'rubygems'
2-
require 'bundler/setup'
3-
41
require 'puppetlabs_spec_helper/rake_tasks'
5-
require 'puppet/version'
6-
require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6
7-
require 'puppet-lint/tasks/puppet-lint'
8-
require 'puppet-syntax/tasks/puppet-syntax'
9-
require 'metadata-json-lint/rake_task'
10-
require 'ci/reporter/rake/rspec'
11-
12-
# These gems aren't always present, for instance
13-
# on Travis with --without development
14-
begin
15-
require 'puppet_blacksmith/rake_tasks'
16-
rescue LoadError # rubocop:disable Lint/HandleExceptions
17-
end
2+
require 'puppet_blacksmith/rake_tasks'
3+
require 'voxpupuli/release/rake_tasks'
4+
require 'puppet-strings/tasks'
185

19-
exclude_paths = [
20-
"bundle/**/*",
21-
"pkg/**/*",
22-
"vendor/**/*",
23-
"spec/**/*",
24-
]
25-
26-
Rake::Task[:lint].clear
27-
28-
PuppetLint.configuration.relative = true
29-
PuppetLint.configuration.disable_80chars
30-
PuppetLint.configuration.disable_class_inherits_from_params_class
31-
PuppetLint.configuration.disable_class_parameter_defaults
6+
PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
327
PuppetLint.configuration.fail_on_warnings = true
33-
34-
PuppetLint::RakeTask.new :lint do |config|
35-
config.ignore_paths = exclude_paths
36-
end
37-
8+
PuppetLint.configuration.send('relative')
9+
PuppetLint.configuration.send('disable_140chars')
10+
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
11+
PuppetLint.configuration.send('disable_documentation')
12+
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
13+
14+
exclude_paths = %w(
15+
pkg/**/*
16+
vendor/**/*
17+
.vendor/**/*
18+
spec/**/*
19+
)
20+
PuppetLint.configuration.ignore_paths = exclude_paths
3821
PuppetSyntax.exclude_paths = exclude_paths
3922

40-
desc "Populate CONTRIBUTORS file"
41-
task :contributors do
42-
system("git log --format='%aN' | sort -u > CONTRIBUTORS")
43-
end
44-
4523
desc 'Run acceptance tests'
4624
RSpec::Core::RakeTask.new(:acceptance) do |t|
4725
t.pattern = 'spec/acceptance'
4826
end
4927

50-
desc "Run syntax, lint, and spec tests."
51-
task :test => [
28+
desc 'Run tests metadata_lint, release_checks'
29+
task test: [
5230
:metadata_lint,
53-
:syntax,
54-
:lint,
55-
:spec,
31+
:release_checks,
5632
]
33+
34+
begin
35+
require 'github_changelog_generator/task'
36+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
37+
version = (Blacksmith::Modulefile.new).version
38+
config.future_release = "#{version}"
39+
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not impact the functionality of the module."
40+
config.exclude_labels = %w{duplicate question invalid wontfix modulesync}
41+
end
42+
rescue LoadError
43+
end
44+
# vim: syntax=ruby

lib/facter/apache.rb

+14-11
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,36 @@ def fetch(uri_str, limit = 10)
2121
Facter.add(:apache_present) do
2222
setcode do
2323
present = Facter::Util::Resolution.which('apachectl')
24-
if not present
25-
present = Facter::Util::Resolution.which('apache2ctl')
26-
end
24+
present = Facter::Util::Resolution.which('apache2ctl') unless present
2725
!!present
2826
end
2927
end
3028

3129
Facter.add(:apache_running) do
32-
confine :apache_present => true
30+
confine apache_present: true
3331
setcode do
34-
Puppet::Type.type(:service).newservice(:name => 'apache2').provider.status == :running
32+
Puppet::Type.type(:service).newservice(name: 'apache2').provider.status == :running
3533
end
3634
end
3735

3836
Facter.add(:apache_statuspage_present) do
39-
confine :apache_present => true
37+
confine apache_present: true
4038
setcode do
4139
uri = 'http://localhost/server-status'
4240
begin
4341
response = fetch(uri)
44-
!!(response.body =~ /<title>Apache Status<\/title>/i)
45-
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
46-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED
42+
!!(response.body =~ %r{<title>Apache Status</title>}i)
43+
rescue Timeout::Error,
44+
Errno::EINVAL,
45+
Errno::ECONNRESET,
46+
EOFError,
47+
Net::HTTPBadResponse,
48+
Net::HTTPHeaderSyntaxError,
49+
Net::ProtocolError,
50+
Errno::ECONNREFUSED
4751
false
4852
end
4953
end
5054
end
5155

52-
# TODO: use a full apache conf parser like https://github.com/bmatzelle/apache_config
53-
# and look for "SetHandler server-status"
56+
# TODO; use a full apache conf parser like https://github.com/bmatzelle/apache_config and look for "SetHandler server-status"

lib/facter/rabbitmq.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
end
66

77
Facter.add(:rabbitmq_management_present) do
8-
confine :rabbitmq_present => true
8+
confine rabbitmq_present: true
99
setcode do
1010
!!Facter::Util::Resolution.exec('/usr/sbin/rabbitmqctl status | grep rabbitmq_management')
1111
end
1212
end
1313

1414
Facter.add(:rabbitmq_management_port) do
15-
confine :rabbitmq_present => true
15+
confine rabbitmq_present: true
1616
setcode do
1717
Facter::Util::Resolution.exec('/usr/sbin/rabbitmqctl environment | /bin/grep -A 10 rabbitmq_management | /bin/grep "listener,\[{port" | /bin/grep -o -E "[0-9]+"')
1818
end
1919
end
2020

21-
22-
# TODO parse /etc/rabbitmq/rabbitmq.config to get user/pass/port exposed as facts
21+
# TODO; parse /etc/rabbitmq/rabbitmq.config to get user/pass/port exposed as facts

lib/facter/redis.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Facter.add("redis_present") do
1+
Facter.add(:redis_present) do
22
setcode do
33
!!Facter::Util::Resolution.which('redis-server')
44
end

spec/acceptance/class_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'configure server side' do
44
context 'minimal config to enable client tests' do
5-
it 'should install a working server side' do
5+
it 'installs a working server side' do
66
pp_master = <<-EOS
77
class { '::rabbitmq':
88
ssl => false,
@@ -32,14 +32,14 @@ class { 'influxdb':
3232
EOS
3333

3434
# Run it twice and test for idempotency
35-
apply_manifest_on(master, pp_master, :catch_failures => true)
36-
apply_manifest_on(master, pp_master, :catch_changes => true)
35+
apply_manifest_on(master, pp_master, catch_failures: true)
36+
apply_manifest_on(master, pp_master, catch_changes: true)
3737
end
3838
end
3939
end
4040

4141
hosts.each do |host|
42-
describe 'redis installed', :if => host['roles'].include?('client') do
42+
describe 'redis installed', if: host['roles'].include?('client') do
4343
context 'during same run' do
4444
it 'works with no errors' do
4545
master_hostname = on(master, facter('hostname')).stdout.strip
@@ -57,8 +57,8 @@ class { 'monitoring':
5757
EOS
5858

5959
# Run it twice and test for idempotency
60-
apply_manifest(pp, :catch_failures => true)
61-
apply_manifest(pp, :catch_changes => true)
60+
apply_manifest(pp, catch_failures: true)
61+
apply_manifest(pp, catch_changes: true)
6262
end
6363

6464
describe package('redis-server') do

spec/classes/init_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
facts
99
end
1010

11-
context "monitoring class without any parameters" do
11+
context 'monitoring class without any parameters' do
1212
it { is_expected.to compile.with_all_deps }
1313

1414
it { is_expected.to contain_class('monitoring::params') }
1515
end
1616

17-
context "rabbitmq present" do
17+
context 'rabbitmq present' do
1818
let(:facts) do
19-
facts.merge({rabbitmq_present: true, rabbitmq_management_present: true, rabbitmq_management_port: '15672'})
19+
facts.merge(rabbitmq_present: true, rabbitmq_management_present: true, rabbitmq_management_port: '15672')
2020
end
2121

2222
it { is_expected.to contain_class('monitoring::metrics::collectd') }
@@ -37,12 +37,12 @@
3737
describe 'monitoring class without any parameters on Solaris/Nexenta' do
3838
let(:facts) do
3939
{
40-
:osfamily => 'Solaris',
41-
:operatingsystem => 'Nexenta',
40+
osfamily: 'Solaris',
41+
operatingsystem: 'Nexenta'
4242
}
4343
end
4444

45-
it { expect { is_expected.to contain_package('monitoring') }.to raise_error(Puppet::Error, /Nexenta not supported/) }
45+
it { expect { is_expected.to contain_package('monitoring') }.to raise_error(Puppet::Error, %r{Nexenta not supported}) }
4646
end
4747
end
4848
end

spec/spec_helper.rb

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
require 'puppetlabs_spec_helper/module_spec_helper'
22
require 'rspec-puppet-facts'
3-
require 'webmock/rspec'
4-
53
include RspecPuppetFacts
64

7-
require 'simplecov'
8-
require 'simplecov-console'
9-
10-
SimpleCov.start do
11-
add_filter '/spec'
12-
add_filter '/vendor'
13-
formatter SimpleCov::Formatter::MultiFormatter.new([
5+
if Dir.exist?(File.expand_path('../../lib', __FILE__))
6+
require 'coveralls'
7+
require 'simplecov'
8+
require 'simplecov-console'
9+
SimpleCov.formatters = [
1410
SimpleCov::Formatter::HTMLFormatter,
15-
SimpleCov::Formatter::Console
16-
])
11+
SimpleCov::Formatter::Console,
12+
Coveralls::SimpleCov::Formatter
13+
]
14+
SimpleCov.start do
15+
track_files 'lib/**/*.rb'
16+
add_filter '/spec'
17+
add_filter '/vendor'
18+
add_filter '/.vendor'
19+
end
1720
end
1821

1922
RSpec.configure do |c|
20-
c.before(:each) do
21-
stub_request(:get, /.*/).
22-
with(:headers => {'User-Agent'=>'Ruby'}).
23-
to_return(:status => 200, :body => "", :headers => {})
24-
end
25-
2623
default_facts = {
2724
puppetversion: Puppet.version,
2825
facterversion: Facter.version
2926
}
3027
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
3128
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
3229
c.default_facts = default_facts
33-
end
30+
end
31+
32+
# vim: syntax=ruby

0 commit comments

Comments
 (0)