rubocop 0.3.0 → 0.4.0

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.
Files changed (83) hide show
  1. data/.rubocop.yml +40 -0
  2. data/.travis.yml +1 -0
  3. data/Gemfile +7 -10
  4. data/Gemfile.lock +21 -19
  5. data/README.md +62 -5
  6. data/VERSION +1 -1
  7. data/bin/rubocop +1 -1
  8. data/lib/rubocop/cli.rb +35 -15
  9. data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -0
  10. data/lib/rubocop/cop/collection_methods.rb +29 -0
  11. data/lib/rubocop/cop/cop.rb +1 -1
  12. data/lib/rubocop/cop/def_parentheses.rb +4 -1
  13. data/lib/rubocop/cop/encoding.rb +6 -4
  14. data/lib/rubocop/cop/end_of_line.rb +1 -3
  15. data/lib/rubocop/cop/favor_modifier.rb +82 -0
  16. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +47 -0
  17. data/lib/rubocop/cop/grammar.rb +3 -2
  18. data/lib/rubocop/cop/indentation.rb +1 -1
  19. data/lib/rubocop/cop/line_length.rb +7 -3
  20. data/lib/rubocop/cop/method_and_variable_snake_case.rb +31 -0
  21. data/lib/rubocop/cop/new_lambda_literal.rb +17 -0
  22. data/lib/rubocop/cop/parentheses_around_condition.rb +24 -0
  23. data/lib/rubocop/cop/surrounding_space.rb +48 -47
  24. data/lib/rubocop/cop/syntax.rb +19 -0
  25. data/lib/rubocop/cop/tab.rb +1 -3
  26. data/lib/rubocop/report/plain_text.rb +1 -1
  27. data/lib/rubocop/report/report.rb +5 -2
  28. data/lib/rubocop/version.rb +1 -1
  29. data/lib/rubocop.rb +14 -0
  30. data/rubocop.gemspec +38 -22
  31. data/spec/rubocop/cli_spec.rb +120 -40
  32. data/spec/rubocop/cops/align_parameters_spec.rb +29 -29
  33. data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +4 -4
  34. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +34 -0
  35. data/spec/rubocop/cops/collection_methods_spec.rb +39 -0
  36. data/spec/rubocop/cops/cop_spec.rb +5 -5
  37. data/spec/rubocop/cops/def_with_parentheses_spec.rb +5 -5
  38. data/spec/rubocop/cops/def_without_parentheses_spec.rb +4 -4
  39. data/spec/rubocop/cops/empty_lines_spec.rb +8 -8
  40. data/spec/rubocop/cops/encoding_spec.rb +17 -11
  41. data/spec/rubocop/cops/end_of_line_spec.rb +5 -5
  42. data/spec/rubocop/cops/favor_modifier_spec.rb +112 -0
  43. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +62 -0
  44. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +45 -0
  45. data/spec/rubocop/cops/grammar_spec.rb +14 -9
  46. data/spec/rubocop/cops/hash_syntax_spec.rb +10 -10
  47. data/spec/rubocop/cops/if_with_semicolon_spec.rb +3 -3
  48. data/spec/rubocop/cops/indentation_spec.rb +7 -7
  49. data/spec/rubocop/cops/line_length_spec.rb +4 -4
  50. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +47 -0
  51. data/spec/rubocop/cops/multiline_blocks_spec.rb +4 -4
  52. data/spec/rubocop/cops/multiline_if_then_spec.rb +7 -7
  53. data/spec/rubocop/cops/new_lambda_literal_spec.rb +23 -0
  54. data/spec/rubocop/cops/numeric_literals_spec.rb +10 -10
  55. data/spec/rubocop/cops/offence_spec.rb +4 -4
  56. data/spec/rubocop/cops/one_line_conditional_spec.rb +2 -3
  57. data/spec/rubocop/cops/parameter_lists_spec.rb +4 -4
  58. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +64 -0
  59. data/spec/rubocop/cops/single_line_blocks_spec.rb +4 -4
  60. data/spec/rubocop/cops/space_after_colon_spec.rb +5 -5
  61. data/spec/rubocop/cops/space_after_comma_spec.rb +3 -3
  62. data/spec/rubocop/cops/space_after_semicolon_spec.rb +3 -3
  63. data/spec/rubocop/cops/space_around_braces_spec.rb +6 -6
  64. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +22 -0
  65. data/spec/rubocop/cops/space_around_operators_spec.rb +50 -25
  66. data/spec/rubocop/cops/space_inside_brackets_spec.rb +8 -8
  67. data/spec/rubocop/cops/space_inside_parens_spec.rb +4 -4
  68. data/spec/rubocop/cops/string_literals_spec.rb +5 -5
  69. data/spec/rubocop/cops/syntax_spec.rb +18 -0
  70. data/spec/rubocop/cops/tab_spec.rb +3 -3
  71. data/spec/rubocop/cops/ternary_operator_spec.rb +8 -8
  72. data/spec/rubocop/cops/trailing_whitespace_spec.rb +4 -4
  73. data/spec/rubocop/cops/unless_else_spec.rb +4 -4
  74. data/spec/rubocop/cops/when_then_spec.rb +5 -5
  75. data/spec/rubocop/reports/emacs_style_spec.rb +3 -3
  76. data/spec/rubocop/reports/report_spec.rb +5 -5
  77. data/spec/spec_helper.rb +6 -0
  78. metadata +57 -28
  79. data/.rbenv-version +0 -1
  80. data/.rvmrc +0 -1
  81. data/features/rubocop.feature +0 -9
  82. data/features/step_definitions/rubocop_steps.rb +0 -1
  83. data/features/support/env.rb +0 -15
