rubocop 0.3.0 → 0.6.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 (139) hide show
  1. data/.rubocop.yml +176 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +60 -0
  4. data/CONTRIBUTING.md +13 -6
  5. data/Gemfile +1 -13
  6. data/README.md +131 -6
  7. data/Rakefile +1 -15
  8. data/bin/rubocop +2 -1
  9. data/lib/rubocop/cli.rb +133 -21
  10. data/lib/rubocop/cop/alias.rb +18 -0
  11. data/lib/rubocop/cop/align_parameters.rb +5 -4
  12. data/lib/rubocop/cop/array_literal.rb +22 -0
  13. data/lib/rubocop/cop/ascii_identifiers_and_comments.rb +18 -0
  14. data/lib/rubocop/cop/avoid_class_vars.rb +20 -0
  15. data/lib/rubocop/cop/avoid_for.rb +17 -0
  16. data/lib/rubocop/cop/avoid_perl_backrefs.rb +20 -0
  17. data/lib/rubocop/cop/avoid_perlisms.rb +46 -0
  18. data/lib/rubocop/cop/blocks.rb +1 -1
  19. data/lib/rubocop/cop/brace_after_percent.rb +28 -0
  20. data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -0
  21. data/lib/rubocop/cop/collection_methods.rb +29 -0
  22. data/lib/rubocop/cop/cop.rb +16 -4
  23. data/lib/rubocop/cop/def_parentheses.rb +4 -1
  24. data/lib/rubocop/cop/encoding.rb +7 -5
  25. data/lib/rubocop/cop/end_of_line.rb +1 -3
  26. data/lib/rubocop/cop/ensure_return.rb +36 -0
  27. data/lib/rubocop/cop/favor_modifier.rb +82 -0
  28. data/lib/rubocop/cop/favor_percent_r.rb +19 -0
  29. data/lib/rubocop/cop/favor_sprintf.rb +37 -0
  30. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +47 -0
  31. data/lib/rubocop/cop/grammar.rb +12 -8
  32. data/lib/rubocop/cop/handle_exceptions.rb +21 -0
  33. data/lib/rubocop/cop/hash_literal.rb +22 -0
  34. data/lib/rubocop/cop/indentation.rb +1 -1
  35. data/lib/rubocop/cop/line_length.rb +7 -3
  36. data/lib/rubocop/cop/method_and_variable_snake_case.rb +31 -0
  37. data/lib/rubocop/cop/method_length.rb +66 -0
  38. data/lib/rubocop/cop/new_lambda_literal.rb +17 -0
  39. data/lib/rubocop/cop/offence.rb +3 -1
  40. data/lib/rubocop/cop/op_method.rb +23 -0
  41. data/lib/rubocop/cop/parentheses_around_condition.rb +24 -0
  42. data/lib/rubocop/cop/percent_literals.rb +25 -0
  43. data/lib/rubocop/cop/percent_r.rb +19 -0
  44. data/lib/rubocop/cop/reduce_arguments.rb +67 -0
  45. data/lib/rubocop/cop/rescue_exception.rb +39 -0
  46. data/lib/rubocop/cop/rescue_modifier.rb +20 -0
  47. data/lib/rubocop/cop/semicolon.rb +18 -0
  48. data/lib/rubocop/cop/space_after_comma_etc.rb +2 -1
  49. data/lib/rubocop/cop/string_literals.rb +12 -0
  50. data/lib/rubocop/cop/surrounding_space.rb +48 -47
  51. data/lib/rubocop/cop/symbol_snake_case.rb +27 -0
  52. data/lib/rubocop/cop/syntax.rb +42 -0
  53. data/lib/rubocop/cop/tab.rb +1 -3
  54. data/lib/rubocop/cop/variable_interpolation.rb +20 -0
  55. data/lib/rubocop/cop/when_then.rb +3 -0
  56. data/lib/rubocop/report/emacs_style.rb +2 -2
  57. data/lib/rubocop/report/plain_text.rb +1 -1
  58. data/lib/rubocop/report/report.rb +5 -2
  59. data/lib/rubocop/version.rb +3 -1
  60. data/lib/rubocop.rb +37 -0
  61. data/rubocop.gemspec +36 -134
  62. data/spec/rubocop/cli_spec.rb +326 -48
  63. data/spec/rubocop/cops/alias_spec.rb +36 -0
  64. data/spec/rubocop/cops/align_parameters_spec.rb +43 -34
  65. data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +4 -4
  66. data/spec/rubocop/cops/array_literal_spec.rb +29 -0
  67. data/spec/rubocop/cops/ascii_identifiers_and_comments_spec.rb +38 -0
  68. data/spec/rubocop/cops/avoid_class_vars_spec.rb +20 -0
  69. data/spec/rubocop/cops/avoid_for_spec.rb +22 -0
  70. data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +18 -0
  71. data/spec/rubocop/cops/avoid_perlisms_spec.rb +44 -0
  72. data/spec/rubocop/cops/brace_after_percent_spec.rb +27 -0
  73. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +34 -0
  74. data/spec/rubocop/cops/collection_methods_spec.rb +39 -0
  75. data/spec/rubocop/cops/cop_spec.rb +5 -5
  76. data/spec/rubocop/cops/def_with_parentheses_spec.rb +5 -5
  77. data/spec/rubocop/cops/def_without_parentheses_spec.rb +4 -4
  78. data/spec/rubocop/cops/empty_lines_spec.rb +8 -8
  79. data/spec/rubocop/cops/encoding_spec.rb +17 -11
  80. data/spec/rubocop/cops/end_of_line_spec.rb +5 -5
  81. data/spec/rubocop/cops/ensure_return_spec.rb +37 -0
  82. data/spec/rubocop/cops/favor_modifier_spec.rb +112 -0
  83. data/spec/rubocop/cops/favor_percent_r.rb +29 -0
  84. data/spec/rubocop/cops/favor_sprintf_spec.rb +57 -0
  85. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +62 -0
  86. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +45 -0
  87. data/spec/rubocop/cops/grammar_spec.rb +59 -44
  88. data/spec/rubocop/cops/handle_exceptions_spec.rb +36 -0
  89. data/spec/rubocop/cops/hash_literal_spec.rb +29 -0
  90. data/spec/rubocop/cops/hash_syntax_spec.rb +10 -10
  91. data/spec/rubocop/cops/if_with_semicolon_spec.rb +3 -3
  92. data/spec/rubocop/cops/indentation_spec.rb +7 -7
  93. data/spec/rubocop/cops/line_length_spec.rb +4 -4
  94. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +47 -0
  95. data/spec/rubocop/cops/method_length_spec.rb +150 -0
  96. data/spec/rubocop/cops/multiline_blocks_spec.rb +4 -4
  97. data/spec/rubocop/cops/multiline_if_then_spec.rb +7 -7
  98. data/spec/rubocop/cops/new_lambda_literal_spec.rb +23 -0
  99. data/spec/rubocop/cops/numeric_literals_spec.rb +10 -10
  100. data/spec/rubocop/cops/offence_spec.rb +10 -4
  101. data/spec/rubocop/cops/one_line_conditional_spec.rb +2 -3
  102. data/spec/rubocop/cops/op_method_spec.rb +58 -0
  103. data/spec/rubocop/cops/parameter_lists_spec.rb +4 -4
  104. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +64 -0
  105. data/spec/rubocop/cops/percent_literals_spec.rb +47 -0
  106. data/spec/rubocop/cops/percent_r_spec.rb +29 -0
  107. data/spec/rubocop/cops/reduce_arguments_spec.rb +57 -0
  108. data/spec/rubocop/cops/rescue_exception_spec.rb +73 -0
  109. data/spec/rubocop/cops/rescue_modifier.rb +40 -0
  110. data/spec/rubocop/cops/semicolon_spec.rb +29 -0
  111. data/spec/rubocop/cops/single_line_blocks_spec.rb +4 -4
  112. data/spec/rubocop/cops/space_after_colon_spec.rb +5 -5
  113. data/spec/rubocop/cops/space_after_comma_spec.rb +3 -3
  114. data/spec/rubocop/cops/space_after_semicolon_spec.rb +3 -3
  115. data/spec/rubocop/cops/space_around_braces_spec.rb +6 -6
  116. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +22 -0
  117. data/spec/rubocop/cops/space_around_operators_spec.rb +57 -25
  118. data/spec/rubocop/cops/space_inside_brackets_spec.rb +8 -8
  119. data/spec/rubocop/cops/space_inside_parens_spec.rb +4 -4
  120. data/spec/rubocop/cops/string_literals_spec.rb +9 -6
  121. data/spec/rubocop/cops/symbol_snake_case_spec.rb +74 -0
  122. data/spec/rubocop/cops/syntax_spec.rb +34 -0
  123. data/spec/rubocop/cops/tab_spec.rb +4 -4
  124. data/spec/rubocop/cops/ternary_operator_spec.rb +8 -8
  125. data/spec/rubocop/cops/trailing_whitespace_spec.rb +4 -4
  126. data/spec/rubocop/cops/unless_else_spec.rb +4 -4
  127. data/spec/rubocop/cops/variable_interpolation_spec.rb +45 -0
  128. data/spec/rubocop/cops/when_then_spec.rb +12 -5
  129. data/spec/rubocop/reports/emacs_style_spec.rb +3 -3
  130. data/spec/rubocop/reports/report_spec.rb +5 -5
  131. data/spec/spec_helper.rb +6 -0
  132. metadata +165 -36
  133. data/.rbenv-version +0 -1
  134. data/.rvmrc +0 -1
  135. data/Gemfile.lock +0 -39
  136. data/VERSION +0 -1
  137. data/features/rubocop.feature +0 -9
  138. data/features/step_definitions/rubocop_steps.rb +0 -1
  139. data/features/support/env.rb +0 -15
