Skip to content

Commit

Permalink
rubocop is a steely-eyed missile man
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Apr 6, 2016
1 parent 3f2b18b commit 03d7e23
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Jenkins
def self.home_dir
begin
return File.expand_path('~jenkins')
rescue ArgumentError => ex
rescue ArgumentError
# The Jenkins user doesn't exist!
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/jenkins/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.available
if manifest
plugins[plugin] = manifest
end
rescue StandardError => ex
rescue StandardError
# Nothing really to do about it, failing means no version which will
# result in a new plugin if needed
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/jenkins_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Puppet::Parser::Functions

config_hash = lookupvar('::jenkins::config_hash')
if config_hash && \
config_hash['HTTP_PORT'] && \
config_hash['HTTP_PORT']['value']
config_hash['HTTP_PORT'] && \
config_hash['HTTP_PORT']['value']
return config_hash['HTTP_PORT']['value']
else
return lookupvar('::jenkins::params::port')
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/jenkins_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Puppet::Parser::Functions

config_hash = lookupvar('::jenkins::config_hash')
if config_hash && \
config_hash['PREFIX'] && \
config_hash['PREFIX']['value']
config_hash['PREFIX'] && \
config_hash['PREFIX']['value']
return config_hash['PREFIX']['value']
else
return lookupvar('::jenkins::params::prefix')
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/jenkins_authorization_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# converged might require one of those accounts for administrative control
autorequire(:jenkins_user) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(:jenkins_user))
r.is_a?(Puppet::Type.type(:jenkins_user))
end
end

Expand All @@ -27,7 +27,7 @@
autorequire(:jenkins_security_realm) do
if self[:ensure] == :present
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(:jenkins_security_realm))
r.is_a?(Puppet::Type.type(:jenkins_security_realm))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/jenkins_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
].each do |type|
autorequire(type) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(type))
r.is_a?(Puppet::Type.type(type))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/jenkins_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def change_to_s(currentvalue, newvalue)
].each do |type|
autorequire(type) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(type))
r.is_a?(Puppet::Type.type(type))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/jenkins_num_executors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
].each do |type|
autorequire(type) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(type))
r.is_a?(Puppet::Type.type(type))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/jenkins_security_realm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
# jenkins_authorization_strategy state changes.
autorequire(:jenkins_user) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(:jenkins_user))
r.is_a?(Puppet::Type.type(:jenkins_user))
end
end

autorequire(:jenkins_authorization_strategy) do
if self[:ensure] == :absent
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(:jenkins_authorization_strategy))
r.is_a?(Puppet::Type.type(:jenkins_authorization_strategy))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/jenkins_slaveagent_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
].each do |type|
autorequire(type) do
catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(type))
r.is_a?(Puppet::Type.type(type))
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions spec/classes/jenkins_jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
end

context 'with cli disabled' do
let(:params) { { :service_ensure => 'stopped',
:cli => false,
:job_hash => { 'build' => { 'config' => '<xml/>' } } } }
let(:params) do
{
:service_ensure => 'stopped',
:cli => false,
:job_hash => { 'build' => { 'config' => '<xml/>' } }
}
end
it do
expect { should compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError, /error during compilation/)
end
Expand Down
12 changes: 7 additions & 5 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
end

describe 'with auto discovery address' do
let(:params) { { :autodiscoveryaddress => '255.255.255.0' } }
it { should contain_file(slave_runtime_file).with_content(/^AUTO_DISCOVERY_ADDRESS="255.255.255.0"$/) }
let(:params) { { :autodiscoveryaddress => '255.255.255.0' } }
it { should contain_file(slave_runtime_file).with_content(/^AUTO_DISCOVERY_ADDRESS="255.255.255.0"$/) }
end

describe 'slave_uid' do
Expand All @@ -54,9 +54,11 @@

describe 'with tool_locations' do
let(:params) { { :tool_locations => 'Python-2.7:/usr/bin/python2.7 Java-1.8:/usr/bin/java' } }
it { should contain_file(slave_runtime_file).
with_content(/--toolLocation Python-2.7=\/usr\/bin\/python2.7/).
with_content(/--toolLocation Java-1.8=\/usr\/bin\/java/) }
it do
should contain_file(slave_runtime_file).
with_content(/--toolLocation Python-2.7=\/usr\/bin\/python2.7/).
with_content(/--toolLocation Java-1.8=\/usr\/bin\/java/)
end
end

describe 'with a UI user/password' do
Expand Down
56 changes: 38 additions & 18 deletions spec/defines/jenkins_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,46 +110,62 @@
</xml>
eos

let(:params) {{ :ensure => 'present',
:config => unformatted_config }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(formatted_config) }
let(:params) do
{
:ensure => 'present',
:config => unformatted_config,
}
end
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(formatted_config)
end
end

describe 'with config with single quotes' do
quotes = "<xml version='1.0' encoding='UTF-8'></xml>"
let(:params) {{ :ensure => 'present', :config => quotes }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(/version="1\.0" encoding="UTF-8"/) }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(/version="1\.0" encoding="UTF-8"/)
end
end

describe 'with config with empty tags' do
empty_tags = '<xml><notempty><empty></empty></notempty><emptytwo></emptytwo></xml>'
let(:params) {{ :ensure => 'present', :config => empty_tags }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content('<xml><notempty><empty/></notempty><emptytwo/></xml>') }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content('<xml><notempty><empty/></notempty><emptytwo/></xml>')
end
end