@@ -10,24 +10,33 @@ module Rubocop
10
10
  after(:each) { $stdout = STDOUT }
11
11
 
12
12
  it 'exits cleanly when -h is used' do
13
- lambda { cli.run ['-h'] }.should exit_with_code(0)
14
- lambda { cli.run ['--help'] }.should exit_with_code(0)
13
+ expect { cli.run ['-h'] }.to exit_with_code(0)
14
+ expect { cli.run ['--help'] }.to exit_with_code(0)
15
15
  message = ['Usage: rubocop [options] [file1, file2, ...]',
16
- ' -v, --[no-]verbose Run verbosely',
16
+ ' -d, --[no-]debug Display debug info',
17
17
  ' -e, --emacs Emacs style output',
18
18
  ' -c, --config FILE Configuration file',
19
- ' -s, --silent Silence summary']
20
- $stdout.string.should == (message * 2).join("\n") + "\n"
19
+ ' -s, --silent Silence summary',
20
+ ' -v, --version Display version']
21
+ expect($stdout.string).to eq((message * 2).join("\n") + "\n")
22
+ end
23
+
24
+ it 'exits cleanly when -v is used' do
25
+ expect { cli.run ['-v'] }.to exit_with_code(0)
26
+ expect { cli.run ['--version'] }.to exit_with_code(0)
27
+ expect($stdout.string).to eq((Rubocop::VERSION + "\n") * 2)
21
28
  end
22
29
 
23
30
  it 'checks a given correct file and returns 0' do
24
31
  File.open('example.rb', 'w') do |f|
25
32
  f.puts '# encoding: utf-8'
26
33
  f.puts 'x = 0'
34
+ f.puts 'puts x'
27
35
  end
28
36
  begin
29
- cli.run(['example.rb']).should == 0
30
- $stdout.string.should == "\n1 files inspected, 0 offences detected\n"
37
+ expect(cli.run(['example.rb'])).to eq(0)
38
+ expect($stdout.string.uncolored)
39
+ .to eq("\n1 files inspected, 0 offences detected\n")
31
40
  ensure
32
41
  File.delete 'example.rb'
33
42
  end
@@ -37,52 +46,95 @@ module Rubocop
37
46
  File.open('example.rb', 'w') do |f|
38
47
  f.puts '# encoding: utf-8'
39
48
  f.puts 'x = 0 '
49
+ f.puts 'puts x'
40
50
  end
41
51
  begin