@@ -5,38 +5,38 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe SpaceInsideBrackets do
8
- let (:space) { SpaceInsideBrackets.new }
8
+ let(:space) { SpaceInsideBrackets.new }
9
9
 
10
10
  it 'registers an offence for an array literal with spaces inside' do
11
11
  inspect_source(space, 'file.rb', ['a = [1, 2 ]',
12
12
  'b = [ 1, 2]'])
13
- space.offences.map(&:message).should ==
13
+ expect(space.offences.map(&:message)).to eq(
14
14
  ['Space inside square brackets detected.',
15
- 'Space inside square brackets detected.']
15
+ 'Space inside square brackets detected.'])
16
16
  end
17
17
 
18
18
  it 'accepts space inside square brackets if on its own row' do
19
19
  inspect_source(space, 'file.rb', ['a = [',
20
20
  ' 1, 2',
21
21
  ' ]'])
22
- space.offences.map(&:message).should == []
22
+ expect(space.offences.map(&:message)).to be_empty
23
23
  end
24
24
 
25
25
  it 'accepts square brackets as method name' do
26
26
  inspect_source(space, 'file.rb', ['def Vector.[](*array)',
27
27
  'end'])
28
- space.offences.map(&:message).should == []
28
+ expect(space.offences.map(&:message)).to be_empty
29
29
  end
