rubocop 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -1
  3. data/README.md +28 -3
  4. data/config/default.yml +14 -12
  5. data/config/disabled.yml +1 -1
  6. data/config/enabled.yml +190 -118
  7. data/lib/rubocop.rb +9 -1
  8. data/lib/rubocop/cli.rb +49 -13
  9. data/lib/rubocop/config.rb +5 -5
  10. data/lib/rubocop/cop/cop.rb +34 -1
  11. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +47 -0
  12. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  13. data/lib/rubocop/cop/lint/useless_assignment.rb +39 -11
  14. data/lib/rubocop/cop/lint/useless_comparison.rb +2 -4
  15. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +20 -0
  16. data/lib/rubocop/cop/rails/read_attribute.rb +28 -0
  17. data/lib/rubocop/cop/style/access_control.rb +12 -1
  18. data/lib/rubocop/cop/style/attr.rb +7 -0
  19. data/lib/rubocop/cop/style/collection_methods.rb +13 -1
  20. data/lib/rubocop/cop/style/constant_name.rb +1 -1
  21. data/lib/rubocop/cop/style/def_parentheses.rb +18 -0
  22. data/lib/rubocop/cop/style/documentation.rb +1 -1
  23. data/lib/rubocop/cop/style/empty_literal.rb +14 -0
  24. data/lib/rubocop/cop/style/even_odd.rb +56 -0
  25. data/lib/rubocop/cop/style/favor_modifier.rb +2 -2
  26. data/lib/rubocop/cop/style/hash_methods.rb +40 -0
  27. data/lib/rubocop/cop/style/indentation_width.rb +148 -0
  28. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +40 -25
  29. data/lib/rubocop/cop/style/method_call_parentheses.rb +8 -0
  30. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  31. data/lib/rubocop/cop/style/nil_comparison.rb +38 -0
  32. data/lib/rubocop/cop/style/signal_exception.rb +11 -0
  33. data/lib/rubocop/cop/style/space_after_method_name.rb +34 -0
  34. data/lib/rubocop/cop/util.rb +17 -0
  35. data/lib/rubocop/formatter/emacs_style_formatter.rb +2 -2
  36. data/lib/rubocop/formatter/file_list_formatter.rb +3 -2
  37. data/lib/rubocop/formatter/formatter_set.rb +3 -11
  38. data/lib/rubocop/formatter/offence_count_formatter.rb +50 -0
  39. data/lib/rubocop/formatter/progress_formatter.rb +0 -2
  40. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -6
  41. data/lib/rubocop/version.rb +1 -1
  42. data/spec/project_spec.rb +7 -0
  43. data/spec/rubocop/cli_spec.rb +119 -57
  44. data/spec/rubocop/config_spec.rb +23 -17
  45. data/spec/rubocop/cop/commissioner_spec.rb +8 -8
  46. data/spec/rubocop/cop/cop_spec.rb +80 -0
  47. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +63 -0
  48. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +59 -0
  49. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +19 -0
  50. data/spec/rubocop/cop/rails/read_attribute_spec.rb +19 -0
  51. data/spec/rubocop/cop/rails/validation_spec.rb +5 -5
  52. data/spec/rubocop/cop/style/access_control_spec.rb +28 -0
  53. data/spec/rubocop/cop/style/attr_spec.rb +6 -1
  54. data/spec/rubocop/cop/style/collection_methods_spec.rb +5 -0
  55. data/spec/rubocop/cop/style/constant_name_spec.rb +9 -0
  56. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +14 -9
  57. data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +12 -7
  58. data/spec/rubocop/cop/style/empty_literal_spec.rb +42 -27
  59. data/spec/rubocop/cop/style/even_odd_spec.rb +47 -0
  60. data/spec/rubocop/cop/style/favor_modifier_spec.rb +15 -14
  61. data/spec/rubocop/cop/style/hash_methods_spec.rb +51 -0
  62. data/spec/rubocop/cop/style/indentation_width_spec.rb +390 -0
  63. data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +58 -50
  64. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +6 -1
  65. data/spec/rubocop/cop/style/nil_comparison_spec.rb +31 -0
  66. data/spec/rubocop/cop/style/signal_exception_spec.rb +28 -0
  67. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +61 -0
  68. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +9 -2
  69. data/spec/rubocop/formatter/file_list_formatter_spec.rb +3 -3
  70. data/spec/rubocop/formatter/offence_count_formatter_spec.rb +52 -0
  71. data/spec/rubocop/formatter/progress_formatter_spec.rb +70 -84
  72. data/spec/rubocop/source_parser_spec.rb +1 -1
  73. metadata +29 -5
  74. data/lib/rubocop/cop/style/line_continuation.rb +0 -27
  75. data/spec/rubocop/cop/style/line_continuation_spec.rb +0 -26