42
- cli.run(['example.rb']).should == 1
43
- $stdout.string.should == ['== example.rb ==',
44
- 'C: 2: Trailing whitespace detected.',
45
- '',
46
- '1 files inspected, 1 offences detected',
47
- ''].join("\n")
52
+ expect(cli.run(['example.rb'])).to eq(1)
53
+ expect($stdout.string.uncolored)
54
+ .to eq ['== example.rb ==',
55
+ 'C: 2: Trailing whitespace detected.',
56
+ '',
57
+ '1 files inspected, 1 offences detected',
58
+ ''].join("\n")
48
59
  ensure
49
60
  File.delete 'example.rb'
50
61
  end
51
62
  end
52
63
 
53
- it 'can report in emacs style' do
54
- File.open('example1.rb', 'w') { |f| f.puts 'x = 0 ' }
55
- File.open('example2.rb', 'w') { |f| f.puts "\tx = 0" }
64
+ it 'can report in emacs style', ruby: 1.9 do
65
+ File.open('example1.rb', 'w') { |f| f.puts 'x= 0 ', 'y ', 'puts x' }
66
+ File.open('example2.rb', 'w') { |f| f.puts "\tx = 0", 'puts x' }
56
67
  begin
57
- cli.run(['--emacs', 'example1.rb', 'example2.rb']).should == 1
58
- $stdout.string.should ==
68
+ expect(cli.run(['--emacs', 'example1.rb', 'example2.rb'])).to eq(1)
69
+ expect($stdout.string.uncolored)
70
+ .to eq(
59
71
  ['example1.rb:1: C: Missing encoding comment.',
60
72
  'example1.rb:1: C: Trailing whitespace detected.',
73
+ "example1.rb:1: C: Surrounding space missing for operator '='.",
74
+ 'example1.rb:2: C: Trailing whitespace detected.',
61
75
  'example2.rb:1: C: Missing encoding comment.',
62
76
  'example2.rb:1: C: Tab detected.',
63
77
  '',
78
+ '2 files inspected, 6 offences detected',
79
+ ''].join("\n"))
80
+ ensure
81
+ File.delete 'example1.rb'
82
+ File.delete 'example2.rb'
83
+ end
84
+ end
85
+
86
+ it 'can report in emacs style', ruby: 2.0 do
87
+ File.open('example1.rb', 'w') { |f| f.puts 'x= 0 ', 'y ', 'puts x' }
88
+ File.open('example2.rb', 'w') { |f| f.puts "\tx = 0", 'puts x' }
89
+ begin
90
+ expect(cli.run(['--emacs', 'example1.rb', 'example2.rb'])).to eq(1)
91
+ expect($stdout.string.uncolored)
92
+ .to eq(
93
+ ['example1.rb:1: C: Trailing whitespace detected.',
94
+ "example1.rb:1: C: Surrounding space missing for operator '='.",
95
+ 'example1.rb:2: C: Trailing whitespace detected.',
96
+ 'example2.rb:1: C: Tab detected.',
97
+ '',
64
98
  '2 files inspected, 4 offences detected',
65
- ''].join("\n")
99
+ ''].join("\n"))
66
100
  ensure
67
101
  File.delete 'example1.rb'
68
102
  File.delete 'example2.rb'
69
103
  end
70
104
  end
71
105
 
72
- it 'ommits summary when --silent passed' do
73
- File.open('example1.rb', 'w') { |f| f.puts 'x = 0 ' }
74
- File.open('example2.rb', 'w') { |f| f.puts "\tx = 0" }
106
+ it 'ommits summary when --silent passed', ruby: 1.9 do
107
+ File.open('example1.rb', 'w') { |f| f.puts 'puts 0 ' }
108
+ File.open('example2.rb', 'w') { |f| f.puts "\tputs 0" }
75
109
  begin
