guard-rubocop 1.0.1 → 1.0.2

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: ec82afdd85de6be92deca90949f571a84eae25cf
4
- data.tar.gz: 68d6f82e862a90d3625e4fcf0b1c06d36a67221c
3
+ metadata.gz: 381f4bdd0bfd18f0421441c723f6d15b7fa60483
4
+ data.tar.gz: 706e9ce598392012ba485deb21c6fc127fc333ac
5
5
  SHA512:
6
- metadata.gz: d40d80a751bc72240d3c0d5b1c1ace21c12e1792a66ee481511733c91ff1f360c478eda6ccf31bf80cf2475ab1c4464176ebf979f61514a668998339687328ea
7
- data.tar.gz: 5a2c18d2e662dc0744463c374bd94cf55979b816538726dd89f81bac3dce0d14850ced6d4dbd35a72caf3c72372cf96cb433651a775ccfdb4eef8ac1cd6127cd
6
+ metadata.gz: a2d6bc60c3f2cbe194e7a5036b1510b8a1a38d7a9c9261a17505d9af95094a84e7b97b6ce7e7fe4a3fdaf792a2990d9af317a3741500820fc1883d1c8b59f0ff
7
+ data.tar.gz: 6caa97c34c3a4c380a25f0bf869a0bbc1648aef2105d774b2cb51f728a4720f039322afe40249f89919f41876855b8cd66ad19c7d3dbd5e1ce386b55bfe595f9
@@ -2,7 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
5
6
  - jruby-19mode
7
+ - rbx
6
8
  script:
7
9
  - bundle exec rspec
