Skip to content

Commit 1695e3a

Browse files
committed
(CONT-237) Rubocop - fixes for unit/acceptance
1 parent 8595402 commit 1695e3a

File tree

5 files changed

+57
-50
lines changed

5 files changed

+57
-50
lines changed

lib/puppetlabs_spec_helper/tasks/fixtures.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def fixtures(category)
140140
# rubocop:disable Security/Eval
141141
# TODO: Remove eval
142142
real_target = eval("\"#{opts['target']}\"", binding, __FILE__, __LINE__) # evaluating target reference in this context (see auto_symlink)
143-
real_source = eval("\"#{opts['repo']}\"", binding, __FILE__, __LINE__) # evaluating repo reference in this context (see auto_symlink)t
143+
real_source = eval("\"#{opts['repo']}\"", binding, __FILE__, __LINE__) # evaluating repo reference in this context (see auto_symlink)
144144

145145
result[real_source] = validate_fixture_hash!(
146146
'target' => File.join(real_target, fixture),

spec/acceptance/smoke_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
# some smoke tests to verify overall sanity
77
RSpec.describe 'rake' do
8-
before(:all) do
9-
@output, @status = Open3.capture2e('rake', '--rakefile', 'spec/acceptance/fixtures/Rakefile', '-T')
8+
let(:output) do
9+
Open3.capture2e('rake', '--rakefile', 'spec/acceptance/fixtures/Rakefile', '-T')
1010
end
1111

12-
it { expect(@output).to match %r{spec_prep} }
13-
it { expect(@status).to be_success }
12+
it { expect(output[0]).to match %r{spec_prep} }
13+
it { expect(output[1]).to be_success }
1414
end

spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
end
99

1010
describe '.scope' do
11-
let(:subject) { described_class.scope }
11+
subject(:scope) { described_class.scope }
1212

1313
it 'returns a Puppet::Parser::Scope instance' do
14-
expect(subject).to be_a_kind_of Puppet::Parser::Scope
14+
expect(scope).to be_a_kind_of Puppet::Parser::Scope
1515
end
1616

1717
it 'is suitable for function testing' do
18-
expect(subject.function_inline_template(['foo'])).to eq('foo')
18+
expect(scope.function_inline_template(['foo'])).to eq('foo')
1919
end
2020

2121
it 'accepts a compiler' do
@@ -25,29 +25,28 @@
2525
end
2626

2727
it 'has a source set' do
28-
scope = subject
2928
expect(scope.source).not_to be_nil
3029
expect(scope.source.name).to eq('foo')
3130
end
3231
end
3332

3433
describe '.resource' do
35-
let(:subject) { described_class.resource }
34+
subject(:resource) { described_class.resource }
3635

3736
it 'can have a defined type' do
3837
expect(described_class.resource(type: :node).type).to eq(:node)
3938
end
4039

4140
it 'defaults to a type of hostclass' do
42-
expect(subject.type).to eq(:hostclass)
41+
expect(resource.type).to eq(:hostclass)
4342
end
4443

4544
it 'can have a defined name' do
4645
expect(described_class.resource(name: 'testingrsrc').name).to eq('testingrsrc')
4746
end
4847

4948
it 'defaults to a name of testing' do
50-
expect(subject.name).to eq('testing')
49+
expect(resource.name).to eq('testing')
5150
end
5251
end
5352

@@ -82,14 +81,14 @@
8281
describe '.function_method' do
8382
it 'accepts an injected scope' do
8483
expect(Puppet::Parser::Functions).to receive(:function).with('my_func').and_return(true)
85-
scope = double(described_class.scope)
84+
scope = instance_double(described_class.scope.to_s)
8685
expect(scope).to receive(:method).with(:function_my_func).and_return(:fake_method)
8786
expect(described_class.function_method('my_func', scope: scope)).to eq(:fake_method)
8887
end
8988

9089
it "returns nil if the function doesn't exist" do
9190
expect(Puppet::Parser::Functions).to receive(:function).with('my_func').and_return(false)
92-
scope = double(described_class.scope)
91+
scope = instance_double(described_class.scope.to_s)
9392
expect(described_class.function_method('my_func', scope: scope)).to be_nil
9493
end
9594
end

spec/unit/puppetlabs_spec_helper/tasks/fixtures_spec.rb

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
end
8585

8686
describe '.fixtures' do
87+
subject(:helper) { described_class }
88+
8789
before :each do
8890
# Unstub the fixtures "helpers"
8991
PuppetlabsSpec::Fixtures.instance_methods.each do |m|
@@ -98,48 +100,50 @@
98100

99101
context 'when file is missing' do
100102
it 'returns basic directories per category' do
101-
expect(subject.fixtures('forge_modules')).to eq({})
102-
expect(subject.fixtures('repositories')).to eq({})
103+
expect(helper.fixtures('forge_modules')).to eq({})
104+
expect(helper.fixtures('repositories')).to eq({})
103105
end
104106
end
105107

106108
context 'when file is empty' do
107109
it 'returns basic directories per category' do
108110
allow(File).to receive(:exist?).with('.fixtures.yml').and_return true
109111
allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return false
110-
expect(subject.fixtures('forge_modules')).to eq({})
111-
expect(subject.fixtures('repositories')).to eq({})
112+
expect(helper.fixtures('forge_modules')).to eq({})
113+
expect(helper.fixtures('repositories')).to eq({})
112114
end
113115
end
114116

115117
context 'when file is malformed' do
116118
it 'raises an error' do
117119
expect(File).to receive(:exist?).with('.fixtures.yml').and_return true
118120
expect(YAML).to receive(:load_file).with('.fixtures.yml').and_raise(Psych::SyntaxError.new('/file', '123', '0', '0', 'spec message', 'spec context'))
119-
expect { subject.fixtures('forge_modules') }.to raise_error(RuntimeError, %r{malformed YAML})
121+
expect { helper.fixtures('forge_modules') }.to raise_error(RuntimeError, %r{malformed YAML})
120122
end
121123
end
122124

123125
context 'when file contains no fixtures' do
124126
it 'raises an error' do
125127
allow(File).to receive(:exist?).with('.fixtures.yml').and_return true
126128
allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return('some' => 'key')
127-
expect { subject.fixtures('forge_modules') }.to raise_error(RuntimeError, %r{No 'fixtures'})
129+
expect { helper.fixtures('forge_modules') }.to raise_error(RuntimeError, %r{No 'fixtures'})
128130
end
129131
end
130132

131133
context 'when file specifies fixtures' do
132134
it 'returns the hash' do
133135
allow(File).to receive(:exist?).with('.fixtures.yml').and_return true
134136
allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return('fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib' } })
135-
expect(subject.fixtures('forge_modules')).to eq('puppetlabs-stdlib' => {
136-
'target' => 'spec/fixtures/modules/stdlib',
137-
'ref' => nil,
138-
'branch' => nil,
139-
'scm' => nil,
140-
'flags' => nil,
141-
'subdir' => nil,
142-
})
137+
expect(helper.fixtures('forge_modules')).to eq(
138+
'puppetlabs-stdlib' => {
139+
'target' => 'spec/fixtures/modules/stdlib',
140+
'ref' => nil,
141+
'branch' => nil,
142+
'scm' => nil,
143+
'flags' => nil,
144+
'subdir' => nil,
145+
},
146+
)
143147
end
144148
end
145149