76
- cli.run(['--emacs',
77
- '--silent',
78
- 'example1.rb',
79
- 'example2.rb']).should == 1
80
- $stdout.string.should ==
110
+ expect(cli.run(['--emacs',
111
+ '--silent',
112
+ 'example1.rb',
113
+ 'example2.rb'])).to eq(1)
114
+ expect($stdout.string).to eq(
81
115
  ['example1.rb:1: C: Missing encoding comment.',
82
116
  'example1.rb:1: C: Trailing whitespace detected.',
83
117
  'example2.rb:1: C: Missing encoding comment.',
84
118
  'example2.rb:1: C: Tab detected.',
85
- ''].join("\n")
119
+ ''].join("\n"))
120
+ ensure
121
+ File.delete 'example1.rb'
122
+ File.delete 'example2.rb'
123
+ end
124
+ end
125
+
126
+ it 'ommits summary when --silent passed', ruby: 2.0 do
127
+ File.open('example1.rb', 'w') { |f| f.puts 'puts 0 ' }
128
+ File.open('example2.rb', 'w') { |f| f.puts "\tputs 0" }
129
+ begin
130
+ expect(cli.run(['--emacs',
131
+ '--silent',
132
+ 'example1.rb',
133
+ 'example2.rb'])).to eq(1)
134
+ expect($stdout.string).to eq(
135
+ ['example1.rb:1: C: Trailing whitespace detected.',
136
+ 'example2.rb:1: C: Tab detected.',
137
+ ''].join("\n"))
86
138
  ensure
87
139
  File.delete 'example1.rb'
88
140
  File.delete 'example2.rb'
@@ -90,7 +142,7 @@ module Rubocop
90
142
  end
91
143
 
92
144
  it 'can be configured with option to disable a certain error' do
93
- File.open('example1.rb', 'w') { |f| f.puts 'x = 0 ' }
145
+ File.open('example1.rb', 'w') { |f| f.puts 'puts 0 ' }
94
146
  File.open('rubocop.yml', 'w') do |f|
95
147
  f.puts('Encoding:',
96
148
  ' Enabled: false',
@@ -99,14 +151,13 @@ module Rubocop
99
151
  ' Enabled: false')
100
152
  end
101
153
  begin
102
- return_code = cli.run(['-c', 'rubocop.yml', 'example1.rb'])
103
- $stdout.string.should ==
154
+ expect(cli.run(['-c', 'rubocop.yml', 'example1.rb'])).to eq(1)
155
+ expect($stdout.string.uncolored).to eq(
104
156
  ['== example1.rb ==',
105
157
  'C: 1: Trailing whitespace detected.',
106
158
  '',
107
159
  '1 files inspected, 1 offences detected',
108
- ''].join("\n")
109
- return_code.should == 1
160
+ ''].join("\n"))
110
161
  ensure
111
162
  File.delete 'example1.rb'
112
163
  File.delete 'rubocop.yml'
@@ -115,7 +166,7 @@ module Rubocop
115
166
 
116
167
  it 'can be configured with project config to disable a certain error' do
117
168
  FileUtils.mkdir 'example_src'
118
- File.open('example_src/example1.rb', 'w') { |f| f.puts 'x = 0 ' }
169
+ File.open('example_src/example1.rb', 'w') { |f| f.puts 'puts 0 ' }
119
170
  File.open('example_src/.rubocop.yml', 'w') do |f|
120
171
  f.puts('Encoding:',
121
172
  ' Enabled: false',
@@ -124,14 +175,34 @@ module Rubocop
124
175
  ' Enabled: false')
125
176
  end
126
177
  begin
127
- return_code = cli.run(['example_src/example1.rb'])
128
- $stdout.string.should ==
178
+ expect(cli.run(['example_src/example1.rb'])).to eq(1)
179
+ expect($stdout.string.uncolored).to eq(
129
180
  ['== example_src/example1.rb ==',
130
181
  'C: 1: Trailing whitespace detected.',
131
182
  '',
132
183
  '1 files inspected, 1 offences detected',
133
- ''].join("\n")
134
- return_code.should == 1
184
+ ''].join("\n"))
185
+ ensure
186
+ FileUtils.rm_rf 'example_src'
187
+ end
188
+ end
189
+
190
+ it 'can use an alternative max line length from a config file' do
191
+ FileUtils.mkdir 'example_src'
192
+ File.open('example_src/example1.rb', 'w') do |f|
193
+ f.puts '# encoding: utf-8'
194
+ f.puts '#' * 90
195
+ end
196
+ File.open('example_src/.rubocop.yml', 'w') do |f|
197
+ f.puts('LineLength:',
198
+ ' Enabled: true',
199
+ ' Max: 100')
200
+ end
201
+ begin
202
+ expect(cli.run(['example_src/example1.rb'])).to eq(0)
203
+ expect($stdout.string.uncolored).to eq(
204
+ ['', '1 files inspected, 0 offences detected',
205
+ ''].join("\n"))
135
206
  ensure
