guard-rubocop 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae91b5efb5588f487c013e9ce9bd122b8e5a3e5d
4
- data.tar.gz: eb7c6e0877ece705ffc2ec3d0678be31c99ffde0
3
+ metadata.gz: df888e087c9fd9f43ae488326b28cdacc0590e04
4
+ data.tar.gz: 4f1e983579323bcddb9de6679c00d84a1342f345
5
5
  SHA512:
6
- metadata.gz: c145d8df9c847803da47b8837347afaa4792fc5a41e484824635a424e384daa2c3694fa109e47797ca17f9e7e6c8c1dbc9bdee7e88fd0de76cc1c7e19d7ff1d7
7
- data.tar.gz: c8a27a5a563029a367fb65d2fa1bb00508f14bb56dc73e834f6767ee172b6e30d47fe4e0a0ba8c2e05ce26d61d67e0b7cd12e82cf75208bfab47aed94701a929
6
+ metadata.gz: 64a073b7cb937839c493b97380185a3e286dc6cc41e741c662ae02231ec633ccf76484edc9382707eb29a0698d656405bf0b7025da87ab4f237f4a8e9d05d6ef
7
+ data.tar.gz: 9c8e163eb4a1e510adf4dab87b370ec9a59e4acaac16ff32e252beb450852099cf0e1cb80edf95b61e2bfe72c51fa5ef46bdfef484279bf9d58ddb2343776d7a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.2.1
4
+
5
+ * Fix exception when any file is deleted
6
+
3
7
  ## v0.2.0
4
8
 
5
9
  * Add `:cli` option which allows to specify additional command line arguments
data/Rakefile CHANGED
@@ -15,4 +15,12 @@ namespace :ci do
15
15
  end
16
16
  end
17
17
 
18
- task default: :spec
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
@@ -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.13'
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
@@ -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
- @tempfile_path ||= begin
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)
@@ -7,7 +7,7 @@ module Guard
7
7
  # http://semver.org/
8
8
  MAJOR = 0
9
9
  MINOR = 2
10
- PATCH = 0
10
+ PATCH = 1
11
11
  VERSION = [MAJOR, MINOR, PATCH].join('.')
12
12
  end
13
13
  end
@@ -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.stub(:system)
14
+ allow(runner).to receive(:system)
15
15
  end
16
16
 
17
17
  it 'executes rubocop' do
18
- runner.should_receive(:system) do |*args|
19
- args.first.should == 'rubocop'
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.stub(:system).and_return(true)
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.stub(:system).and_return(false)
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.should_receive(:notify)
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.should_not_receive(:notify)
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.stub(:system).and_return(true)
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.stub(:system).and_return(false)
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].should_not == %w(rubocop --format progress)
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].should == %w(rubocop --format progress)
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].should == %w(--format json)
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].should == '--out'
121
- build_command[6].should_not be_empty
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].should == %w(--debug --rails)
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].should == %w(file1.rb file2.rb)
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.should == []
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.should == ['--out', 'output file.txt']
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.should == ['--out', 'output file.txt']
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?.should be_true
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?.should be_false
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?.should be_false
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?.should be_false
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?.should be_true
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?.should be_true
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?.should be_false
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).should be_false
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].should == 2
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.stub(:result).and_return(
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.should_receive(:notify) do |message, options|
313
- message.should == '2 files inspected, 4 offences detected'
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.should_receive(:notify) do |message, options|
320
- options[:title].should == 'RuboCop results'
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.should_receive(:notify) do |message, options|
328
- options[:image].should == :success
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.should_receive(:notify) do |message, options|
337
- options[:image].should == :failed
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.stub(:result).and_return(
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.should include '0 files'
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.should include '1 file'
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.should include '2 files'
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.should include 'no offences'
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.should include '1 offence'
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.should include '2 offences'
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.should == ['lib/bar.rb']
400
+ expect(runner.failed_paths).to eq(['lib/bar.rb'])
409
401
  end
410
402
  end
411
403
  end
@@ -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.should_receive(:run_all)
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.should_not_receive(:run_all)
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
- runner.stub(:run).and_return(true)
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
- runner.stub(:run).and_return(true)
53
- runner.stub(:failed_paths).and_return([])
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.should be_empty
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
- runner.stub(:run).and_return(false)
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.stub(:throw)
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
- runner.stub(:run).and_return(false)
72
- runner.stub(:failed_paths).and_return(failed_paths)
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.should == 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
- runner.stub(:run).and_raise(RuntimeError)
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
- runner.stub(:run).and_return(true)
91
- runner.stub(:failed_paths).and_return([])
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
- runner.should_receive(:run).with([])
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) { ['some.rb', 'dir/another.rb', 'dir/../some.rb'] }
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
- runner.stub(:run).and_return(true)
106
- runner.stub(:failed_paths).and_return([])
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
- runner.should_receive(:run)
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
- runner.should_receive(:run) do |paths|
116
- paths.should == [
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
- let(:failed_path) { File.expand_path('failed_file_last_time.rb') }
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
- runner.should_receive(:run) do |paths|
132
- paths.should include failed_path
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
- runner.should_receive(:run) do |paths|
150
- paths.should == changed_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.should be_empty
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).should == [
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).should == [
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).should == [
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'] # rubocop:disable IfUnlessModifier
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.0
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-05 00:00:00.000000000 Z
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.13'
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.13'
82
+ version: '2.14'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement