|
7 | 7 | let(:content) { "notify { 'test': }" } |
8 | 8 |
|
9 | 9 | describe '#initialize' do |
10 | | - it { is_expected.to have_attributes(:problems => []) } |
| 10 | + it { is_expected.to have_attributes(problems: []) } |
11 | 11 | end |
12 | 12 |
|
13 | 13 | describe '#load_data' do |
14 | 14 | let(:lexer) { PuppetLint::Lexer.new } |
15 | 15 |
|
16 | | - before do |
| 16 | + before(:each) do |
17 | 17 | allow(PuppetLint::Lexer).to receive(:new).and_return(lexer) |
18 | 18 | end |
19 | 19 |
|
20 | 20 | context 'when the tokeniser encounters an error' do |
21 | | - before do |
| 21 | + before(:each) do |
22 | 22 | allow(lexer).to receive(:tokenise).with(content).and_raise(lexer_error) |
23 | 23 | instance.load_data(path, content) |
24 | 24 | end |
|
33 | 33 | it 'creates a syntax error problem for the file' do |
34 | 34 | expect(instance.problems).to have(1).problem |
35 | 35 | 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, |
44 | 44 | ) |
45 | 45 | end |
46 | 46 | end |
|
55 | 55 | it 'creates a syntax error problem for the file' do |
56 | 56 | expect(instance.problems).to have(1).problem |
57 | 57 | 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, |
66 | 66 | ) |
67 | 67 | end |
68 | 68 | end |
|
74 | 74 | let(:data) { "notify { 'test': }" } |
75 | 75 | let(:enabled_checks) { [] } |
76 | 76 |
|
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 |
79 | 79 | end |
80 | 80 |
|
81 | 81 | 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 |
83 | 83 | instance.run(fileinfo, data) |
84 | 84 | end |
85 | 85 |
|
|
98 | 98 | it 'does not run the disabled checks' do |
99 | 99 | # expect().to_not all(matcher) is not supported |
100 | 100 | disabled_check_classes.each do |check_class| |
101 | | - expect(check_class).to_not receive(:new) |
| 101 | + expect(check_class).not_to receive(:new) |
102 | 102 | end |
103 | 103 |
|
104 | 104 | instance.run(fileinfo, data) |
|
110 | 110 | let(:mock_arrow_alignment) do |
111 | 111 | instance_double( |
112 | 112 | 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 }], |
115 | 115 | ) |
116 | 116 | end |
117 | 117 | let(:mock_hard_tabs) do |
118 | | - instance_double(PuppetLint::CheckPlugin, :run => [], :fix_problems => []) |
| 118 | + instance_double(PuppetLint::CheckPlugin, run: [], fix_problems: []) |
119 | 119 | end |
120 | 120 | let(:fix_state) { false } |
121 | 121 |
|
|
127 | 127 | end |
128 | 128 |
|
129 | 129 | 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 }]) |
131 | 131 | end |
132 | 132 |
|
133 | 133 | context 'and fix is enabled' do |
134 | 134 | let(:fix_state) { true } |
135 | 135 |
|
136 | 136 | 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 }]) |
138 | 138 | end |
139 | 139 | end |
140 | 140 | end |
141 | 141 | end |
142 | 142 |
|
143 | 143 | 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 |
146 | 146 | allow($stdout).to receive(:puts).with(anything) |
147 | 147 | end |
148 | 148 |
|
|
173 | 173 | end |
174 | 174 |
|
175 | 175 | context 'and the file being linted is readable' do |
176 | | - before do |
| 176 | + before(:each) do |
177 | 177 | allow(File).to receive(:readable?).with(fileinfo).and_return(true) |
178 | 178 | allow(File).to receive(:read).with(fileinfo).and_return(data) |
179 | 179 | end |
|
196 | 196 |
|
197 | 197 | let(:expected_enabled_checks) { [:arrow_alignment, :trailing_whitespace] } |
198 | 198 |
|
199 | | - before do |
| 199 | + before(:each) do |
200 | 200 | PuppetLint.configuration.checks.each do |check| |
201 | 201 | allow(PuppetLint.configuration).to receive("#{check}_enabled?").and_return(expected_enabled_checks.include?(check)) |
202 | 202 | end |
|
212 | 212 |
|
213 | 213 | let(:tokens) do |
214 | 214 | [ |
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'), |
218 | 218 | ] |
219 | 219 | end |
220 | 220 |
|
221 | | - before do |
| 221 | + before(:each) do |
222 | 222 | allow(PuppetLint::Data).to receive(:tokens).and_return(tokens) |
223 | 223 | end |
224 | 224 |
|
|
0 commit comments