@@ -6,88 +6,96 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe MethodAndVariableSnakeCase do
9
- let(:snake_case) { MethodAndVariableSnakeCase.new }
9
+ let(:cop) { described_class.new }
10
+ let(:highlights) { cop.offences.map { |o| o.location.source } }
10
11
 
11
12
  it 'registers an offence for camel case in instance method name' do
12
- inspect_source(snake_case,
13
- ['def myMethod',
14
- ' # ...',
15
- 'end',
16
- ])
17
- expect(snake_case.offences.map(&:message)).to eq(
18
- ['Use snake_case for methods and variables.'])
13
+ inspect_source(cop, ['def myMethod',
14
+ ' # ...',
15
+ 'end'])
16
+ expect(cop.offences).to have(1).item
17
+ expect(highlights).to eq(['myMethod'])
19
18
  end
20
19
 
21
20
  it 'registers an offence for camel case in singleton method name' do
22
- inspect_source(snake_case,
23
- ['def self.myMethod',
24
- ' # ...',
25
- 'end',
26
- ])
27
- expect(snake_case.offences.map(&:message)).to eq(
28
- ['Use snake_case for methods and variables.'])
21
+ inspect_source(cop, ['def self.myMethod',
22
+ ' # ...',
23
+ 'end'])
24
+ expect(cop.offences).to have(1).item
25
+ expect(highlights).to eq(['myMethod'])
29
26
  end
30
27
 
31
28
  it 'registers an offence for camel case in local variable name' do
32
- inspect_source(snake_case, ['myLocal = 1'])
33
- expect(snake_case.offences.map(&:message)).to eq(
34
- ['Use snake_case for methods and variables.'])
29
+ inspect_source(cop, 'myLocal = 1')
30
+ expect(cop.offences).to have(1).item
31
+ expect(highlights).to eq(['myLocal'])
35
32
  end
36
33
 
37
34
  it 'registers an offence for camel case in instance variable name' do
38
- inspect_source(snake_case, ['@myAttribute = 3'])
39
- expect(snake_case.offences.map(&:message)).to eq(
40
- ['Use snake_case for methods and variables.'])
35
+ inspect_source(cop, '@myAttribute = 3')
36
+ expect(cop.offences).to have(1).item
37
+ expect(highlights).to eq(['@myAttribute'])
41
38
  end
42
39
 
43
40
  it 'registers an offence for camel case in setter name' do
44
- inspect_source(snake_case, ['self.mySetter = 2'])
45
- expect(snake_case.offences.map(&:message)).to eq(
46
- ['Use snake_case for methods and variables.'])
41
+ inspect_source(cop, 'self.mySetter = 2')
42
+ expect(cop.offences).to have(1).item
43
+ expect(highlights).to eq(['mySetter'])
47
44
  end
48
45
 
49
46
  it 'registers an offence for capitalized camel case' do
50
- inspect_source(snake_case,
51
- ['def MyMethod',
52
- 'end',
53
- ])
54
- expect(snake_case.offences.map(&:message)).to eq(
55
- ['Use snake_case for methods and variables.'])
47
+ inspect_source(cop, ['def MyMethod',
48
+ 'end'])
49
+ expect(cop.offences).to have(1).item
50
+ expect(highlights).to eq(['MyMethod'])
56
51
  end
57
52
 