30
30
 
31
31
  it 'accepts square brackets called with method call syntax' do
32
32
  inspect_source(space, 'file.rb', ['subject.[](0)'])
33
- space.offences.map(&:message).should == []
33
+ expect(space.offences.map(&:message)).to be_empty
34
34
  end
35
35
 
36
36
  it 'only reports a single space once' do
37
37
  inspect_source(space, 'file.rb', ['[ ]'])
38
- space.offences.map(&:message).should ==
39
- ['Space inside square brackets detected.']
38
+ expect(space.offences.map(&:message)).to eq(
39
+ ['Space inside square brackets detected.'])
40
40
  end
41
41
  end
42
42
  end
@@ -5,21 +5,21 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe SpaceInsideParens do
8
- let (:space) { SpaceInsideParens.new }
8
+ let(:space) { SpaceInsideParens.new }
9
9
 
10
10
  it 'registers an offence for spaces inside parens' do
11
11
  inspect_source(space, 'file.rb', ['f( 3)',
12
12
  'g(3 )'])
13
- space.offences.map(&:message).should ==
13
+ expect(space.offences.map(&:message)).to eq(
14
14
  ['Space inside parentheses detected.',
15
- 'Space inside parentheses detected.']
15
+ 'Space inside parentheses detected.'])
16
16
  end
