Skip to content

Commit 1175ccd

Browse files
authored
Merge pull request #56 from puppetlabs/maint-spec_rubocop_updates
(MAINT) Rubocop updates for spec
2 parents 683ecb5 + 6f33546 commit 1175ccd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1577
-1581
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,5 @@ Style/RedundantArgument:
518518
Enabled: false
519519
Style/SwapValues:
520520
Enabled: false
521+
RSpec/FilePath:
522+
Enabled: false

spec/puppet-lint/bin_spec.rb

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def initialize(args)
2626
end
2727

2828
describe PuppetLint::Bin do
29-
subject do
29+
subject(:bin) do
3030
sane_args = if args.is_a?(Array)
3131
args
3232
else
@@ -57,18 +57,19 @@ def initialize(args)
5757

5858
context 'when asked to display available checks' do
5959
let(:args) { '--list-checks' }
60+
6061
all_checks = PuppetLint.configuration.checks.map(&:to_s)
6162

6263
its(:exitstatus) { is_expected.to eq(0) }
6364

6465
all_checks.each do |c|
6566
it "includes check #{c} in its output" do
66-
expect(subject.stdout).to include c
67+
expect(bin.stdout).to include c
6768
end
6869
end
6970
end
7071

71-
context 'when passed a backslash separated path on Windows', :if => Gem.win_platform? do
72+
context 'when passed a backslash separated path on Windows', if: Gem.win_platform? do
7273
let(:args) do
7374
[
7475
'spec\fixtures\test\manifests',
@@ -93,7 +94,7 @@ def initialize(args)
9394
[
9495
"#{args[0]} - WARNING: optional parameter listed before required parameter on line 2 (check: parameter_order)",
9596
"#{args[1]} - ERROR: test::foo not in autoload module layout on line 2 (check: autoloader_layout)",
96-
].join("\n")
97+
].join("\n"),
9798
)
9899
end
99100
end
@@ -144,8 +145,10 @@ def initialize(args)
144145
end
145146

146147
its(:exitstatus) { is_expected.to eq(1) }
147-
its(:stdout) { is_expected.to match(%r{WARNING}) }
148-
its(:stdout) { is_expected.to_not match(%r{ERROR}) }
148+
its(:stdout) do
149+
is_expected.to match(%r{WARNING})
150+
is_expected.not_to match(%r{ERROR})
151+
end
149152
end
150153

151154
context 'when specifying a specific check to run' do
@@ -159,8 +162,10 @@ def initialize(args)
159162
end
160163

161164
its(:exitstatus) { is_expected.to eq(0) }
162-
its(:stdout) { is_expected.to_not match(%r{ERROR}) }
163-
its(:stdout) { is_expected.to match(%r{WARNING}) }
165+
its(:stdout) do
166+
is_expected.not_to match(%r{ERROR})
167+
is_expected.to match(%r{WARNING})
168+
end
164169
end
165170

166171
context 'when asked to display filenames ' do
@@ -202,7 +207,7 @@ def initialize(args)
202207
'',
203208
" define test::warning($foo='bar', $baz) { }",
204209
' ^',
205-
].join("\n")
210+
].join("\n"),
206211
)
207212
end
208213
end
@@ -440,7 +445,7 @@ def initialize(args)
440445
end
441446

442447
its(:exitstatus) { is_expected.to eq(0) }
443-
its(:stdout) { is_expected.to_not match(%r{IGNORED}) }
448+
its(:stdout) { is_expected.not_to match(%r{IGNORED}) }
444449
end
445450

446451
context 'when showing ignored problems' do
@@ -469,7 +474,7 @@ def initialize(args)
469474
[
470475
'IGNORED: double quoted string containing no variables on line 3 (check: double_quoted_strings)',
471476
' for a good reason',
472-
].join("\n")
477+
].join("\n"),
473478
)
474479
end
475480
end
@@ -517,44 +522,48 @@ def initialize(args)
517522
end
518523