58
53
  it 'accepts snake case in names' do
59
- inspect_source(snake_case,
60
- ['def my_method',
61
- ' my_local_html = 1',
62
- ' self.my_setter = 2',
63
- ' @my_attribute = 3',
64
- 'end',
65
- ])
66
- expect(snake_case.offences.map(&:message)).to be_empty
54
+ inspect_source(cop, ['def my_method',
55
+ ' my_local_html = 1',
56
+ ' self.my_setter = 2',
57
+ ' @my_attribute = 3',
58
+ 'end'])
59
+ expect(cop.offences).to be_empty
67
60
  end
68
61
 
69
62
  it 'registers an offence for mixed snake case and camel case' do
70
- inspect_source(snake_case,
71
- ['def visit_Arel_Nodes_SelectStatement',
72
- 'end'])
73
- expect(snake_case.offences.map(&:message)).to eq(
74
- ['Use snake_case for methods and variables.'])
63
+ inspect_source(cop, ['def visit_Arel_Nodes_SelectStatement',
64
+ 'end'])
65
+ expect(cop.offences).to have(1).item
66
+ expect(highlights).to eq(['visit_Arel_Nodes_SelectStatement'])
75
67
  end
76
68
 
77
69
  it 'accepts screaming snake case globals' do
78
- inspect_source(snake_case, ['$MY_GLOBAL = 0'])
79
- expect(snake_case.offences.map(&:message)).to be_empty
70
+ inspect_source(cop, '$MY_GLOBAL = 0')
71
+ expect(cop.offences).to be_empty
80
72
  end
81
73
 
82
74
  it 'accepts screaming snake case constants' do
83
- inspect_source(snake_case, ['MY_CONSTANT = 0'])
84
- expect(snake_case.offences.map(&:message)).to be_empty
75
+ inspect_source(cop, 'MY_CONSTANT = 0')
76
+ expect(cop.offences).to be_empty
85
77
  end
86
78
 
87
79
  it 'accepts assigning to camel case constant' do
88
- inspect_source(snake_case,
89
- ['Paren = Struct.new :left, :right, :kind'])
90
- expect(snake_case.offences.map(&:message)).to be_empty
80
+ inspect_source(cop, 'Paren = Struct.new :left, :right, :kind')
81
+ expect(cop.offences).to be_empty
82
+ end
83
+
84
+ it 'accepts one line methods' do
85
+ inspect_source(cop, "def body; '' end")
86
+ expect(cop.offences).to be_empty
87
+ end
88
+
89
+ it 'accepts operator definitions' do
90
+ inspect_source(cop, ['def +(other)',
91
+ ' # ...',
92
+ 'end'])
93
+ expect(cop.offences).to be_empty
94
+ end
95
+
96
+ it 'accepts assignment with indexing of self' do
97
+ inspect_source(cop, 'self[:a] = b')
98
+ expect(cop.offences).to be_empty
91
99
  end
92
100
  end
93
101
  end
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe MethodCallParentheses do
9
- let(:cop) { MethodCallParentheses.new }
9
+ let(:cop) { described_class.new }
10
10
 
11
11
  it 'registers an offence for parens in method call without args' do
12
12
  inspect_source(cop, ['top.test()'])
@@ -19,6 +19,11 @@ module Rubocop
19
19
  it 'it accepts parens in method call with args' do
20
20
  inspect_source(cop, ['top.test(a)'])
21
21
  end
22
+
23
+ it 'auto-corrects by removing unneeded braces' do
24
+ new_source = autocorrect_source(cop, 'test()')
25
+ expect(new_source).to eq('test')
26
+ end
22
27
  end
23
28
  end
24
29
  end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Style