17
17
 
18
18
  it 'accepts parentheses in block parameter list' do
19
19
  inspect_source(space, 'file.rb',
20
20
  ['list.inject(Tms.new) { |sum, (label, item)|',
21
21
  '}'])
22
- space.offences.map(&:message).should == []
22
+ expect(space.offences.map(&:message)).to be_empty
23
23
  end
24
24
 
25
25
  end
@@ -5,27 +5,30 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe StringLiterals do
8
- let (:sl) { StringLiterals.new }
8
+ let(:sl) { StringLiterals.new }
9
9
 
10
10
  it 'registers an offence for double quotes when single quotes suffice' do
11
11
  inspect_source(sl, 'file.rb', ['s = "abc"'])
12
- sl.offences.map(&:message).should ==
12
+ expect(sl.offences.map(&:message)).to eq(
13
13
  ["Prefer single-quoted strings when you don't need string " +
14
- 'interpolation or special symbols.']
14
+ 'interpolation or special symbols.'])
15
15
  end
16
16
 
17
17
  it 'accepts double quotes when they are needed' do
18
18
  src = ['a = "\n"',
19
19
  'b = "#{encode_severity}:#{sprintf("%3d", line_number)}: #{m}"',
20
- 'c = "\'"']
20
+ 'c = "\'"',
21
+ 'd = "#@test"',
22
+ 'e = "#$test"',
23
+ 'f = "#@@test"']
21
24
  inspect_source(sl, 'file.rb', src)
22
- sl.offences.map(&:message).should == []
25
+ expect(sl.offences.map(&:message)).to be_empty
23
26
  end
24
27
 
25
28
  it 'can handle double quotes within embedded expression' do
26
29
  src = ['"#{"A"}"']
27
30
  inspect_source(sl, 'file.rb', src)
28
- sl.offences.map(&:message).should == []
31
+ expect(sl.offences.map(&:message)).to be_empty
29
32
  end
30
33
  end
31
34
  end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe SymbolSnakeCase do