519524
context 'when fixing a file with \n line endings' do
520-
before(:context) do
521-
@windows_file = Tempfile.new('windows')
522-
@posix_file = Tempfile.new('posix')
523-
524-
@windows_file.binmode
525-
@posix_file.binmode
526-
527-
@windows_file.write("\r\n")
528-
@posix_file.write("\n")
529-
530-
@windows_file.close
531-
@posix_file.close
525+
let(:windows_file) do
526+
Tempfile.new('windows')
532527
end
533528

534-
after(:context) do
535-
@windows_file.unlink
536-
@posix_file.unlink
529+
let(:posix_file) do
530+
Tempfile.new('posix')
537531
end
538532

539533
let(:args) do
540534
[
541535
'--fix',
542-
@posix_file.path,
543-
@windows_file.path,
536+
posix_file.path,
537+
windows_file.path,
544538
]
545539
end
546540

541+
before(:each) do
542+
windows_file.binmode
543+
windows_file.write("\r\n")
544+
windows_file.close
545+
546+
posix_file.binmode
547+
posix_file.write("\n")
548+
posix_file.close
549+
end
550+
551+
after(:each) do
552+
windows_file.unlink
553+
posix_file.unlink
554+
end
555+
547556
its(:exitstatus) { is_expected.to eq(0) }
548557

549558
it 'does not change the line endings' do
550-
File.open(@posix_file.path, 'rb') do |f|
559+
File.open(posix_file.path, 'rb') do |f|
551560
data = f.read
552561

553562
expect(data).to match(%r{\n\Z}m)
554-
expect(data).to_not match(%r{\r\n\Z}m)
563+
expect(data).not_to match(%r{\r\n\Z}m)
555564
end
556565

557-
File.open(@windows_file.path, 'rb') do |f|
566+
File.open(windows_file.path, 'rb') do |f|
558567
data = f.read
559568

560569
expect(data).to match(%r{\r\n\Z}m)

spec/puppet-lint/checks_spec.rb

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
let(:content) { "notify { 'test': }" }
88

99
describe '#initialize' do
10-
it { is_expected.to have_attributes(:problems => []) }
10+
it { is_expected.to have_attributes(problems: []) }
1111
end
1212

1313
describe '#load_data' do
1414
let(:lexer) { PuppetLint::Lexer.new }
1515

16-
before do
16+
before(:each) do
1717
allow(PuppetLint::Lexer).to receive(:new).and_return(lexer)
1818
end
1919

2020
context 'when the tokeniser encounters an error' do
21-
before do
21+
before(:each) do
2222
allow(lexer).to receive(:tokenise).with(content).and_raise(lexer_error)
2323
instance.load_data(path, content)
2424
end
@@ -33,14 +33,14 @@
3333
it 'creates a syntax error problem for the file' do
3434
expect(instance.problems).to have(1).problem
3535
expect(instance.problems.first).to include(
36-
:kind => :error,
37-
:check => :syntax,
38-
:message => 'Syntax error',
39-
:line => 1,
40-
:column => 2,
41-
:path => anything,
42-
:fullpath => anything,
43-
:filename => anything
36+
kind: :error,
37+
check: :syntax,
38+
message: 'Syntax error',
39+
line: 1,
40+
column: 2,
41+
path: anything,
42+
fullpath: anything,
43+
filename: anything,
4444
)
4545
end
4646
end
@@ -55,14 +55,14 @@
5555
it 'creates a syntax error problem for the file' do
5656
expect(instance.problems).to have(1).problem
5757
expect(instance.problems.first).to include(
58-
:kind => :error,
59-
:check => :syntax,
60-
:message => 'Syntax error (some reason)',
61-
:line => 1,
62-
:column => 2,
63-
:path => anything,
64-
:fullpath => anything,
65-
:filename => anything
58+
kind: :error,
59+
check: :syntax,
60+
message: 'Syntax error (some reason)',
61+
line: 1,
62+
column: 2,
63+
path: anything,
64+
fullpath: anything,
65+
filename: anything,
6666
)
6767
end
6868
end
@@ -74,12 +74,12 @@
7474
let(:data) { "notify { 'test': }" }
7575
let(:enabled_checks) { [] }
7676

77-
before do
78-
allow(instance).to receive(:enabled_checks).and_return(enabled_checks)
77+
before(:each) do
78+
allow(instance).to receive(:enabled_checks).and_return(enabled_checks) # rubocop: disable RSpec/SubjectStub
7979
end
8080