8
+ describe NilComparison do
9
+ let(:cop) { described_class.new }
10
+
11
+ it 'registers an offence for == nil' do
12
+ inspect_source(cop,
13
+ ['x == nil'])
14
+ expect(cop.offences.size).to eq(1)
15
+ end
16
+
17
+ it 'registers an offence for === nil' do
18
+ inspect_source(cop,
19
+ ['x === nil'])
20
+ expect(cop.offences.size).to eq(1)
21
+ end
22
+
23
+ it 'registers an offence for === nil' do
24
+ inspect_source(cop,
25
+ ['x != nil'])
26
+ expect(cop.offences.size).to eq(1)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -68,6 +68,34 @@ module Rubocop
68
68
  expect(cop.messages).to eq([SignalException::FAIL_MSG] * 2 +
69
69
  [SignalException::RAISE_MSG])
70
70
  end
71
+
72
+ it 'auto-corrects raise to fail when appropriate' do
73
+ new_source = autocorrect_source(cop,
74
+ ['begin',
75
+ ' raise',
76
+ 'rescue Exception',
77
+ ' raise',
78
+ 'end'])
79
+ expect(new_source).to eq(['begin',
80
+ ' fail',
81
+ 'rescue Exception',
82
+ ' raise',
83
+ 'end'].join("\n"))
84
+ end
85
+
86
+ it 'auto-corrects fail to raise when appropriate' do
87
+ new_source = autocorrect_source(cop,
88
+ ['begin',
89
+ ' fail',
90
+ 'rescue Exception',
91
+ ' fail',
92
+ 'end'])
93
+ expect(new_source).to eq(['begin',
94
+ ' fail',
95
+ 'rescue Exception',
96
+ ' raise',
97
+ 'end'].join("\n"))
98
+ end
71
99
  end
72
100
  end
73
101
  end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Style
8
+ describe SpaceAfterMethodName do
9
+ let(:cop) { SpaceAfterMethodName.new }
10
+
11
+ it 'registers an offence for def with space before the parenthesis' do
12
+ inspect_source(cop,
13
+ ['def func (x)',
14
+ ' a',
15
+ 'end'])
16
+ expect(cop.offences).to have(1).item
17
+ end
18
+
19
+ it 'registers an offence for defs with space before the parenthesis' do
20
+ inspect_source(cop,
21
+ ['def self.func (x)',
22
+ ' a',
23
+ 'end'])
24
+ expect(cop.offences).to have(1).item
25
+ end
26
+
27
+ it 'accepts a def without arguments' do
28
+ inspect_source(cop,
29
+ ['def func',
30
+ ' a',
31
+ 'end'])
32
+ expect(cop.offences).to be_empty
33
+ end
34
+
35
+ it 'accepts a defs without arguments' do
36
+ inspect_source(cop,
37
+ ['def self.func',
38
+ ' a',
39
+ 'end'])
40
+ expect(cop.offences).to be_empty
41
+ end
42
+
43
+ it 'accepts a def with arguments but no parentheses' do
44
+ inspect_source(cop,
45
+ ['def func x',
46
+ ' a',
47
+ 'end'])
48
+ expect(cop.offences).to be_empty
49
+ end
50
+
51
+ it 'accepts a defs with arguments but no parentheses' do
52
+ inspect_source(cop,
53
+ ['def self.func x',
54
+ ' a',
55
+ 'end'])
56
+ expect(cop.offences).to be_empty
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -9,7 +9,7 @@ module Rubocop
9
9
  let(:formatter) { EmacsStyleFormatter.new(output) }
10
10
  let(:output) { StringIO.new }
11
11
 
12
- describe '#report_file' do
12
+ describe '#file_finished' do
13
13
  it 'displays parsable text' do
14
14
  cop = Cop::Cop.new
15
15
  source_buffer = Parser::Source::Buffer.new('test', 1)
@@ -22,11 +22,18 @@ module Rubocop
22
22
  Parser::Source::Range.new(source_buffer, 9, 10),
23
23
  'message 2')
24
24
 
25
- formatter.report_file('test', cop.offences)
25
+ formatter.file_finished('test', cop.offences)
26
26
  expect(output.string).to eq ['test:1:1: C: message 1',
27
27
  "test:3:6: F: message 2\n"].join("\n")
28
28
  end
29
29
  end
30
+
31
+ describe '#finished' do
32
+ it 'does not report summary' do
33
+ formatter.finished(['/path/to/file'])
34
+ expect(output.string).to be_empty
35
+ end
36
+ end
30
37
  end