136
207
  FileUtils.rm_rf 'example_src'
137
208
  end
@@ -139,7 +210,9 @@ module Rubocop
139
210
 
140
211
  it 'finds no violations when checking the rubocop source code' do
141
212
  cli.run
142
- $stdout.string.should =~ /files inspected, 0 offences detected\n/
213
+ expect($stdout.string.uncolored).to match(
214
+ /files inspected, 0 offences detected\n/
215
+ )
143
216
  end
144
217
 
145
218
  it 'can process a file with an invalide UTF-8 byte sequence' do
@@ -148,11 +221,18 @@ module Rubocop
148
221
  f.puts "# \xf9\x29"
149
222
  end
150
223
  begin
151
- cli.run(['--emacs', 'example.rb']).should == 0
224
+ expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
152
225
  ensure
153
226
  File.delete 'example.rb'
154
227
  end
155
228
  end
229
+
230
+ it 'has configuration for all cops in .rubocop.yml' do
231
+ cop_names = Cop::Cop.all.map do |cop_class|
232
+ cop_class.name.split('::').last
233
+ end
234
+ expect(YAML.load_file('.rubocop.yml').keys.sort).to eq(cop_names.sort)
235
+ end
156
236
  end
157
237
  end
158
238
  end
@@ -5,22 +5,22 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe AlignParameters do
8
- let (:align) { AlignParameters.new }
8
+ let(:align) { AlignParameters.new }
9
9
 
10
10
  it 'registers an offence for parameters with single indent' do
11
11
  inspect_source(align, 'file.rb', ['function(a,',
12
12
  ' if b then c else d end)'])
13
- align.offences.map(&:message).should ==
13
+ expect(align.offences.map(&:message)).to eq(
14
14
  ['Align the parameters of a method call if they span more than ' +
15
- 'one line.']
15
+ 'one line.'])
16
16
  end
17
17
 
18
18
  it 'registers an offence for parameters with double indent' do
19
19
  inspect_source(align, 'file.rb', ['function(a,',
20
20
  ' if b then c else d end)'])
21
- align.offences.map(&:message).should ==
21
+ expect(align.offences.map(&:message)).to eq(
22
22
  ['Align the parameters of a method call if they span more than ' +
23
- 'one line.']
23
+ 'one line.'])
24
24
  end
25
25
 
26
26
  it 'accepts correctly aligned parameters' do
@@ -28,19 +28,19 @@ module Rubocop
28
28
  ' 0, 1,',
29
29
  ' (x + y),',
30
30
  ' if b then c else d end)'])
31
- align.offences.map(&:message).should == []
31
+ expect(align.offences.map(&:message)).to be_empty
32
32
  end
33
33
 
34
34
  it 'accepts calls that only span one line' do
35
35
  inspect_source(align, 'file.rb', ['find(path, s, @special[sexp[0]])'])
36
- align.offences.map(&:message).should == []
36
+ expect(align.offences.map(&:message)).to be_empty
37
37
  end
38
38
 
39
39
  it "doesn't get confused by a symbol argument" do
40
40
  inspect_source(align, '',
41
41
  ['add_offence(:convention, index,',
42
42
  ' ERROR_MESSAGE % kind)'])
43
- align.offences.map(&:message).should == []
43
+ expect(align.offences.map(&:message)).to be_empty
44
44
  end
45
45
 
46
46
  it "doesn't get confused by splat operator" do
@@ -53,49 +53,49 @@ module Rubocop
53
53
  ' c)',
54
54
  'func3(*a)',
55
55
  ])
56
- align.offences.map(&:to_s).should ==
56
+ expect(align.offences.map(&:to_s)).to eq(
57
57
  ['C: 5: Align the parameters of a method call if they span ' +
58
- 'more than one line.']
58
+ 'more than one line.'])
59
59
  end
60
60
 
61
61
  it 'can handle a correctly aligned string literal as first argument' do
62
62
  inspect_source(align, '',
63
63
  ['add_offence(:convention, x,',
64
64
  ' a)'])