8
10
  - bundle exec rubocop
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.0.2
6
+
7
+ * Support both spelling “offense” (RuboCop 0.19 or later) and “offence” (prior to RuboCop 0.19) ([rubocop#700](https://github.com/bbatsov/rubocop/issues/700))
8
+
5
9
  ## v1.0.1
6
10
 
7
11
  * Fix inappripriate multiple run on a save with Vim ([#6](https://github.com/yujinakayama/guard-rubocop/pull/6))
data/Gemfile CHANGED
@@ -7,3 +7,10 @@ group :test do
7
7
  gem 'simplecov-rcov', '~> 0.2'
8
8
  gem 'ci_reporter', '~> 1.8'
9
9
  end
10
+
11
+ platforms :rbx do
12
+ gem 'rubysl'
13
+ gem 'rubinius-developer_tools'
14
+ gem 'json'
15
+ gem 'racc' # Needed for RuboCop
16
+ end
data/Guardfile CHANGED
@@ -1,14 +1,16 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard :rspec, all_after_pass: true, all_on_start: true, keep_failed: true do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- watch(%r{^spec/support/.+\.rb$}) { "spec" }
9
- end
4
+ group :red_green_refactor, halt_on_fail: true do
5
+ guard :rspec, all_after_pass: true, all_on_start: true, cmd: 'bundle exec rspec' do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ watch(%r{^spec/support/.+\.rb$}) { "spec" }
10
+ end
10
11
 
11
- guard :rubocop do
12
- watch(%r{.+\.rb$})
13
- watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
12
+ guard :rubocop do
13
+ watch(%r{.+\.rb$})
14
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
15
+ end
14
16
  end
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Guard::Rubocop allows you to automatically check Ruby code style with [RuboCop](https://github.com/bbatsov/rubocop) when files are modified.
6
6
 
7
- Tested on MRI 1.9, MRI 2.0, JRuby and Rubinius in 1.9 modes.
7
+ Tested on MRI 1.9, 2.0, 2.1, JRuby in 1.9 mode and Rubinius.
8
8
 
9
9
  ## Installation
10
10
 
@@ -55,7 +55,7 @@ end
55
55
  ```ruby
56
56
  all_on_start: true # Check all files at Guard startup.
57
57
  # default: true
58
- cli: ['--rails'] # Pass arbitrary RuboCop CLI arguments.
58
+ cli: '--rails' # Pass arbitrary RuboCop CLI arguments.
59
59
  # An array or string is acceptable.
60
60
  # default: nil
61
61
  keep_failed: true # Keep failed files until they pass.
@@ -67,6 +67,31 @@ notification: :failed # Display Growl notification after each run.
67
67
  # default: :failed
68
68
  ```
69
69
 
70
+ ## Advanced Tips
71
+
72
+ If you're using a testing Guard plugin such as [`guard-rspec`](https://github.com/guard/guard-rspec) together with `guard-rubocop` in the TDD way (the red-green-refactor cycle),
73
+ you might be uncomfortable with the offense reports from RuboCop in the red-green phase:
74
+
75
+ * In the red-green phase, you're not necessarily required to write clean code – you just focus writing code to pass the test. It means, in this phase, `guard-rspec` should be run but `guard-rubocop` should not.
76
+ * In the refactor phase, you're required to make the code clean while keeping the test passing. In this phase, both `guard-rspec` and `guard-rubocop` should be run.
77
+
78
+ In this case, you may think the following `Guardfile` structure useful:
79
+
80
+ ```ruby
81
+ # This group allows to skip running RuboCop when RSpec failed.
82
+ group :red_green_refactor, halt_on_fail: true do
83
+ guard :rspec do
84
+ # ...
85
+ end
86
+
87
+ guard :rubocop do
88
+ # ...
89
+ end
90
+ end
91
+ ```
92
+
93
+ Note: You need to use `guard-rspec` 4.2.3 or later due to a [bug](https://github.com/guard/guard-rspec/pull/234) where it unintentionally fails when there are no spec files to be run.
94
+
70
95
  ## Contributing
71
96
 
72
97
  1. Fork it
@@ -25,8 +25,8 @@ 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.14'
28
+ spec.add_development_dependency 'rspec', '~> 3.0.0.beta1'
29
29
  spec.add_development_dependency 'simplecov', '~> 0.7'
30
- spec.add_development_dependency 'guard-rspec', '~> 4.0'
30
+ spec.add_development_dependency 'guard-rspec', '>= 4.2.3', '< 5.0'
31
31
  spec.add_development_dependency 'ruby_gntp', '~> 0.3'
32
32
  end
@@ -92,13 +92,15 @@ module Guard
92
92
  text = pluralize(summary[:inspected_file_count], 'file')
93
93
  text << ' inspected, '
94
94
 
95
- text << pluralize(summary[:offence_count], 'offence', no_for_zero: true)
95
+ offense_count = summary[:offense_count] || summary[:offence_count]
96
+ text << pluralize(offense_count, 'offense', no_for_zero: true)
96
97
  text << ' detected'
97
98
  end
98
99
 
99
100
  def failed_paths
100
101
  failed_files = result[:files].reject do |file|
101
- file[:offences].empty?
102
+ offenses = file[:offenses] || file[:offences]
103
+ offenses.empty?
102
104
  end
103
105
  failed_files.map do |file|
104
106
  file[:path]
@@ -7,7 +7,7 @@ module Guard
7
7
  # http://semver.org/
8
8
  MAJOR = 1
9
9
  MINOR = 0
10
- PATCH = 1
10
+ PATCH = 2
11
11
 
12
12
  def self.to_s
13
13
  [MAJOR, MINOR, PATCH].join('.')
@@ -25,14 +25,14 @@ describe Guard::Rubocop::Runner do
25
25
  before do
26
26
  allow(runner).to receive(:system).and_return(true)
27
27
  end
28
- it { should be_true }
28
+ it { should be_truthy }
29
29
  end
30
30
 
31
31
  context 'when RuboCop exited with non 0 status' do
32
32
  before do
33
33
  allow(runner).to receive(:system).and_return(false)
34
34
  end
35
- it { should be_false }
35
+ it { should be_falsey }
36
36
  end
37
37
 
38
38
  shared_examples 'notifies', :notifies do
@@ -172,7 +172,7 @@ describe Guard::Rubocop::Runner do
172
172
  let(:args) { %w(--format simple --debug) }
173
173
 
174
174
  it 'returns true' do
175
- expect(include_formatter_for_console?).to be_true
175
+ expect(include_formatter_for_console?).to be_truthy
176
176
  end
177
177
  end
178
178
 
@@ -180,7 +180,7 @@ describe Guard::Rubocop::Runner do
180
180
  let(:args) { %w(--format simple --out simple.txt) }
181
181
 
182
182
  it 'returns false' do
183
- expect(include_formatter_for_console?).to be_false
183
+ expect(include_formatter_for_console?).to be_falsey
184
184
  end
185
185
  end
186
186
 
@@ -188,7 +188,7 @@ describe Guard::Rubocop::Runner do
188
188
  let(:args) { %w(--format simple --debug --out simple.txt) }
189
189
 
190
190
  it 'returns false' do
191
- expect(include_formatter_for_console?).to be_false
191
+ expect(include_formatter_for_console?).to be_falsey
192
192
  end
193
193
  end
194
194
  end
@@ -198,7 +198,7 @@ describe Guard::Rubocop::Runner do
198
198
  let(:args) { %w(-fs --debug) }
199
199
 
200
200
  it 'returns true' do
201
- expect(include_formatter_for_console?).to be_true
201
+ expect(include_formatter_for_console?).to be_truthy
202
202
  end
203
203
  end
204
204
 
@@ -206,7 +206,7 @@ describe Guard::Rubocop::Runner do
206
206
  let(:args) { %w(-fs -osimple.txt) }
207
207
 
208
208
  it 'returns false' do
209
- expect(include_formatter_for_console?).to be_false
209
+ expect(include_formatter_for_console?).to be_falsey
210
210
  end
211
211
  end
212
212
  end
@@ -216,7 +216,7 @@ describe Guard::Rubocop::Runner do
216
216
  let(:args) { %w(--format simple --out simple.txt --format emacs --out emacs.txt) }
217
217
 
218
218
  it 'returns false' do
219
- expect(include_formatter_for_console?).to be_false
219
+ expect(include_formatter_for_console?).to be_falsey
220
220
  end
221
221
  end
222
222
 
@@ -224,7 +224,7 @@ describe Guard::Rubocop::Runner do
224
224
  let(:args) { %w(--format simple --format emacs --out emacs.txt) }
225
225
 
226
226
  it 'returns true' do
227
- expect(include_formatter_for_console?).to be_true
227
+ expect(include_formatter_for_console?).to be_truthy
228
228
  end
229
229
  end
230
230
 
@@ -232,7 +232,7 @@ describe Guard::Rubocop::Runner do
232
232
  let(:args) { %w(--format simple --format emacs) }
233
233
 
234
234
  it 'returns true' do
235
- expect(include_formatter_for_console?).to be_true
235
+ expect(include_formatter_for_console?).to be_truthy
236
236
  end
237
237
  end
238
238
  end
@@ -241,14 +241,14 @@ describe Guard::Rubocop::Runner do
241
241
  let(:args) { %w(--debug) }
242
242
 
243
243
  it 'returns false' do
244
- expect(include_formatter_for_console?).to be_false
244
+ expect(include_formatter_for_console?).to be_falsey
245
245
  end
246
246
  end
247
247
  end
248
248
 
249
249
  describe '#json_file_path' do
250
250
  it 'is not world readable' do
251
- expect(File.world_readable?(runner.json_file_path)).to be_false
251
+ expect(File.world_readable?(runner.json_file_path)).to be_falsey
252
252
  end
253
253
  end
254
254
 
@@ -265,10 +265,10 @@ describe Guard::Rubocop::Runner do
265
265
  },
266
266
  "files": [{
267
267
  "path": "lib/foo.rb",
268
- "offences": []
268
+ "offenses": []
269
269
  }, {
270
270
  "path": "lib/bar.rb",
271
- "offences": [{
271
+ "offenses": [{
272
272
  "severity": "convention",
273
273
  "message": "Line is too long. [81/79]",
274
274
  "cop_name": "LineLength",
@@ -289,7 +289,7 @@ describe Guard::Rubocop::Runner do
289
289
  }
290
290
  ],
291
291
  "summary": {
292
- "offence_count": 2,
292
+ "offense_count": 2,
293
293
  "target_file_count": 2,
294
294
  "inspected_file_count": 2
295
295
  }
@@ -301,7 +301,7 @@ describe Guard::Rubocop::Runner do
301
301
 
302
302
  describe '#result', :json_file do
303
303
  it 'parses JSON file' do
304
- expect(runner.result[:summary][:offence_count]).to eq(2)
304
+ expect(runner.result[:summary][:offense_count]).to eq(2)
305
305
  end
306
306
  end
307
307
 
@@ -310,7 +310,7 @@ describe Guard::Rubocop::Runner do
310
310
  allow(runner).to receive(:result).and_return(
311
311
  {
312
312
  summary: {
313
- offence_count: 4,
313
+ offense_count: 4,
314
314
  target_file_count: 3,
315
315
  inspected_file_count: 2
316
316
  }
@@ -320,7 +320,7 @@ describe Guard::Rubocop::Runner do
320
320
 
321
321
  it 'notifies summary' do
322
322
  expect(Guard::Notifier).to receive(:notify) do |message, options|
323
- expect(message).to eq('2 files inspected, 4 offences detected')
323
+ expect(message).to eq('2 files inspected, 4 offenses detected')
324
324
  end
325
325
  runner.notify(true)
326
326
  end
@@ -356,7 +356,7 @@ describe Guard::Rubocop::Runner do
356
356
  allow(runner).to receive(:result).and_return(
357
357
  {
358
358
  summary: {
359
- offence_count: offence_count,
359
+ offense_count: offense_count,
360
360
  target_file_count: target_file_count,
361
361
  inspected_file_count: inspected_file_count
362
362
  }
@@ -366,7 +366,7 @@ describe Guard::Rubocop::Runner do
366
366
 
367
367
  subject(:summary_text) { runner.summary_text }
368
368
 
369
- let(:offence_count) { 0 }
369
+ let(:offense_count) { 0 }
370
370
  let(:target_file_count) { 0 }
371
371
  let(:inspected_file_count) { 0 }
372
372
 
@@ -391,31 +391,88 @@ describe Guard::Rubocop::Runner do
391
391
  end
392
392
  end
393
393
 
394
- context 'when no offences are detected' do
395
- let(:offence_count) { 0 }
396
- it 'includes "no offences"' do
397
- expect(summary_text).to include 'no offences'
394
+ context 'when no offenses are detected' do
395
+ let(:offense_count) { 0 }
396
+ it 'includes "no offenses"' do
397
+ expect(summary_text).to include 'no offenses'
398
398
  end
399
399
  end
400
400
 
401
- context 'when an offence is detected' do
402
- let(:offence_count) { 1 }
403
- it 'includes "1 offence"' do
404
- expect(summary_text).to include '1 offence'
401
+ context 'when an offense is detected' do
402
+ let(:offense_count) { 1 }
403
+ it 'includes "1 offense"' do
404
+ expect(summary_text).to include '1 offense'
405
405
  end
406
406
  end
407
407
 
408
- context 'when 2 offences are detected' do
409
- let(:offence_count) { 2 }
410
- it 'includes "2 offences"' do
411
- expect(summary_text).to include '2 offences'
408
+ context 'when 2 offenses are detected' do
409
+ let(:offense_count) { 2 }
410
+ it 'includes "2 offenses"' do
411
+ expect(summary_text).to include '2 offenses'
412
+ end
413
+ end
414
+
415
+ context 'with spelling "offence" in old RuboCop' do
416
+ before do
417
+ allow(runner).to receive(:result).and_return(
418
+ {
419
+ summary: {
420
+ offence_count: 2,
421
+ target_file_count: 1,
422
+ inspected_file_count: 1
423
+ }
424
+ }
425
+ )
426
+ end
427
+
428
+ it 'handles the spelling' do
429
+ expect(summary_text).to include '2 offenses'
412
430
  end
413
431
  end
414
432
  end
415
433
 
416
434
  describe '#failed_paths', :json_file do
417
- it 'returns file paths which have offences' do
435
+ it 'returns file paths which have offenses' do
418
436
  expect(runner.failed_paths).to eq(['lib/bar.rb'])
419
437
  end
438
+
439
+ context 'with spelling "offence" in old RuboCop' do
440
+ before do
441
+ json = <<-END
442
+ {
443
+ "files": [{
444
+ "path": "lib/foo.rb",
445
+ "offences": []
446
+ }, {
447
+ "path": "lib/bar.rb",
448
+ "offences": [{
449
+ "severity": "convention",
450
+ "message": "Line is too long. [81/79]",
451
+ "cop_name": "LineLength",
452
+ "location": {
453
+ "line": 546,
454
+ "column": 80
455
+ }
456
+ }, {
457
+ "severity": "warning",
458
+ "message": "Unreachable code detected.",
459
+ "cop_name": "UnreachableCode",
460
+ "location": {
461
+ "line": 15,
462
+ "column": 9
463
+ }
464
+ }
465
+ ]
466
+ }
467
+ ]
468
+ }
469
+ END
470
+ File.write(runner.json_file_path, json)
471
+ end
472
+
473
+ it 'handles the spelling' do
474
+ expect(runner.failed_paths).to eq(['lib/bar.rb'])
475
+ end
476
+ end
420
477
  end
421
478
  end
@@ -14,12 +14,12 @@ describe Guard::Rubocop, :silence_output do
14
14
 
15
15
  describe '[:all_on_start]' do
16
16
  subject { super()[:all_on_start] }
17
- it { should be_true }
17
+ it { should be_truthy }
18
18
  end
19
19
 
20
20
  describe '[:keep_failed]' do
21
21
  subject { super()[:keep_failed] }
22
- it { should be_true }
22
+ it { should be_truthy }
23
23
  end
24
24
 
25
25
  describe '[:notification]' do
@@ -132,7 +132,7 @@ describe Guard::Rubocop, :silence_output do
132
132
  end
133
133
 
134
134
  it 'passes cleaned paths to rubocop' do
135
- expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
135
+ expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |instance, paths|
136
136
  expect(paths).to eq([
137
137
  File.expand_path('some.rb'),
138
138
  File.expand_path('dir/another.rb')
@@ -159,7 +159,7 @@ describe Guard::Rubocop, :silence_output do
159
159
 
160
160
  it 'also inspects paths which are failed last time' do
161
161
  guard.failed_paths << failed_path
162
- expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
162
+ expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |instance, paths|
163
163
  expect(paths).to include failed_path
164
164
  end
165
165
  subject
@@ -171,7 +171,7 @@ describe Guard::Rubocop, :silence_output do
171
171
 
172
172
  it 'inspects just changed paths' do
173
173
  guard.failed_paths << failed_path
174
- expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |paths|
174
+ expect_any_instance_of(Guard::Rubocop::Runner).to receive(:run) do |instance, paths|
175
175
  expect(paths).to eq(changed_paths)
176
176
  end
177
177
  subject
@@ -5,7 +5,9 @@ RSpec.configure do |config|
5
5
  c.syntax = :expect
6
6
  end
7
7
 
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.mock_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
9
11
  end
10
12
 
11
13
  Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
@@ -1,14 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
3
  shared_context 'silence output', silence_output: true do
4
- before do
5
- null_output = double('output').as_null_object
4
+ null_object = BasicObject.new
5
+
6
+ class << null_object
7
+ # #respond_to_missing? does not work.
8
+ def respond_to?(*)
9
+ true
10
+ end
11
+
12
+ def method_missing(*)
13
+ end
14
+ end
6
15
 
16
+ before do
7
17
  @original_stdout = $stdout
8
18
  @original_stderr = $stderr
9
-
10
- $stdout = null_output
11
- $stderr = null_output
19
+ $stdout = null_object
20
+ $stderr = null_object
12
21
  end
13
22
 
14
23
  after do
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: 1.0.1
4
+ version: 1.0.2
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-12-02 00:00:00.000000000 Z
11
+ date: 2014-02-11 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.14'
75
+ version: 3.0.0.beta1
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.14'
82
+ version: 3.0.0.beta1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,22 @@ dependencies:
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.3
104
+ - - "<"
102
105
  - !ruby/object:Gem::Version
103
- version: '4.0'
106
+ version: '5.0'
104
107
  type: :development
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
108
- - - "~>"
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 4.2.3
114
+ - - "<"
109
115
  - !ruby/object:Gem::Version
110
- version: '4.0'
116
+ version: '5.0'
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: ruby_gntp
113
119
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
176
  version: '0'
171
177
  requirements: []
172
178
  rubyforge_project:
173
- rubygems_version: 2.0.14
179
+ rubygems_version: 2.2.0
174
180
  signing_key:
175
181
  specification_version: 4
176
182
  summary: Guard plugin for RuboCop