guard-rubocop 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Rakefile +9 -1
- data/guard-rubocop.gemspec +1 -1
- data/lib/guard/rubocop.rb +3 -0
- data/lib/guard/rubocop/runner.rb +2 -2
- data/lib/guard/rubocop/version.rb +1 -1
- data/spec/guard/rubocop/runner_spec.rb +45 -53
- data/spec/guard/rubocop_spec.rb +87 -41
- data/spec/spec_helper.rb +5 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df888e087c9fd9f43ae488326b28cdacc0590e04
|
4
|
+
data.tar.gz: 4f1e983579323bcddb9de6679c00d84a1342f345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64a073b7cb937839c493b97380185a3e286dc6cc41e741c662ae02231ec633ccf76484edc9382707eb29a0698d656405bf0b7025da87ab4f237f4a8e9d05d6ef
|
7
|
+
data.tar.gz: 9c8e163eb4a1e510adf4dab87b370ec9a59e4acaac16ff32e252beb450852099cf0e1cb80edf95b61e2bfe72c51fa5ef46bdfef484279bf9d58ddb2343776d7a
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -15,4 +15,12 @@ namespace :ci do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
desc 'Check code style with RuboCop'
|
19
|
+
task :style do
|
20
|
+
sh('rubocop')
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Run RSpec code examples and check code style with RuboCop'
|
24
|
+
task all: [:spec, :style]
|
25
|
+
|
26
|
+
task default: :all
|
data/guard-rubocop.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
-
spec.add_development_dependency 'rspec', '~> 2.
|
28
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
29
29
|
spec.add_development_dependency 'simplecov', '~> 0.7'
|
30
30
|
spec.add_development_dependency 'guard-rspec', '~> 3.0'
|
31
31
|
spec.add_development_dependency 'ruby_gntp', '~> 0.3'
|
data/lib/guard/rubocop.rb
CHANGED
@@ -37,6 +37,8 @@ module Guard
|
|
37
37
|
paths += @failed_paths if @options[:keep_failed]
|
38
38
|
paths = clean_paths(paths)
|
39
39
|
|
40
|
+
return if paths.empty?
|
41
|
+
|
40
42
|
displayed_paths = paths.map { |path| smart_path(path) }
|
41
43
|
UI.info "Inspecting Ruby code style: #{displayed_paths.join(' ')}"
|
42
44
|
|
@@ -52,6 +54,7 @@ module Guard
|
|
52
54
|
paths.map! { |path| File.expand_path(path) }
|
53
55
|
paths.uniq!
|
54
56
|
paths.reject! do |path|
|
57
|
+
next true unless File.exists?(path)
|
55
58
|
included_in_other_path?(path, paths)
|
56
59
|
end
|
57
60
|
paths
|
data/lib/guard/rubocop/runner.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
# rubocop:disable Documentation
|
6
|
-
|
7
6
|
module Guard
|
8
7
|
class Rubocop
|
9
8
|
# This class runs `rubocop` command, retrieves result and notifies.
|
@@ -11,6 +10,7 @@ module Guard
|
|
11
10
|
class Runner
|
12
11
|
# rubocop:enable Documentation
|
13
12
|
|
13
|
+
#
|
14
14
|
def initialize(options)
|
15
15
|
@options = options
|
16
16
|
end
|
@@ -69,7 +69,7 @@ module Guard
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def json_file_path
|
72
|
-
@
|
72
|
+
@json_file_path ||= begin
|
73
73
|
# Just generate random tempfile path.
|
74
74
|
basename = self.class.name.downcase.gsub('::', '_')
|
75
75
|
tempfile = Tempfile.new(basename)
|
@@ -11,40 +11,40 @@ describe Guard::Rubocop::Runner do
|
|
11
11
|
let(:paths) { ['spec/spec_helper.rb'] }
|
12
12
|
|
13
13
|
before do
|
14
|
-
runner.
|
14
|
+
allow(runner).to receive(:system)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'executes rubocop' do
|
18
|
-
runner.
|
19
|
-
args.first.
|
18
|
+
expect(runner).to receive(:system) do |*args|
|
19
|
+
expect(args.first).to eq('rubocop')
|
20
20
|
end
|
21
21
|
runner.run
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'when RuboCop exited with 0 status' do
|
25
25
|
before do
|
26
|
-
runner.
|
26
|
+
allow(runner).to receive(:system).and_return(true)
|
27
27
|
end
|
28
28
|
it { should be_true }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when RuboCop exited with non 0 status' do
|
32
32
|
before do
|
33
|
-
runner.
|
33
|
+
allow(runner).to receive(:system).and_return(false)
|
34
34
|
end
|
35
35
|
it { should be_false }
|
36
36
|
end
|
37
37
|
|
38
38
|
shared_examples 'notifies', :notifies do
|
39
39
|
it 'notifies' do
|
40
|
-
runner.
|
40
|
+
expect(runner).to receive(:notify)
|
41
41
|
runner.run
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
shared_examples 'does not notify', :does_not_notify do
|
46
46
|
it 'does not notify' do
|
47
|
-
runner.
|
47
|
+
expect(runner).not_to receive(:notify)
|
48
48
|
runner.run
|
49
49
|
end
|
50
50
|
end
|
@@ -52,7 +52,7 @@ describe Guard::Rubocop::Runner do
|
|
52
52
|
shared_examples 'notification' do |expectations|
|
53
53
|
context 'when passed' do
|
54
54
|
before do
|
55
|
-
runner.
|
55
|
+
allow(runner).to receive(:system).and_return(true)
|
56
56
|
end
|
57
57
|
|
58
58
|
if expectations[:passed]
|
@@ -64,7 +64,7 @@ describe Guard::Rubocop::Runner do
|
|
64
64
|
|
65
65
|
context 'when failed' do
|
66
66
|
before do
|
67
|
-
runner.
|
67
|
+
allow(runner).to receive(:system).and_return(false)
|
68
68
|
end
|
69
69
|
|
70
70
|
if expectations[:failed]
|
@@ -100,7 +100,7 @@ describe Guard::Rubocop::Runner do
|
|
100
100
|
let(:options) { { cli: %w(--format simple) } }
|
101
101
|
|
102
102
|
it 'does not add args for the default formatter for console' do
|
103
|
-
build_command[0..2].
|
103
|
+
expect(build_command[0..2]).not_to eq(%w(rubocop --format progress))
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -108,33 +108,25 @@ describe Guard::Rubocop::Runner do
|
|
108
108
|
let(:options) { { cli: %w(--format simple --out simple.txt) } }
|
109
109
|
|
110
110
|
it 'adds args for the default formatter for console' do
|
111
|
-
build_command[0..2].
|
111
|
+
expect(build_command[0..2]).to eq(%w(rubocop --format progress))
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'adds args for JSON formatter ' do
|
116
|
-
build_command[3..4].
|
116
|
+
expect(build_command[3..4]).to eq(%w(--format json))
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'adds args for output file path of JSON formatter ' do
|
120
|
-
build_command[5].
|
121
|
-
build_command[6].
|
120
|
+
expect(build_command[5]).to eq('--out')
|
121
|
+
expect(build_command[6]).not_to be_empty
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'adds args specified by user' do
|
125
|
-
build_command[7..8].
|
125
|
+
expect(build_command[7..8]).to eq(%w(--debug --rails))
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'adds the passed paths' do
|
129
|
-
build_command[9..-1].
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'when the value of :cli option is a string' do
|
133
|
-
let(:options) { { cli: '--debug --rails' } }
|
134
|
-
|
135
|
-
it 'handles' do
|
136
|
-
build_command[7..8].should == %w(--debug --rails)
|
137
|
-
end
|
129
|
+
expect(build_command[9..-1]).to eq(%w(file1.rb file2.rb))
|
138
130
|
end
|
139
131
|
end
|
140
132
|
|
@@ -143,7 +135,7 @@ describe Guard::Rubocop::Runner do
|
|
143
135
|
let(:options) { { cli: nil } }
|
144
136
|
|
145
137
|
it 'returns empty array' do
|
146
|
-
runner.args_specified_by_user.
|
138
|
+
expect(runner.args_specified_by_user).to eq([])
|
147
139
|
end
|
148
140
|
end
|
149
141
|
|
@@ -151,7 +143,7 @@ describe Guard::Rubocop::Runner do
|
|
151
143
|
let(:options) { { cli: ['--out', 'output file.txt'] } }
|
152
144
|
|
153
145
|
it 'just returns the array' do
|
154
|
-
runner.args_specified_by_user.
|
146
|
+
expect(runner.args_specified_by_user).to eq(['--out', 'output file.txt'])
|
155
147
|
end
|
156
148
|
end
|
157
149
|
|
@@ -159,7 +151,7 @@ describe Guard::Rubocop::Runner do
|
|
159
151
|
let(:options) { { cli: '--out "output file.txt"' } }
|
160
152
|
|
161
153
|
it 'returns an array from String#shellsplit' do
|
162
|
-
runner.args_specified_by_user.
|
154
|
+
expect(runner.args_specified_by_user).to eq(['--out', 'output file.txt'])
|
163
155
|
end
|
164
156
|
end
|
165
157
|
|
@@ -180,7 +172,7 @@ describe Guard::Rubocop::Runner do
|
|
180
172
|
let(:args) { %w(--format simple --debug) }
|
181
173
|
|
182
174
|
it 'returns true' do
|
183
|
-
include_formatter_for_console
|
175
|
+
expect(include_formatter_for_console?).to be_true
|
184
176
|
end
|
185
177
|
end
|
186
178
|
|
@@ -188,7 +180,7 @@ describe Guard::Rubocop::Runner do
|
|
188
180
|
let(:args) { %w(--format simple --out simple.txt) }
|
189
181
|
|
190
182
|
it 'returns false' do
|
191
|
-
include_formatter_for_console
|
183
|
+
expect(include_formatter_for_console?).to be_false
|
192
184
|
end
|
193
185
|
end
|
194
186
|
|
@@ -196,7 +188,7 @@ describe Guard::Rubocop::Runner do
|
|
196
188
|
let(:args) { %w(--format simple --debug --out simple.txt) }
|
197
189
|
|
198
190
|
it 'returns false' do
|
199
|
-
include_formatter_for_console
|
191
|
+
expect(include_formatter_for_console?).to be_false
|
200
192
|
end
|
201
193
|
end
|
202
194
|
end
|
@@ -206,7 +198,7 @@ describe Guard::Rubocop::Runner do
|
|
206
198
|
let(:args) { %w(--format simple --out simple.txt --format emacs --out emacs.txt) }
|
207
199
|
|
208
200
|
it 'returns false' do
|
209
|
-
include_formatter_for_console
|
201
|
+
expect(include_formatter_for_console?).to be_false
|
210
202
|
end
|
211
203
|
end
|
212
204
|
|
@@ -214,7 +206,7 @@ describe Guard::Rubocop::Runner do
|
|
214
206
|
let(:args) { %w(--format simple --format emacs --out emacs.txt) }
|
215
207
|
|
216
208
|
it 'returns true' do
|
217
|
-
include_formatter_for_console
|
209
|
+
expect(include_formatter_for_console?).to be_true
|
218
210
|
end
|
219
211
|
end
|
220
212
|
|
@@ -222,7 +214,7 @@ describe Guard::Rubocop::Runner do
|
|
222
214
|
let(:args) { %w(--format simple --format emacs) }
|
223
215
|
|
224
216
|
it 'returns true' do
|
225
|
-
include_formatter_for_console
|
217
|
+
expect(include_formatter_for_console?).to be_true
|
226
218
|
end
|
227
219
|
end
|
228
220
|
end
|
@@ -231,14 +223,14 @@ describe Guard::Rubocop::Runner do
|
|
231
223
|
let(:args) { %w(--debug) }
|
232
224
|
|
233
225
|
it 'returns false' do
|
234
|
-
include_formatter_for_console
|
226
|
+
expect(include_formatter_for_console?).to be_false
|
235
227
|
end
|
236
228
|
end
|
237
229
|
end
|
238
230
|
|
239
231
|
describe '#json_file_path' do
|
240
232
|
it 'is not world readable' do
|
241
|
-
File.world_readable?(runner.json_file_path).
|
233
|
+
expect(File.world_readable?(runner.json_file_path)).to be_false
|
242
234
|
end
|
243
235
|
end
|
244
236
|
|
@@ -291,13 +283,13 @@ describe Guard::Rubocop::Runner do
|
|
291
283
|
|
292
284
|
describe '#result', :json_file do
|
293
285
|
it 'parses JSON file' do
|
294
|
-
runner.result[:summary][:offence_count].
|
286
|
+
expect(runner.result[:summary][:offence_count]).to eq(2)
|
295
287
|
end
|
296
288
|
end
|
297
289
|
|
298
290
|
describe '#notify' do
|
299
291
|
before do
|
300
|
-
runner.
|
292
|
+
allow(runner).to receive(:result).and_return(
|
301
293
|
{
|
302
294
|
summary: {
|
303
295
|
offence_count: 4,
|
@@ -309,23 +301,23 @@ describe Guard::Rubocop::Runner do
|
|
309
301
|
end
|
310
302
|
|
311
303
|
it 'notifies summary' do
|
312
|
-
Guard::Notifier.
|
313
|
-
message.
|
304
|
+
expect(Guard::Notifier).to receive(:notify) do |message, options|
|
305
|
+
expect(message).to eq('2 files inspected, 4 offences detected')
|
314
306
|
end
|
315
307
|
runner.notify(true)
|
316
308
|
end
|
317
309
|
|
318
310
|
it 'notifies with title "RuboCop results"' do
|
319
|
-
Guard::Notifier.
|
320
|
-
options[:title].
|
311
|
+
expect(Guard::Notifier).to receive(:notify) do |message, options|
|
312
|
+
expect(options[:title]).to eq('RuboCop results')
|
321
313
|
end
|
322
314
|
runner.notify(true)
|
323
315
|
end
|
324
316
|
|
325
317
|
context 'when passed' do
|
326
318
|
it 'shows success image' do
|
327
|
-
Guard::Notifier.
|
328
|
-
options[:image].
|
319
|
+
expect(Guard::Notifier).to receive(:notify) do |message, options|
|
320
|
+
expect(options[:image]).to eq(:success)
|
329
321
|
end
|
330
322
|
runner.notify(true)
|
331
323
|
end
|
@@ -333,8 +325,8 @@ describe Guard::Rubocop::Runner do
|
|
333
325
|
|
334
326
|
context 'when failed' do
|
335
327
|
it 'shows failed image' do
|
336
|
-
Guard::Notifier.
|
337
|
-
options[:image].
|
328
|
+
expect(Guard::Notifier).to receive(:notify) do |message, options|
|
329
|
+
expect(options[:image]).to eq(:failed)
|
338
330
|
end
|
339
331
|
runner.notify(false)
|
340
332
|
end
|
@@ -343,7 +335,7 @@ describe Guard::Rubocop::Runner do
|
|
343
335
|
|
344
336
|
describe '#summary_text' do
|
345
337
|
before do
|
346
|
-
runner.
|
338
|
+
allow(runner).to receive(:result).and_return(
|
347
339
|
{
|
348
340
|
summary: {
|
349
341
|
offence_count: offence_count,
|
@@ -363,49 +355,49 @@ describe Guard::Rubocop::Runner do
|
|
363
355
|
context 'when no files are inspected' do
|
364
356
|
let(:inspected_file_count) { 0 }
|
365
357
|
it 'includes "0 files"' do
|
366
|
-
summary_text.
|
358
|
+
expect(summary_text).to include '0 files'
|
367
359
|
end
|
368
360
|
end
|
369
361
|
|
370
362
|
context 'when a file is inspected' do
|
371
363
|
let(:inspected_file_count) { 1 }
|
372
364
|
it 'includes "1 file"' do
|
373
|
-
summary_text.
|
365
|
+
expect(summary_text).to include '1 file'
|
374
366
|
end
|
375
367
|
end
|
376
368
|
|
377
369
|
context 'when 2 files are inspected' do
|
378
370
|
let(:inspected_file_count) { 2 }
|
379
371
|
it 'includes "2 files"' do
|
380
|
-
summary_text.
|
372
|
+
expect(summary_text).to include '2 files'
|
381
373
|
end
|
382
374
|
end
|
383
375
|
|
384
376
|
context 'when no offences are detected' do
|
385
377
|
let(:offence_count) { 0 }
|
386
378
|
it 'includes "no offences"' do
|
387
|
-
summary_text.
|
379
|
+
expect(summary_text).to include 'no offences'
|
388
380
|
end
|
389
381
|
end
|
390
382
|
|
391
383
|
context 'when an offence is detected' do
|
392
384
|
let(:offence_count) { 1 }
|
393
385
|
it 'includes "1 offence"' do
|
394
|
-
summary_text.
|
386
|
+
expect(summary_text).to include '1 offence'
|
395
387
|
end
|
396
388
|
end
|
397
389
|
|
398
390
|
context 'when 2 offences are detected' do
|
399
391
|
let(:offence_count) { 2 }
|
400
392
|
it 'includes "2 offences"' do
|
401
|
-
summary_text.
|
393
|
+
expect(summary_text).to include '2 offences'
|
402
394
|
end
|
403
395
|
end
|
404
396
|
end
|
405
397
|
|
406
398
|
describe '#failed_paths', :json_file do
|
407
399
|
it 'returns file paths which have offences' do
|
408
|
-
runner.failed_paths.
|
400
|
+
expect(runner.failed_paths).to eq(['lib/bar.rb'])
|
409
401
|
end
|
410
402
|
end
|
411
403
|
end
|
data/spec/guard/rubocop_spec.rb
CHANGED
@@ -7,8 +7,6 @@ describe Guard::Rubocop, :silence_output do
|
|
7
7
|
let(:watchers) { [] }
|
8
8
|
let(:options) { {} }
|
9
9
|
|
10
|
-
let(:runner) { Guard::Rubocop::Runner.any_instance }
|
11
|
-
|
12
10
|
describe '#options' do
|
13
11
|
subject { super().options }
|
14
12
|
|
@@ -26,7 +24,7 @@ describe Guard::Rubocop, :silence_output do
|
|
26
24
|
let(:options) { { all_on_start: true } }
|
27
25
|
|
28
26
|
it 'runs all' do
|
29
|
-
guard.
|
27
|
+
expect(guard).to receive(:run_all)
|
30
28
|
guard.start
|
31
29
|
end
|
32
30
|
end
|
@@ -35,7 +33,7 @@ describe Guard::Rubocop, :silence_output do
|
|
35
33
|
let(:options) { { all_on_start: false } }
|
36
34
|
|
37
35
|
it 'does nothing' do
|
38
|
-
guard.
|
36
|
+
expect(guard).not_to receive(:run_all)
|
39
37
|
guard.start
|
40
38
|
end
|
41
39
|
end
|
@@ -44,40 +42,41 @@ describe Guard::Rubocop, :silence_output do
|
|
44
42
|
shared_examples 'processes after running', :processes_after_running do
|
45
43
|
context 'when passed' do
|
46
44
|
it 'throws nothing' do
|
47
|
-
|
45
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(true)
|
48
46
|
expect { subject }.not_to throw_symbol
|
49
47
|
end
|
50
48
|
|
51
49
|
it 'clears failed paths' do
|
52
|
-
|
53
|
-
|
50
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(true)
|
51
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:failed_paths).and_return([])
|
54
52
|
subject
|
55
|
-
guard.failed_paths.
|
53
|
+
expect(guard.failed_paths).to be_empty
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
context 'when failed' do
|
60
58
|
it 'throws symbol :task_has_failed' do
|
61
|
-
|
59
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(false)
|
62
60
|
expect { subject }.to throw_symbol(:task_has_failed)
|
63
61
|
end
|
64
62
|
|
65
63
|
it 'keeps failed paths' do
|
66
|
-
guard.
|
64
|
+
allow(guard).to receive(:throw)
|
67
65
|
failed_paths = [
|
68
66
|
'some_failed_file.rb',
|
69
67
|
'dir/another_failed_file.rb'
|
70
68
|
]
|
71
|
-
|
72
|
-
|
69
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(false)
|
70
|
+
allow_any_instance_of(Guard::Rubocop::Runner)
|
71
|
+
.to receive(:failed_paths).and_return(failed_paths)
|
73
72
|
subject
|
74
|
-
guard.failed_paths.
|
73
|
+
expect(guard.failed_paths).to eq(failed_paths)
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
77
|
context 'when an exception is raised' do
|
79
78
|
it 'prevents itself from firing' do
|
80
|
-
|
79
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_raise(RuntimeError)
|
81
80
|
expect { subject }.not_to raise_error
|
82
81
|
end
|
83
82
|
end
|
@@ -87,49 +86,65 @@ describe Guard::Rubocop, :silence_output do
|
|
87
86
|
subject { super().run_all }
|
88
87
|
|
89
88
|
before do
|
90
|
-
|
91
|
-
|
89
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(true)
|
90
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:failed_paths).and_return([])
|
92
91
|
end
|
93
92
|
|
94
93
|
it 'inspects all files with rubocop' do
|
95
|
-
|
94
|
+
expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run).with([])
|
96
95
|
guard.run_all
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
99
|
describe '#run_on_changes', :processes_after_running do
|
101
100
|
subject { super().run_on_changes(changed_paths) }
|
102
|
-
let(:changed_paths)
|
101
|
+
let(:changed_paths) do
|
102
|
+
[
|
103
|
+
'lib/guard/rubocop.rb',
|
104
|
+
'spec/spec_helper.rb'
|
105
|
+
]
|
106
|
+
end
|
103
107
|
|
104
108
|
before do
|
105
|
-
|
106
|
-
|
109
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:run).and_return(true)
|
110
|
+
allow_any_instance_of(Guard::Rubocop::Runner).to receive(:failed_paths).and_return([])
|
107
111
|
end
|
108
112
|
|
109
113
|
it 'inspects changed files with rubocop' do
|
110
|
-
|
114
|
+
expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run)
|
111
115
|
guard.run_on_changes(changed_paths)
|
112
116
|
end
|
113
117
|
|
114
118
|
it 'passes cleaned paths to rubocop' do
|
115
|
-
|
116
|
-
paths.
|
119
|
+
expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
|
120
|
+
expect(paths).to eq([
|
117
121
|
File.expand_path('some.rb'),
|
118
122
|
File.expand_path('dir/another.rb')
|
119
|
-
]
|
123
|
+
])
|
120
124
|
end
|
121
125
|
guard.run_on_changes(changed_paths)
|
122
126
|
end
|
123
127
|
|
124
|
-
|
128
|
+
context 'when cleaned paths are empty' do
|
129
|
+
before do
|
130
|
+
allow(guard).to receive(:clean_paths).and_return([])
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'does nothing' do
|
134
|
+
expect_any_instance_of(Guard::Rubocop::Runner).not_to receive(:run)
|
135
|
+
guard.run_on_changes(changed_paths)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
let(:failed_path) { File.expand_path('Rakefile') }
|
125
140
|
|
126
141
|
context 'when :keep_failed option is enabled' do
|
127
142
|
let(:options) { { keep_failed: true } }
|
128
143
|
|
129
144
|
it 'also inspects paths which are failed last time' do
|
130
145
|
guard.failed_paths << failed_path
|
131
|
-
|
132
|
-
paths.
|
146
|
+
expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
|
147
|
+
expect(paths).to include failed_path
|
133
148
|
end
|
134
149
|
guard.run_on_changes(changed_paths)
|
135
150
|
end
|
@@ -137,17 +152,11 @@ describe Guard::Rubocop, :silence_output do
|
|
137
152
|
|
138
153
|
context 'when :keep_failed option is disabled' do
|
139
154
|
let(:options) { { keep_failed: false } }
|
140
|
-
let(:changed_paths) do
|
141
|
-
[
|
142
|
-
File.expand_path('some.rb'),
|
143
|
-
File.expand_path('dir/another.rb')
|
144
|
-
]
|
145
|
-
end
|
146
155
|
|
147
156
|
it 'inspects just changed paths' do
|
148
157
|
guard.failed_paths << failed_path
|
149
|
-
|
150
|
-
paths.
|
158
|
+
expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
|
159
|
+
expect(paths).to eq(changed_paths)
|
151
160
|
end
|
152
161
|
guard.run_on_changes(changed_paths)
|
153
162
|
end
|
@@ -158,7 +167,7 @@ describe Guard::Rubocop, :silence_output do
|
|
158
167
|
it 'clears failed paths' do
|
159
168
|
guard.failed_paths << 'failed.rb'
|
160
169
|
guard.reload
|
161
|
-
guard.failed_paths.
|
170
|
+
expect(guard.failed_paths).to be_empty
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
@@ -168,10 +177,10 @@ describe Guard::Rubocop, :silence_output do
|
|
168
177
|
'lib/guard/rubocop.rb',
|
169
178
|
'spec/spec_helper.rb'
|
170
179
|
]
|
171
|
-
guard.clean_paths(paths).
|
180
|
+
expect(guard.clean_paths(paths)).to eq([
|
172
181
|
File.expand_path('lib/guard/rubocop.rb'),
|
173
182
|
File.expand_path('spec/spec_helper.rb')
|
174
|
-
]
|
183
|
+
])
|
175
184
|
end
|
176
185
|
|
177
186
|
it 'removes duplicated paths' do
|
@@ -180,10 +189,22 @@ describe Guard::Rubocop, :silence_output do
|
|
180
189
|
'spec/spec_helper.rb',
|
181
190
|
'lib/guard/../guard/rubocop.rb'
|
182
191
|
]
|
183
|
-
guard.clean_paths(paths).
|
192
|
+
expect(guard.clean_paths(paths)).to eq([
|
184
193
|
File.expand_path('lib/guard/rubocop.rb'),
|
185
194
|
File.expand_path('spec/spec_helper.rb')
|
195
|
+
])
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'removes non-existent paths' do
|
199
|
+
paths = [
|
200
|
+
'lib/guard/rubocop.rb',
|
201
|
+
'path/to/non_existent_file.rb',
|
202
|
+
'spec/spec_helper.rb'
|
186
203
|
]
|
204
|
+
expect(guard.clean_paths(paths)).to eq([
|
205
|
+
File.expand_path('lib/guard/rubocop.rb'),
|
206
|
+
File.expand_path('spec/spec_helper.rb')
|
207
|
+
])
|
187
208
|
end
|
188
209
|
|
189
210
|
it 'removes paths which are included in another path' do
|
@@ -192,11 +213,36 @@ describe Guard::Rubocop, :silence_output do
|
|
192
213
|
'spec/spec_helper.rb',
|
193
214
|
'spec'
|
194
215
|
]
|
195
|
-
guard.clean_paths(paths).
|
216
|
+
expect(guard.clean_paths(paths)).to eq([
|
196
217
|
File.expand_path('lib/guard/rubocop.rb'),
|
197
218
|
File.expand_path('spec')
|
198
|
-
]
|
219
|
+
])
|
199
220
|
end
|
200
221
|
end
|
201
222
|
|
223
|
+
describe '#smart_path' do
|
224
|
+
def smart_path(path)
|
225
|
+
guard.send(:smart_path, path)
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when the passed path is under the current working directory' do
|
229
|
+
let(:path) { File.expand_path('spec/spec_helper.rb') }
|
230
|
+
|
231
|
+
it 'returns relative path' do
|
232
|
+
expect(smart_path(path)).to eq('spec/spec_helper.rb')
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'when the passed path is outside of the current working directory' do
|
237
|
+
let(:path) do
|
238
|
+
tempfile = Tempfile.new('')
|
239
|
+
tempfile.close
|
240
|
+
File.expand_path(tempfile.path)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'returns absolute path' do
|
244
|
+
expect(smart_path(path)).to eq(path)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
202
248
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |c|
|
5
|
+
c.syntax = :expect
|
6
|
+
end
|
7
|
+
|
4
8
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
9
|
end
|
6
10
|
|
@@ -14,7 +18,7 @@ SimpleCov.coverage_dir(File.join('spec', 'coverage'))
|
|
14
18
|
if ENV['TRAVIS']
|
15
19
|
require 'coveralls'
|
16
20
|
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
17
|
-
elsif ENV['CI']
|
21
|
+
elsif ENV['CI']
|
18
22
|
require 'simplecov-rcov'
|
19
23
|
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
20
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.14'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
82
|
+
version: '2.14'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|