describe 'with config with &quot;' do
quotes = "<config>the dog said &quot;woof&quot;</config>"
let(:params) {{ :ensure => 'present', :config => quotes }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content('<config>the dog said "woof"</config>') }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content('<config>the dog said "woof"</config>')
end
end

describe 'with sourced config and blank regular config' do
let(:thesource) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
let(:params) {{ :ensure => 'present', :source => thesource, :config => '' }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(/sourcedconfig/) }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(/sourcedconfig/)
end
end

describe 'with sourced config and regular config' do
quotes = "<xml version='1.0' encoding='UTF-8'></xml>"
let(:thesource) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
let(:params) {{ :ensure => 'present', :source => thesource, :config => quotes }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(/sourcedconfig/) }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(/sourcedconfig/)
end
end

describe 'with sourced config and no regular config' do
Expand All @@ -165,16 +181,20 @@
describe 'with templated config and blank regular config' do
let(:thetemplate) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
let(:params) {{ :ensure => 'present', :template => thetemplate, :config => '' }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(/sourcedconfig/) }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(/sourcedconfig/)
end
end

describe 'with templated config and regular config' do
quotes = "<xml version='1.0' encoding='UTF-8'></xml>"
let(:thetemplate) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
let(:params) {{ :ensure => 'present', :template => thetemplate, :config => quotes }}
it { should contain_file('/tmp/myjob-config.xml')\
.with_content(/sourcedconfig/) }
it do
should contain_file('/tmp/myjob-config.xml')
.with_content(/sourcedconfig/)
end
end

describe 'with templated config and no regular config' do
Expand Down
29 changes: 16 additions & 13 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
:cleanup => false,
:extract => false,
).that_requires("File[#{pdir}]")
.that_notifies('Service[jenkins]')
.that_notifies('Service[jenkins]')
end
it do
should contain_file("#{pdir}/#{title}.hpi").with(
:owner => 'jenkins',
:group => 'jenkins',
:mode => '0644',
).that_requires("Archive[#{title}.hpi]")
.that_comes_before('Service[jenkins]')
.that_comes_before('Service[jenkins]')
end
end

Expand Down Expand Up @@ -105,7 +105,7 @@
:group => 'jenkins',
:mode => '0644',
).that_requires("Archive[#{title}.hpi]")
.that_notifies('Service[jenkins]')
.that_notifies('Service[jenkins]')
end
end

Expand All @@ -122,12 +122,14 @@
end

describe 'with proxy' do
let(:pre_condition) { [
'class { jenkins:
proxy_host => "proxy.company.com",
proxy_port => 8080,
}',
]}
let(:pre_condition) do
<<-EOS
class { jenkins:
proxy_host => "proxy.company.com",
proxy_port => 8080,
}
EOS
end

it do
should contain_archive('myplug.hpi').with(
Expand Down Expand Up @@ -194,10 +196,10 @@
describe 'source' do
shared_examples 'should download from $source url' do
it 'should download from $source url' do
should contain_archive('myplug.hpi').with(
should contain_archive('myplug.hpi').with(
:source => 'http://e.org/myplug.hpi',
)
.that_requires("File[#{pdir}]")
.that_requires("File[#{pdir}]")
end
end

Expand Down Expand Up @@ -245,8 +247,9 @@
:ensure => 'file',
:owner => 'jenkins',
:group => 'jenkins',
).that_requires("Archive[foo.hpi]")
.that_notifies('Service[jenkins]')
)
.that_requires("Archive[foo.hpi]")
.that_notifies('Service[jenkins]')
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
shared_context 'jenkins' do
# rspec examples are not avaiable as variables to serverspec describe blocks
$libdir = case fact 'osfamily'
when 'RedHat'
'/usr/lib/jenkins'
when 'Debian'
'/usr/share/jenkins'
end
when 'RedHat'
'/usr/lib/jenkins'
when 'Debian'
'/usr/share/jenkins'
end

let(:libdir) { $libdir }

Expand Down
22 changes: 14 additions & 8 deletions spec/unit/puppet/type/jenkins_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@

it 'should support valid hexstrings' do
value = '51a8b1dd95bc76b1a2869356c043e8b9'
expect { described_class.new(
:name => 'nobody',
:api_token_plain => value
) }.to_not raise_error
expect {
described_class.new(
:name => 'nobody',
:api_token_plain => value
)
}
.to_not raise_error
end

%w[ 51a8b1dd95bc76b1a2869356c043e8b
51a8b1dd95bc76b1a2869356c043e8b99 ].each do |value|
it 'should reject hexstrings of invalid length' do
expect { described_class.new(
:name => 'nobody',
:api_token_plain => value
) }.to raise_error(Puppet::ResourceError, /is not a 32char hex string/)
expect {
described_class.new(
:name => 'nobody',
:api_token_plain => value,
)
}
.to raise_error(Puppet::ResourceError, /is not a 32char hex string/)
end
end
end #api_token_plain
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet_x/jenkins/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
describe "#[]" do
context 'unknown config key' do
it do
expect{described_class.new[:foo]}
.to raise_error(PuppetX::Jenkins::Config::UnknownConfig)
expect{described_class.new[:foo]}
.to raise_error(PuppetX::Jenkins::Config::UnknownConfig)
end
end # unknown config key

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet_x/jenkins/provider/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
before(:each) do
# clear class level state
if described_class.class_variable_defined?(:@@cli_auth_required)
described_class.class_variable_set(:@@cli_auth_required, false)
described_class.class_variable_set(:@@cli_auth_required, false)
end
end

Expand Down
Loading

0 comments on commit 03d7e23

Please sign in to comment.