31
38
  end
32
39
  end
@@ -9,7 +9,7 @@ module Rubocop
9
9
  let(:formatter) { FileListFormatter.new(output) }
10
10
  let(:output) { StringIO.new }
11
11
 
12
- describe '#report_file' do
12
+ describe '#file_finished' do
13
13
  it 'displays parsable text' do
14
14
  cop = Cop::Cop.new
15
15
  source_buffer = Parser::Source::Buffer.new('test', 1)
@@ -22,8 +22,8 @@ module Rubocop
22
22
  Parser::Source::Range.new(source_buffer, 9, 10),
23
23
  'message 2')
24
24
 
25
- formatter.report_file('test', cop.offences)
26
- formatter.report_file('test_2', cop.offences)
25
+ formatter.file_finished('test', cop.offences)
26
+ formatter.file_finished('test_2', cop.offences)
27
27
  expect(output.string).to eq ['test',
28
28
  "test_2\n"].join("\n")
29
29
  end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ require 'tempfile'
6
+
7
+ module Rubocop
8
+ module Formatter
9
+ describe OffenceCountFormatter do
10
+ subject(:formatter) { Formatter::OffenceCountFormatter.new(output) }
11
+ let(:output) { StringIO.new }
12
+
13
+ let(:files) do
14
+ %w(lib/rubocop.rb spec/spec_helper.rb bin/rubocop).map do |path|
15
+ File.expand_path(path)
16
+ end
17
+ end
18
+
19
+ describe '#file_finished' do
20
+ before { formatter.started(files) }
21
+
22
+ let(:finish) { formatter.file_finished(files.first, offences) }
23
+
24
+ context 'when no offences are detected' do
25
+ let(:offences) { [] }
26
+ it 'shouldn\'t add to offence_counts' do
27
+ expect { finish }.to_not change { formatter.offence_counts }
28
+ end
29
+ end
30
+
31
+ context 'when any offences are detected' do
32
+ let(:offences) { [double('offence', cop_name: 'OffendedCop')] }
33
+ it 'should increment the count for the cop in offence_counts' do
34
+ expect { finish }.to change { formatter.offence_counts }
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#report_summary' do
40
+ context 'when a offence detected' do
41
+ let(:cop_counts) { { 'OffendedCop' => 1 } }
42
+ it 'shows the cop and the offence count' do
43
+ formatter.report_summary(1, cop_counts)
44
+ expect(output.string).to include(
45
+ "\n1 OffendedCop")
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -95,101 +95,87 @@ module Rubocop
95
95
  formatter.started(files)
96
96
  end
97
97
 
98
- context 'when #reports_summary? is true' do
99
- before { formatter.reports_summary = true }
100
-
101
- context 'when any offences are detected' do
102
- before do
103
- source_buffer = Parser::Source::Buffer.new('test', 1)
104
- source = 9.times.map do |index|
105
- "This is line #{index + 1}."
106
- end
107
- source_buffer.source = source.join("\n")
108
- line_length = source[0].length + "\n".length
109
-
110
- formatter.file_started(files[0], {})
111
- formatter.file_finished(files[0], [
112
- Cop::Offence.new(
113
- :convention,
114
- Parser::Source::Range.new(source_buffer,
115
- line_length + 2,
116
- line_length + 3),
117
- 'foo',
118
- 'Cop'
119
- )
120
- ])
121
-
122
- formatter.file_started(files[1], {})
123
- formatter.file_finished(files[1], [
124
- ])
125
-
126
- formatter.file_started(files[2], {})
127
- formatter.file_finished(files[2], [
128
- Cop::Offence.new(
129
- :error,
130
- Parser::Source::Range.new(source_buffer,
131
- 4 * line_length + 1,
132
- 4 * line_length + 2),
133
- 'bar',
134
- 'Cop'
135
- ),
136
- Cop::Offence.new(
137
- :convention,
138
- Parser::Source::Range.new(source_buffer,
139
- 5 * line_length,
140
- 5 * line_length + 1),
141
- 'foo',
142
- 'Cop'
143
- )
144
- ])
145
- end
146
-
147
- it 'reports all detected offences for all failed files' do
148
- formatter.finished(files)
149
- expect(output.string).to include([
150
- 'Offences:',
151
- '',
152
- 'lib/rubocop.rb:2:3: C: foo',
153
- 'This is line 2.',
154
- ' ^',
155
- 'bin/rubocop:5:2: E: bar',
156
- 'This is line 5.',
157
- ' ^',
158
- 'bin/rubocop:6:1: C: foo',
159
- 'This is line 6.',
160
- '^'
161
- ].join("\n"))
98
+ context 'when any offences are detected' do
99
+ before do
100
+ source_buffer = Parser::Source::Buffer.new('test', 1)
101
+ source = 9.times.map do |index|
102
+ "This is line #{index + 1}."
162
103
  end