@@ -148,14 +152,16 @@
148152
allow(File).to receive(:exist?).with('.fixtures.yml').and_return true
149153
allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return('defaults' => { 'forge_modules' => { 'flags' => '--module_repository=https://myforge.example.com/' } },
150154
'fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib' } })
151-
expect(subject.fixtures('forge_modules')).to eq('puppetlabs-stdlib' => {
152-
'target' => 'spec/fixtures/modules/stdlib',
153-
'ref' => nil,
154-
'branch' => nil,
155-
'scm' => nil,
156-
'flags' => '--module_repository=https://myforge.example.com/',
157-
'subdir' => nil,
158-
})
155+
expect(helper.fixtures('forge_modules')).to eq(
156+
'puppetlabs-stdlib' => {
157+
'target' => 'spec/fixtures/modules/stdlib',
158+
'ref' => nil,
159+
'branch' => nil,
160+
'scm' => nil,
161+
'flags' => '--module_repository=https://myforge.example.com/',
162+
'subdir' => nil,
163+
},
164+
)
159165
end
160166
end
161167

@@ -170,14 +176,16 @@
170176
end
171177

172178
it 'returns the hash' do
173-
expect(subject.repositories).to eq('https://github.com/puppetlabs/puppetlabs-stdlib.git' => {
174-
'target' => 'spec/fixtures/modules/stdlib',
175-
'ref' => nil,
176-
'branch' => nil,
177-
'scm' => nil,
178-
'flags' => nil,
179-
'subdir' => nil,
180-
})
179+
expect(helper.repositories).to eq(
180+
'https://github.com/puppetlabs/puppetlabs-stdlib.git' => {
181+
'target' => 'spec/fixtures/modules/stdlib',
182+
'ref' => nil,
183+
'branch' => nil,
184+
'scm' => nil,
185+
'flags' => nil,
186+
'subdir' => nil,
187+
},
188+
)
181189
end
182190
end
183191

@@ -198,7 +206,7 @@
198206
end
199207

200208
it 'raises an ArgumentError' do
201-
expect { subject.fixtures('repositories') }.to raise_error(ArgumentError)
209+
expect { helper.fixtures('repositories') }.to raise_error(ArgumentError)
202210
end
203211
end
204212

@@ -219,7 +227,7 @@ def stub_fixtures(data)
219227
},
220228
},
221229
)
222-
expect(subject.fixtures('forge_modules')).to include('puppetlabs-stdlib')
230+
expect(helper.fixtures('forge_modules')).to include('puppetlabs-stdlib')
223231
end
224232

225233
it 'excludes the fixture if the puppet version does not match', if: Gem::Version.new(Puppet::PUPPETVERSION) > Gem::Version.new('4') do
@@ -233,7 +241,7 @@ def stub_fixtures(data)
233241
},
234242
},
235243
)
236-
expect(subject.fixtures('forge_modules')).to eq({})
244+
expect(helper.fixtures('forge_modules')).to eq({})
237245
end
238246

239247
it 'includes the fixture on obsolete puppet versions', if: Gem::Version.new(Puppet::PUPPETVERSION) <= Gem::Version.new('4') do
@@ -247,7 +255,7 @@ def stub_fixtures(data)
247255
},
248256
},
249257
)
250-
expect(subject.fixtures('forge_modules')).to include('puppetlabs-stdlib')
258+
expect(helper.fixtures('forge_modules')).to include('puppetlabs-stdlib')
251259
end
252260
end
253261
end

spec/watchr.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def growl(message)
1414
(Regexp.last_match(1).to_i == 0) ? '~/.watchr_images/passed.png' : '~/.watchr_images/failed.png'
1515
else
1616
'~/.watchr_images/unknown.png'
17-
end
17+
end
1818
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
1919
system %(#{growlnotify} #{options} &)
2020
end
@@ -35,7 +35,7 @@ def run_spec_test(file)
3535
end
3636

3737
def filter_rspec(data)
38-
data.split("\n").find_all { |l|
38+
data.split("\n").select { |l|
3939
l =~ %r{^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending}
4040
}.join("\n")
4141
end

0 commit comments

Comments
 (0)