65
- align.offences.map(&:message).should == []
65
+ expect(align.offences.map(&:message)).to be_empty
66
66
  end
67
67
 
68
68
  it 'can handle a string literal as other argument' do
69
69
  inspect_source(align, '',
70
70
  ['add_offence(:convention,',
71
71
  ' "", a)'])
72
- align.offences.map(&:message).should == []
72
+ expect(align.offences.map(&:message)).to be_empty
73
73
  end
74
74
 
75
75
  it "doesn't get confused by a line break inside a parameter" do
76
76
  inspect_source(align, '',
77
77
  ['read(path, { headers: true,',
78
78
  ' converters: :numeric })'])
79
- align.offences.map(&:message).should == []
79
+ expect(align.offences.map(&:message)).to be_empty
80
80
  end
81
81
 
82
82
  it "doesn't get confused by symbols with embedded expressions" do
83
83
  inspect_source(align, '',
84
84
  ['send(:"#{name}_comments_path")'])
85
- align.offences.map(&:message).should == []
85
+ expect(align.offences.map(&:message)).to be_empty
86
86
  end
87
87
 
88
88
  it "doesn't get confused by regexen with embedded expressions" do
89
89
  inspect_source(align, '',
90
90
  ['a(/#{name}/)'])
91
- align.offences.map(&:message).should == []
91
+ expect(align.offences.map(&:message)).to be_empty
92
92
  end
93
93
 
94
94
  it 'accepts braceless hashes' do
95
95
  inspect_source(align, '',
96
96
  ['run(collection, :entry_name => label,',
97
97
  ' :paginator => paginator)'])
98
- align.offences.map(&:message).should == []
98
+ expect(align.offences.map(&:message)).to be_empty
99
99
  end
100
100
 
101
101
  it 'accepts the first parameter being on a new row' do
@@ -104,7 +104,7 @@ module Rubocop
104
104
  ' a,',
105
105
  ' b',
106
106
  ' )'])
107
- align.offences.map(&:message).should == []
107
+ expect(align.offences.map(&:message)).to be_empty
108
108
  end
109
109
 
110
110
  it 'can handle heredoc strings' do
@@ -115,7 +115,7 @@ module Rubocop
115
115
  ' end',
116
116
  ' EOS']
117
117
  inspect_source(align, '', src)
118
- align.offences.map(&:message).should == []
118
+ expect(align.offences.map(&:message)).to be_empty
119
119
  end
120
120
 
121
121
  it 'can handle a method call within a method call' do
@@ -124,13 +124,13 @@ module Rubocop
124
124
  ' b(b1,',
125
125
  ' b2),',
126
126
  ' a2)'])
127
- align.offences.map(&:message).should == []
127
+ expect(align.offences.map(&:message)).to be_empty
128
128
  end
129
129
 
130
130
  it 'can handle a call embedded in a string' do
131
131
  inspect_source(align, '',
132
132
  ['model("#{index(name)}", child)'])
133
- align.offences.map(&:message).should == []
133
+ expect(align.offences.map(&:message)).to be_empty
134
134
  end
135
135
 
136
136
  it 'can handle do-end' do
@@ -138,7 +138,7 @@ module Rubocop
138
138
  [' run(lambda do |e|',
139
139
  " w = e['warden']",
140
140
  ' end)'])
141
- align.offences.map(&:message).should == []
141
+ expect(align.offences.map(&:message)).to be_empty
142
142
  end
143
143
 
144
144
  it 'can handle a call with a block inside another call' do
@@ -147,19 +147,19 @@ module Rubocop
147
147
  " col['name']",
148
148
  ' })']
149
149
  inspect_source(align, '', src)
150
- align.offences.map(&:message).should == []
150
+ expect(align.offences.map(&:message)).to be_empty
151
151
  end
152
152
 
153
153
  it 'can handle a ternary condition with a block reference' do
154
154
  src = ['cond ? a : func(&b)']
155
155
  inspect_source(align, '', src)
156
- align.offences.map(&:message).should == []
156
+ expect(align.offences.map(&:message)).to be_empty
157
157
  end
158
158
 
159
159
  it 'can handle parentheses used with no parameters' do
160
160
  src = ['func()']
161
161
  inspect_source(align, '', src)