104
+ source_buffer.source = source.join("\n")
105
+ line_length = source[0].length + "\n".length
106
+
107
+ formatter.file_started(files[0], {})
108
+ formatter.file_finished(files[0], [
109
+ Cop::Offence.new(
110
+ :convention,
111
+ Parser::Source::Range.new(source_buffer,
112
+ line_length + 2,
113
+ line_length + 3),
114
+ 'foo',
115
+ 'Cop'
116
+ )
117
+ ])
118
+
119
+ formatter.file_started(files[1], {})
120
+ formatter.file_finished(files[1], [
121
+ ])
122
+
123
+ formatter.file_started(files[2], {})
124
+ formatter.file_finished(files[2], [
125
+ Cop::Offence.new(
126
+ :error,
127
+ Parser::Source::Range.new(source_buffer,
128
+ 4 * line_length + 1,
129
+ 4 * line_length + 2),
130
+ 'bar',
131
+ 'Cop'
132
+ ),
133
+ Cop::Offence.new(
134
+ :convention,
135
+ Parser::Source::Range.new(source_buffer,
136
+ 5 * line_length,
137
+ 5 * line_length + 1),
138
+ 'foo',
139
+ 'Cop'
140
+ )
141
+ ])
163
142
  end
164
143
 
165
- context 'when no offences are detected' do
166
- before do
167
- files.each do |file|
168
- formatter.file_started(file, {})
169
- formatter.file_finished(file, [])
170
- end
171
- end
144
+ it 'reports all detected offences for all failed files' do
145
+ formatter.finished(files)
146
+ expect(output.string).to include([
147
+ 'Offences:',
148
+ '',
149
+ 'lib/rubocop.rb:2:3: C: foo',
150
+ 'This is line 2.',
151
+ ' ^',
152
+ 'bin/rubocop:5:2: E: bar',
153
+ 'This is line 5.',
154
+ ' ^',
155
+ 'bin/rubocop:6:1: C: foo',
156
+ 'This is line 6.',
157
+ '^'
158
+ ].join("\n"))
159
+ end
160
+ end
172
161
 
173
- it 'does not report offences' do
174
- formatter.finished(files)
175
- expect(output.string).not_to include('Offences:')
162
+ context 'when no offences are detected' do
163
+ before do
164
+ files.each do |file|
165
+ formatter.file_started(file, {})
166
+ formatter.file_finished(file, [])
176
167
  end
177
168
  end
178
169
 
179
- it 'calls #report_summary' do
180
- formatter.should_receive(:report_summary)
170
+ it 'does not report offences' do
181
171
  formatter.finished(files)
172
+ expect(output.string).not_to include('Offences:')
182
173
  end
183
174
  end
184
175
 
185
- context 'when #reports_summary? is false' do
186
- before { formatter.reports_summary = false }
187
-
188
- it 'reports nothing' do
189
- output.string = ''
190
- formatter.finished(files)
191
- expect(output.string).to eq("\n")
192
- end
176
+ it 'calls #report_summary' do
177
+ formatter.should_receive(:report_summary)
178
+ formatter.finished(files)
193
179
  end
194
180
  end
195
181
  end