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

Add rubocop testing and conform to its style recommendations #124

Merged
merged 1 commit into from
Nov 2, 2016
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
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ rvm:

env:
matrix:
- PUPPET_GEM_VERSION="~> 4.7.0"
- PUPPET_GEM_VERSION="~> 4.8.0"
- PUPPET_GEM_VERSION="~> 4"
- PUPPET_GEM_VERSION="~> 4.7.0" CHECK=test
- PUPPET_GEM_VERSION="~> 4.8.0" CHECK=test
- PUPPET_GEM_VERSION="~> 4" CHECK=test
- PUPPET_GEM_VERSION="~> 4" CHECK=rubocop

sudo: false

script: 'SPEC_OPTS="--format documentation" bundle exec rake validate lint spec'
script: 'SPEC_OPTS="--format documentation" bundle exec rake $CHECK'

matrix:
fast_finish: true
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'rubocop', :require => false
gem 'puppetlabs_spec_helper', '>= 1.2.0', :require => false
gem 'facter', '>= 2.0', :require => false
gem 'hiera', '~> 3.0', :require => false
gem 'rubocop', :require => false
gem 'puppet-lint', '~> 2.0', :require => false
gem 'puppet-lint-absolute_classname-check', :require => false
gem 'puppet-lint-alias-check', :require => false
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ task :validate do
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end

desc 'Run tests for CI'
task :test do
[:lint, :validate, :spec].each do |test|
Rake::Task[test].invoke
end
end
20 changes: 10 additions & 10 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@
cron_minute = nil
end

if [true, 'true'].include?(noop_value)
cron_command = '/opt/puppetlabs/bin/puppet agent --onetime --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay --noop'
else
cron_command = '/opt/puppetlabs/bin/puppet agent --onetime --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay'
end
cron_command = if [true, 'true'].include?(noop_value)
'/opt/puppetlabs/bin/puppet agent --onetime --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay --noop'
else
'/opt/puppetlabs/bin/puppet agent --onetime --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay'
end

it do
should contain_cron('puppet_agent_every_thirty').with({
Expand Down Expand Up @@ -165,11 +165,11 @@
context "set to #{value} (as #{value.class})" do
let(:params) { { :run_at_boot => value } }

if [true, 'true'].include?(value)
foo = 'present'
else
foo = 'absent'
end
foo = if [true, 'true'].include?(value)
'present'
else
'absent'
end

it { should contain_cron('puppet_agent_once_at_boot').with_ensure(foo) }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@
'non-empty array of strings' => {
:name => %w(autosign_entries),
:valid => [['array with one string'], %w(array with many strings)],
:invalid => [%w(), [1,'not_all','string'], true, 'string', { 'ha' => 'sh' }, 3, 2.42],
:invalid => [%w(), [1, 'not_all', 'string'], true, 'string', { 'ha' => 'sh' }, 3, 2.42],
:message => 'Error while evaluating a Resource Statement',
},
'memory size regex' => {
:name => %w(memory_size),
:valid => ['1g', '1m', '1500m', '3g'],
:valid => %w(1g 1m 1500m 3g),
:invalid => ['1g1', 'm', '1k', '2t', 'g3', '1.2g'],
:message => 'must be an integer following by the unit',
},
Expand Down