8181
it 'loads the manifest data' do
82-
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original
82+
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original # rubocop: disable RSpec/SubjectStub
8383
instance.run(fileinfo, data)
8484
end
8585

@@ -98,7 +98,7 @@
9898
it 'does not run the disabled checks' do
9999
# expect().to_not all(matcher) is not supported
100100
disabled_check_classes.each do |check_class|
101-
expect(check_class).to_not receive(:new)
101+
expect(check_class).not_to receive(:new)
102102
end
103103

104104
instance.run(fileinfo, data)
@@ -110,12 +110,12 @@
110110
let(:mock_arrow_alignment) do
111111
instance_double(
112112
PuppetLint::CheckPlugin,
113-
:run => [{ :kind => :error, :check => :arrow_alignment }],
114-
:fix_problems => [{ :kind => :fixed, :check => :arrow_alignment }]
113+
run: [{ kind: :error, check: :arrow_alignment }],
114+
fix_problems: [{ kind: :fixed, check: :arrow_alignment }],
115115
)
116116
end
117117
let(:mock_hard_tabs) do
118-
instance_double(PuppetLint::CheckPlugin, :run => [], :fix_problems => [])
118+
instance_double(PuppetLint::CheckPlugin, run: [], fix_problems: [])
119119
end
120120
let(:fix_state) { false }
121121

@@ -127,22 +127,22 @@
127127
end
128128

129129
it 'adds the found problems to the problems array' do
130-
expect(instance).to have_attributes(:problems => [{ :kind => :error, :check => :arrow_alignment }])
130+
expect(instance).to have_attributes(problems: [{ kind: :error, check: :arrow_alignment }])
131131
end
132132

133133
context 'and fix is enabled' do
134134
let(:fix_state) { true }
135135

136136
it 'calls #fix_problems on the check and adds the results to the problems array' do
137-
expect(instance).to have_attributes(:problems => [{ :kind => :fixed, :check => :arrow_alignment }])
137+
expect(instance).to have_attributes(problems: [{ kind: :fixed, check: :arrow_alignment }])
138138
end
139139
end
140140
end
141141
end
142142

143143
context 'when an unhandled exception is raised' do
144-
before do
145-
allow(instance).to receive(:load_data).with(fileinfo, data).and_raise(StandardError.new('test message'))
144+
before(:each) do
145+
allow(instance).to receive(:load_data).with(fileinfo, data).and_raise(StandardError.new('test message')) # rubocop: disable RSpec/SubjectStub
146146
allow($stdout).to receive(:puts).with(anything)
147147
end
148148

@@ -173,7 +173,7 @@
173173
end
174174

175175
context 'and the file being linted is readable' do
176-
before do
176+
before(:each) do
177177
allow(File).to receive(:readable?).with(fileinfo).and_return(true)
178178
allow(File).to receive(:read).with(fileinfo).and_return(data)
179179
end
@@ -196,7 +196,7 @@
196196

197197
let(:expected_enabled_checks) { [:arrow_alignment, :trailing_whitespace] }
198198

199-
before do
199+
before(:each) do
200200
PuppetLint.configuration.checks.each do |check|
201201
allow(PuppetLint.configuration).to receive("#{check}_enabled?").and_return(expected_enabled_checks.include?(check))
202202
end
@@ -212,13 +212,13 @@
212212

213213
let(:tokens) do
214214
[
215-
instance_double(PuppetLint::Lexer::Token, :to_manifest => '1'),
216-
instance_double(PuppetLint::Lexer::Token, :to_manifest => '2'),
217-
instance_double(PuppetLint::Lexer::Token, :to_manifest => '3'),
215+
instance_double(PuppetLint::Lexer::Token, to_manifest: '1'),
216+
instance_double(PuppetLint::Lexer::Token, to_manifest: '2'),
217+
instance_double(PuppetLint::Lexer::Token, to_manifest: '3'),
218218
]
219219
end
220220

221-
before do
221+
before(:each) do
222222
allow(PuppetLint::Data).to receive(:tokens).and_return(tokens)
223223
end
224224

0 commit comments

Comments
 (0)