8
+ let(:snake_case) { SymbolSnakeCase.new }
9
+
10
+ it 'registers an offence for camel case in names' do
11
+ inspect_source(snake_case, 'file.rb',
12
+ ['test = :BadIdea'])
13
+ expect(snake_case.offences.map(&:message)).to eq(
14
+ ['Use snake_case for symbols.'])
15
+ end
16
+
17
+ it 'accepts snake case in names' do
18
+ inspect_source(snake_case, 'file.rb',
19
+ ['test = :good_idea'])
20
+ expect(snake_case.offences).to be_empty
21
+ end
22
+
23
+ it 'accepts snake case with a prefix @ in names' do
24
+ inspect_source(snake_case, 'file.rb',
25
+ ['test = :@good_idea'])
26
+ expect(snake_case.offences).to be_empty
27
+ end
28
+
29
+ it 'accepts snake case with ? suffix' do
30
+ inspect_source(snake_case, 'file.rb',
31
+ ['test = :good_idea?'])
32
+ expect(snake_case.offences).to be_empty
33
+ end
34
+
35
+ it 'accepts snake case with ! suffix' do
36
+ inspect_source(snake_case, 'file.rb',
37
+ ['test = :good_idea!'])
38
+ expect(snake_case.offences).to be_empty
39
+ end
40
+
41
+ it 'accepts snake case with = suffix' do
42
+ inspect_source(snake_case, 'file.rb',
43
+ ['test = :good_idea='])
44
+ expect(snake_case.offences).to be_empty
45
+ end
46
+
47
+ it 'accepts special cases - !, [] and **' do
48
+ inspect_source(snake_case, 'file.rb',
49
+ ['test = :**',
50
+ 'test = :!',
51
+ 'test = :[]',
52
+ 'test = :[]='])
53
+ expect(snake_case.offences).to be_empty
54
+ end
55
+
56
+ it 'accepts special cases - ==, <=>, >, <, >=, <=' do
57
+ inspect_source(snake_case, 'file.rb',
58
+ ['test = :==',
59
+ 'test = :<=>',
60
+ 'test = :>',
61
+ 'test = :<',
62
+ 'test = :>=',
63
+ 'test = :<='])
64
+ expect(snake_case.offences).to be_empty
65
+ end
66
+
67
+ it 'registers an offence for SCREAMING_SNAKE_CASE' do
68
+ inspect_source(snake_case, 'file.rb',
69
+ ['test = :BAD_IDEA'])
70
+ expect(snake_case.offences.size).to eq(1)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe Syntax do
8
+ let(:sc) { Syntax.new }
9
+
10
+ it 'registers an offence for unused variables', ruby: 2.0 do
11
+ sc.inspect('file.rb', ['x = 5', 'puts 10'], nil, nil)
12
+ expect(sc.offences.size).to eq(1)
13
+ expect(sc.offences.first.message)
14
+ .to eq('Assigned but unused variable - x')
15
+ end
16
+
17
+ describe '#process_line' do
18
+ it 'processes warnings correctly' do
19
+ l, s, m = sc.process_line('admin.rb:1: warning: possibly useless')
20
+ expect(l).to eq(1)
21
+ expect(s).to eq(:warning)
22
+ expect(m).to eq('Possibly useless')
23
+ end
24
+
25
+ it 'processes errors correctly' do
26
+ l, s, m = sc.process_line('admin.rb:1: unterminated string meets')
27
+ expect(l).to eq(1)
28
+ expect(s).to eq(:error)
29
+ expect(m).to eq('Unterminated string meets')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,16 +5,16 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe Tab do
8
- let (:tab) { Tab.new }
8
+ let(:tab) { Tab.new }
9
9
 
10
10
  it 'registers an offence for a line indented with tab' do
11
11
  tab.inspect('file.rb', ["\tx = 0"], nil, nil)
12
- tab.offences.size.should == 1
12
+ expect(tab.offences.size).to eq(1)
13
13
  end
14
14
 
15
15
  it 'accepts a line with tab in a string' do
16
- tab.inspect('file.rb', [%Q(x = "\t")], nil, nil)
17
- tab.offences.size.should == 0
16
+ tab.inspect('file.rb', ["(x = \"\t\")"], nil, nil)
17
+ expect(tab.offences).to be_empty
18
18
  end
19
19
  end
20
20
  end
@@ -5,30 +5,30 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe MultilineTernaryOperator do
8
- let (:op) { MultilineTernaryOperator.new }
8
+ let(:op) { MultilineTernaryOperator.new }
9
9
 
10
10
  it 'registers an offence for a multiline ternary operator expression' do
11
11
  inspect_source(op, 'file.rb', ['a = cond ?',
12
12
  ' b : c'])
13
- op.offences.map(&:message).should ==
13
+ expect(op.offences.map(&:message)).to eq(
14
14
  ['Avoid multi-line ?: (the ternary operator); use if/unless ' +
15
- 'instead.']
15
+ 'instead.'])
16
16
  end
17
17
 
18
18
  it 'accepts a single line ternary operator expression' do
19
19
  inspect_source(op, 'file.rb', ['a = cond ? b : c'])
20
- op.offences.map(&:message).should == []
20
+ expect(op.offences.map(&:message)).to be_empty
21
21
  end
22
22
  end
23
23
 
24
24
  describe NestedTernaryOperator do
25
- let (:op) { NestedTernaryOperator.new }
25
+ let(:op) { NestedTernaryOperator.new }
26
26
 
27
27
  it 'registers an offence for a nested ternary operator expression' do