162
- align.offences.map(&:message).should == []
162
+ expect(align.offences.map(&:message)).to be_empty
163
163
  end
164
164
 
165
165
  it 'can handle a multiline hash as first parameter' do
@@ -167,7 +167,7 @@ module Rubocop
167
167
  ' :space_before => "",',
168
168
  '}, state)']
169
169
  inspect_source(align, '', src)
170
- align.offences.map(&:message).should == []
170
+ expect(align.offences.map(&:message)).to be_empty
171
171
  end
172
172
 
173
173
  it 'can handle a multiline hash as second parameter' do
@@ -175,26 +175,26 @@ module Rubocop
175
175
  ' :value => value',
176
176
  '})']
177
177
  inspect_source(align, '', src)
178
- align.offences.map(&:message).should == []
178
+ expect(align.offences.map(&:message)).to be_empty
179
179
  end
180
180
 
181
181
  it 'can handle method calls without parentheses' do
182
182
  src = ['a(b c, d)']
183
183
  inspect_source(align, '', src)
184
- align.offences.map(&:message).should == []
184
+ expect(align.offences.map(&:message)).to be_empty
185
185
  end
186
186
 
187
187
  it 'can handle other method calls without parentheses' do
188
188
  src = ['chars(Unicode.apply_mapping @wrapped_string, :uppercase)']
189
189
  inspect_source(align, '', src)
190
- align.offences.map(&:message).should == []
190
+ expect(align.offences.map(&:message)).to be_empty
191
191
  end
192
192
 
193
193
  it "doesn't check alignment if tabs are used to indent" do
194
194
  src = ['a(b,',
195
195
  "\tc)"]
196
196
  inspect_source(align, '', src)
197
- align.offences.map(&:message).should == []
197
+ expect(align.offences.map(&:message)).to be_empty
198
198
  end
199
199
  end
200
200
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe AmpersandsPipesVsAndOr do
8
- let (:amp) { AmpersandsPipesVsAndOr.new }
8
+ let(:amp) { AmpersandsPipesVsAndOr.new }
9
9
 
10
10
  it 'registers an offence for AND used in condition of if statement' do
11
11
  check('if', 'and', '&&')
@@ -48,9 +48,9 @@ module Rubocop
48
48
  'end'])
49
49
  # Just one offence should be registered. The good_operator
50
50
  # should be accepted.
51
- amp.offences.map(&:message).should ==
52
- ['Use &&/|| for boolean expressions, and/or for control flow.']
53
- amp.offences[0].line_number.should == 1
51
+ expect(amp.offences.map(&:message)).to eq(
52
+ ['Use &&/|| for boolean expressions, and/or for control flow.'])
53
+ expect(amp.offences[0].line_number).to eq(1)
54
54
  end
55
55
  end
56
56
  end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe ClassAndModuleCamelCase do
8
+ let(:camel_case) { ClassAndModuleCamelCase.new }
9
+
10
+ it 'registers an offence for underscore in class and module name' do
11
+ inspect_source(camel_case, 'file.rb',
12
+ ['class My_Class',
13
+ 'end',
14
+ '',
15
+ 'module My_Module',
16
+ 'end',
17
+ ])
18
+ expect(camel_case.offences.map(&:message)).to eq(
19
+ ['Use CamelCase for classes and modules.'] * 2)
20
+ end
21
+
22
+ it 'accepts CamelCase names' do
23
+ inspect_source(camel_case, 'file.rb',
24
+ ['class MyClass',
25
+ 'end',
26
+ '',
27
+ 'module Mine',
28
+ 'end',
29
+ ])
30
+ expect(camel_case.offences.map(&:message)).to be_empty
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe CollectionMethods do
8
+ let(:cm) { CollectionMethods.new }
9
+
10
+ it 'registers an offence for collect' do
11
+ inspect_source(cm, 'file.rb', ['[1, 2, 3].collect { |e| e + 1 }'])
12
+ expect(cm.offences.size).to eq(1)
13
+ expect(cm.offences.map(&:message))
14
+ .to eq(['Prefer map over collect.'])
15
+ end
16
+
17
+ it 'registers an offence for inject' do
18
+ inspect_source(cm, 'file.rb', ['[1, 2, 3].inject { |e| e + 1 }'])
19
+ expect(cm.offences.size).to eq(1)
20
+ expect(cm.offences.map(&:message))
21
+ .to eq(['Prefer reduce over inject.'])
22
+ end
23
+
24
+ it 'registers an offence for detect' do
25
+ inspect_source(cm, 'file.rb', ['[1, 2, 3].detect { |e| e + 1 }'])
26
+ expect(cm.offences.size).to eq(1)
27
+ expect(cm.offences.map(&:message))
28
+ .to eq(['Prefer find over detect.'])
29
+ end
30
+
31
+ it 'registers an offence for find_all' do
32
+ inspect_source(cm, 'file.rb', ['[1, 2, 3].find_all { |e| e + 1 }'])
33
+ expect(cm.offences.size).to eq(1)
34
+ expect(cm.offences.map(&:message))
35
+ .to eq(['Prefer select over find_all.'])
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,26 +5,26 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe Cop do
8
- let (:cop) { Cop.new }
8
+ let(:cop) { Cop.new }
9
9
 
10
10
  it 'initially has 0 offences' do
11
- cop.offences.size.should == 0
11
+ expect(cop.offences).to be_empty
12
12
  end
13
13
 
14
14
  it 'initially has nothing to report' do
15
- cop.has_report?.should be_false
15
+ expect(cop.has_report?).to be_false
16
16
  end
17
17
 
18
18
  it 'keeps track of offences' do
19
19
  cop.add_offence(:convention, 1, 'message')
20
20
 
21
- cop.offences.size.should == 1
21
+ expect(cop.offences.size).to eq(1)
22
22
  end
23
23
 
24
24
  it 'will report registered offences' do
25
25
  cop.add_offence(:convention, 1, 'message')
26
26
 
27
- cop.has_report?.should be_true
27
+ expect(cop.has_report?).to be_true
28
28
  end
29
29
  end
30
30
  end
@@ -5,28 +5,28 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe DefWithParentheses do
8
- let (:def_par) { DefWithParentheses.new }
8
+ let(:def_par) { DefWithParentheses.new }
9
9
 
10
10
  it 'reports an offence for def with empty parens' do
11
11
  src = ['def func()',
12
12
  'end']
13
13
  inspect_source(def_par, '', src)
14
- def_par.offences.map(&:message).should ==
14
+ expect(def_par.offences.map(&:message)).to eq(
15
15
  ["Omit the parentheses in defs when the method doesn't accept any " +
16
- 'arguments.']
16
+ 'arguments.'])
17
17
  end
18
18
 
19
19
  it 'accepts def with arg and parens' do
20
20
  src = ['def func(a)',
21
21
  'end']
22
22
  inspect_source(def_par, '', src)
23
- def_par.offences.map(&:message).should == []
23
+ expect(def_par.offences.map(&:message)).to be_empty
24
24
  end
25
25
 
26
26
  it 'accepts empty parentheses in one liners' do
27
27
  src = ["def to_s() join '/' end"]
28
28
  inspect_source(def_par, '', src)
29
- def_par.offences.map(&:message).should == []
29
+ expect(def_par.offences.map(&:message)).to be_empty
30
30
  end
31
31
  end
32
32
  end
@@ -5,21 +5,21 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe DefWithoutParentheses do
8
- let (:def_par) { DefWithoutParentheses.new }
8
+ let(:def_par) { DefWithoutParentheses.new }
9
9
 
10
10
  it 'reports an offence for def with parameters but no parens' do
11
11
  src = ['def func a, b',
12
12
  'end']
13
13
  inspect_source(def_par, '', src)
14
- def_par.offences.map(&:message).should ==
15
- ['Use def with parentheses when there are arguments.']
14
+ expect(def_par.offences.map(&:message)).to eq(
15
+ ['Use def with parentheses when there are arguments.'])
16
16
  end
17
17
 
18
18
  it 'accepts def with no args and no parens' do
19
19
  src = ['def func',
20
20
  'end']
21
21
  inspect_source(def_par, '', src)
22
- def_par.offences.map(&:message).should == []
22
+ expect(def_par.offences.map(&:message)).to be_empty
23
23
  end
24
24
  end
25
25
  end