28
28
  inspect_source(op, 'file.rb', ['a ? (b ? b1 : b2) : a2'])
29
- op.offences.map(&:message).should ==
29
+ expect(op.offences.map(&:message)).to eq(
30
30
  ['Ternary operators must not be nested. Prefer if/else constructs ' +
31
- 'instead.']
31
+ 'instead.'])
32
32
  end
33
33
 
34
34
  it 'accepts a non-nested ternary operator within an if' do
@@ -37,7 +37,7 @@ module Rubocop
37
37
  'else',
38
38
  ' d',
39
39
  'end'])
40
- op.offences.map(&:message).should == []
40
+ expect(op.offences.map(&:message)).to be_empty
41
41
  end
42
42
  end
43
43
  end
@@ -5,22 +5,22 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe TrailingWhitespace do
8
- let (:tws) { TrailingWhitespace.new }
8
+ let(:tws) { TrailingWhitespace.new }
9
9
 
10
10
  it 'registers an offence for a line ending with space' do
11
11
  source = ['x = 0 ']
12
12
  tws.inspect('file.rb', source, nil, nil)
13
- tws.offences.size.should == 1
13
+ expect(tws.offences.size).to eq(1)
14
14
  end
15
15
 
16
16
  it 'registers an offence for a line ending with tab' do
17
17
  tws.inspect('file.rb', ["x = 0\t"], nil, nil)
18
- tws.offences.size.should == 1
18
+ expect(tws.offences.size).to eq(1)
19
19
  end
20
20
 
21
21
  it 'accepts a line without trailing whitespace' do
22
22
  tws.inspect('file.rb', ["x = 0\n"], nil, nil)
23
- tws.offences.size.should == 0
23
+ expect(tws.offences).to be_empty
24
24
  end
25
25
  end
26
26
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe UnlessElse do
8
- let (:ue) { UnlessElse.new }
8
+ let(:ue) { UnlessElse.new }
9
9
 
10
10
  it 'registers an offence for an unless with else' do
11
11
  inspect_source(ue, 'file.rb', ['unless x',
@@ -13,16 +13,16 @@ module Rubocop
13
13
  'else',
14
14
  ' a = 0',
15
15
  'end'])
16
- ue.offences.map(&:message).should ==
16
+ expect(ue.offences.map(&:message)).to eq(
17
17
  ['Never use unless with else. Rewrite these with the ' +
18
- 'positive case first.']
18
+ 'positive case first.'])
19
19
  end
20
20
 
21
21
  it 'accepts an unless without else' do
22
22
  inspect_source(ue, 'file.rb', ['unless x',
23
23
  ' a = 1',
24
24
  'end'])
25
- ue.offences.map(&:message).should == []
25
+ expect(ue.offences.map(&:message)).to be_empty
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe VariableInterpolation do
8
+ let(:vi) { VariableInterpolation.new }
9
+
10
+ it 'registers an offence for interpolated global variables' do
11
+ inspect_source(vi,
12
+ 'file.rb',
13
+ ['puts "this is a #$test"'])
14
+ expect(vi.offences.size).to eq(1)
15
+ expect(vi.offences.map(&:message))
16
+ .to eq(['Replace interpolated var $test with expression #{$test}.'])
17
+ end
18
+
19
+ it 'registers an offence for interpolated instance variables' do
20
+ inspect_source(vi,
21
+ 'file.rb',
22
+ ['puts "this is a #@test"'])
23
+ expect(vi.offences.size).to eq(1)
24
+ expect(vi.offences.map(&:message))
25
+ .to eq(['Replace interpolated var @test with expression #{@test}.'])
26
+ end
27
+
28
+ it 'registers an offence for interpolated class variables' do
29
+ inspect_source(vi,
30
+ 'file.rb',
31
+ ['puts "this is a #@@t"'])
32
+ expect(vi.offences.size).to eq(1)
33
+ expect(vi.offences.map(&:message))
34
+ .to eq(['Replace interpolated var @@t with expression #{@@t}.'])
35
+ end
36
+
37
+ it 'does not register an offence for variables in expressions' do
38
+ inspect_source(vi,
39
+ 'file.rb',
40
+ ['puts "this is a #{@test}"'])
41
+ expect(vi.offences).to be_empty
42
+ end
43
+ end
44
+ end
45
+ end
@@ -5,21 +5,28 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  describe WhenThen do
8
- let (:wt) { WhenThen.new }
8
+ let(:wt) { WhenThen.new }
9
9
 
10
10
  it 'registers an offence for when x;' do
11
11
  inspect_source(wt, 'file.rb', ['case a',
12
12
  'when b; c',
13
13
  'end'])
14
- wt.offences.map(&:message).should ==
15
- ['Never use "when x;". Use "when x then" instead.']
14
+ expect(wt.offences.map(&:message)).to eq(
15
+ ['Never use "when x;". Use "when x then" instead.'])
16
+ end
17
+
18
+ it 'misses semicolon but does not crash when there are no tokens' do
19
+ inspect_source(wt, 'file.rb', ['case a',
20
+ 'when []; {}',
21
+ 'end'])
22
+ expect(wt.offences.map(&:message)).to eq([])
16
23
  end
17
24
 
18
25
  it 'accepts when x then' do
19
26
  inspect_source(wt, 'file.rb', ['case a',
20
27
  'when b then c',
21
28
  'end'])
22
- wt.offences.map(&:message).should == []
29
+ expect(wt.offences.map(&:message)).to be_empty
23
30
  end
24
31
 
25
32
  it 'accepts ; separating statements in the body of when' do
@@ -31,7 +38,7 @@ module Rubocop
31
38
  'when f',
32
39
  ' g; h',
33
40
  'end'])
34
- wt.offences.map(&:message).should == []
41
+ expect(wt.offences.map(&:message)).to be_empty
35
42
  end
36
43
  end
37
44
  end
@@ -6,7 +6,7 @@ require 'stringio'
6
6
  module Rubocop
7
7
  module Report
8
8
  describe EmacsStyle do
9
- let (:emacs_style) { Rubocop::Report.create('test', :emacs_style) }
9
+ let(:emacs_style) { Rubocop::Report.create('test', :emacs_style) }
10
10
 
11
11
  it 'displays parsable text' do
12
12
  cop = Cop::Cop.new
@@ -17,8 +17,8 @@ module Rubocop
17
17
 
18
18
  s = StringIO.new
19
19
  emacs_style.display(s)
20
- s.string.should == ['test:1: C: message 1',
21
- "test:11: F: message 2\n"].join("\n")
20
+ expect(s.string).to eq ['test:1: C: message 1',
21
+ "test:11: F: message 2\n"].join("\n")
22
22
  end
23
23
  end
24
24
  end
@@ -5,14 +5,14 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Report
7
7
  describe Report do
8
- let (:report) { Report.new('test') }
8
+ let(:report) { Report.new('test') }
9
9
 
10
10
  it 'initially has 0 entries' do
11
- report.entries.size.should == 0
11
+ expect(report.entries.size).to be_zero
12
12
  end
13
13
 
14
14
  it 'initially has nothing to report' do
15
- report.empty?.should be_true
15
+ expect(report.empty?).to be_true
16
16
  end
17
17
 
18
18
  it 'keeps track of offences' do
@@ -21,8 +21,8 @@ module Rubocop
21
21
 
22
22
  report << cop
23
23
 
24
- report.empty?.should be_false
25
- report.entries.size.should == 1
24
+ expect(report.empty?).to be_false
25
+ expect(report.entries.size).to eq(1)
26
26
  end
27
27
  end
28
28
  end
data/spec/spec_helper.rb CHANGED
@@ -40,6 +40,12 @@ module ExitCodeMatchers
40
40
  end
41
41
 
42
42
  RSpec.configure do |config|
43
+ config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }
44
+
45
+ config.expect_with :rspec do |c|
46
+ c.syntax = :expect # disables `should`
47
+ end
48
+
43
49
  config.include(ExitCodeMatchers)
44
50
  end
45
51