rubocop-rspec 1.32.0 → 1.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +2 -0
  4. data/Rakefile +2 -0
  5. data/config/default.yml +6 -0
  6. data/lib/rubocop-rspec.rb +3 -0
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
  9. data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
  10. data/lib/rubocop/cop/rspec/around_block.rb +4 -2
  11. data/lib/rubocop/cop/rspec/be.rb +4 -2
  12. data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
  13. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
  14. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
  15. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
  16. data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
  17. data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
  18. data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
  19. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  20. data/lib/rubocop/cop/rspec/described_class.rb +3 -3
  21. data/lib/rubocop/cop/rspec/dialect.rb +76 -0
  22. data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
  23. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  25. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  26. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
  27. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  28. data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
  29. data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
  30. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
  31. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  32. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  33. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  34. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
  35. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
  36. data/lib/rubocop/cop/rspec/file_path.rb +2 -2
  37. data/lib/rubocop/cop/rspec/focus.rb +3 -3
  38. data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
  39. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
  40. data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
  41. data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
  42. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  43. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  44. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
  45. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
  46. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
  47. data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
  48. data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
  49. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  50. data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
  51. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  52. data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
  53. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
  54. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  55. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
  56. data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
  57. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  58. data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
  59. data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
  60. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  61. data/lib/rubocop/cop/rspec/pending.rb +3 -3
  62. data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
  63. data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
  64. data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
  65. data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
  66. data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
  67. data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
  68. data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
  69. data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
  70. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  71. data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
  72. data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
  73. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
  74. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
  75. data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
  76. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
  77. data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
  78. data/lib/rubocop/cop/rspec/yield.rb +2 -4
  79. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  80. data/lib/rubocop/rspec.rb +2 -0
  81. data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
  82. data/lib/rubocop/rspec/config_formatter.rb +3 -1
  83. data/lib/rubocop/rspec/description_extractor.rb +3 -1
  84. data/lib/rubocop/rspec/factory_bot.rb +58 -0
  85. data/lib/rubocop/rspec/final_end_location.rb +2 -0
  86. data/lib/rubocop/rspec/inject.rb +2 -0
  87. data/lib/rubocop/rspec/language.rb +9 -2
  88. data/lib/rubocop/rspec/top_level_describe.rb +2 -0
  89. data/lib/rubocop/rspec/version.rb +1 -1
  90. data/rubocop-rspec.gemspec +3 -1
  91. data/spec/project/changelog_spec.rb +2 -0
  92. data/spec/project/default_config_spec.rb +2 -0
  93. data/spec/project/project_requires_spec.rb +2 -0
  94. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
  95. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
  96. data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
  97. data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
  98. data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
  99. data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
  100. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
  101. data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
  102. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
  103. data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
  104. data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
  105. data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
  106. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
  107. data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
  108. data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
  109. data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
  110. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
  111. data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
  112. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
  113. data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
  114. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
  115. data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
  116. data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
  117. data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
  118. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
  119. data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
  120. data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
  121. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
  122. data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
  123. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
  124. data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
  125. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
  126. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
  127. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
  128. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
  129. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
  130. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
  131. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
  132. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
  133. data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
  134. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
  135. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
  136. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
  137. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
  138. data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
  139. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
  140. data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
  141. data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
  142. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
  143. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
  144. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
  145. data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
  146. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
  147. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
  148. data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
  149. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
  150. data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
  151. data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
  152. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  153. data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
  154. data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
  155. data/spec/rubocop/rspec/util/one_spec.rb +2 -0
  156. data/spec/rubocop/rspec/wording_spec.rb +2 -0
  157. data/spec/shared/autocorrect_behavior.rb +2 -0
  158. data/spec/shared/detects_style_behavior.rb +2 -0
  159. data/spec/shared/smoke_test_examples.rb +2 -0
  160. data/spec/spec_helper.rb +2 -0
  161. data/spec/support/expect_offense.rb +3 -1
  162. metadata +8 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::AroundBlock do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::BeEql do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -8,6 +10,11 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
8
10
  it { expect(foo).to eql(false) }
9
11
  ^^^ Prefer `be` over `eql`.
10
12
  RUBY
13
+
14
+ expect_correction(<<-RUBY)
15
+ it { expect(foo).to be(true) }
16
+ it { expect(foo).to be(false) }
17
+ RUBY
11
18
  end
12
19
 
13
20
  it 'registers an offense for `eql` when argument is an integer' do
@@ -17,6 +24,11 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
17
24
  it { expect(foo).to eql(123) }
18
25
  ^^^ Prefer `be` over `eql`.
19
26
  RUBY
27
+
28
+ expect_correction(<<-RUBY)
29
+ it { expect(foo).to be(0) }
30
+ it { expect(foo).to be(123) }
31
+ RUBY
20
32
  end
21
33
 
22
34
  it 'registers an offense for `eql` when argument is a float' do
@@ -26,6 +38,11 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
26
38
  it { expect(foo).to eql(1.23) }
27
39
  ^^^ Prefer `be` over `eql`.
28
40
  RUBY
41
+
42
+ expect_correction(<<-RUBY)
43
+ it { expect(foo).to be(1.0) }
44
+ it { expect(foo).to be(1.23) }
45
+ RUBY
29
46
  end
30
47
 
31
48
  it 'registers an offense for `eql` when argument is a symbol' do
@@ -33,6 +50,10 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
33
50
  it { expect(foo).to eql(:foo) }
34
51
  ^^^ Prefer `be` over `eql`.
35
52
  RUBY
53
+
54
+ expect_correction(<<-RUBY)
55
+ it { expect(foo).to be(:foo) }
56
+ RUBY
36
57
  end
37
58
 
38
59
  it 'registers an offense for `eql` when argument is nil' do
@@ -40,6 +61,10 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
40
61
  it { expect(foo).to eql(nil) }
41
62
  ^^^ Prefer `be` over `eql`.
42
63
  RUBY
64
+
65
+ expect_correction(<<-RUBY)
66
+ it { expect(foo).to be(nil) }
67
+ RUBY
43
68
  end
44
69
 
45
70
  it 'does not register an offense for `eql` when argument is a string' do
@@ -53,8 +78,4 @@ RSpec.describe RuboCop::Cop::RSpec::BeEql do
53
78
  it { expect(foo).to_not eql(1) }
54
79
  RUBY
55
80
  end
56
-
57
- include_examples 'autocorrect',
58
- 'it { expect(foo).to eql(1) }',
59
- 'it { expect(foo).to be(1) }'
60
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::Be do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::Capybara::FeatureMethods, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::ContextWording, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -41,6 +43,36 @@ RSpec.describe RuboCop::Cop::RSpec::ContextWording, :config do
41
43
  RUBY
42
44
  end
43
45
 
46
+ context 'with metadata hash' do
47
+ it 'finds context without separate `when` at the beginning' do
48
+ expect_offense(<<-RUBY)
49
+ context 'whenever you do', legend: true do
50
+ ^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
51
+ end
52
+ RUBY
53
+ end
54
+ end
55
+
56
+ context 'with symbol metadata' do
57
+ it 'finds context without separate `when` at the beginning' do
58
+ expect_offense(<<-RUBY)
59
+ context 'whenever you do', :legend do
60
+ ^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
61
+ end
62
+ RUBY
63
+ end
64
+ end
65
+
66
+ context 'with mixed metadata' do
67
+ it 'finds context without separate `when` at the beginning' do
68
+ expect_offense(<<-RUBY)
69
+ context 'whenever you do', :legend, myth: true do
70
+ ^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
71
+ end
72
+ RUBY
73
+ end
74
+ end
75
+
44
76
  context 'when configured' do
45
77
  let(:cop_config) { { 'Prefixes' => %w[if] } }
46
78
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::DescribeClass do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::DescribeMethod do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::DescribeSymbol do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::DescribedClass, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -112,6 +114,7 @@ RSpec.describe RuboCop::Cop::RSpec::DescribedClass, :config do
112
114
  describe MyClass do
113
115
  Class.new { foo = MyClass }
114
116
  Module.new { bar = MyClass }
117
+ Struct.new { lol = MyClass }
115
118
 
116
119
  def method
117
120
  include MyClass
@@ -121,7 +124,7 @@ RSpec.describe RuboCop::Cop::RSpec::DescribedClass, :config do
121
124
  include MyClass
122
125
  end
123
126
 
124
- module MyModle
127
+ module MyModule
125
128
  include MyClass
126
129
  end
127
130
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RuboCop::Cop::RSpec::Dialect, :config do
4
+ subject(:cop) { described_class.new(config) }
5
+
6
+ let(:cop_config) do
7
+ {
8
+ 'PreferredMethods' => {
9
+ 'context' => 'describe'
10
+ }
11
+ }
12
+ end
13
+
14
+ it 'allows describe blocks' do
15
+ expect_no_offenses(<<-RUBY)
16
+ describe 'display name presence' do
17
+ end
18
+ RUBY
19
+ end
20
+
21
+ it 'allows calling methods named context in examples' do
22
+ expect_no_offenses(<<-RUBY)
23
+ it 'tests common context invocations' do
24
+ expect(request.context).to be_empty?
25
+ end
26
+ RUBY
27
+ end
28
+
29
+ it 'registers an offense for context blocks' do
30
+ expect_offense(<<-RUBY)
31
+ context 'display name presence' do
32
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
33
+ end
34
+ RUBY
35
+
36
+ expect_correction(<<-RUBY)
37
+ describe 'display name presence' do
38
+ end
39
+ RUBY
40
+ end
41
+
42
+ it 'registers an offense for RSpec.context blocks' do
43
+ expect_offense(<<-RUBY)
44
+ RSpec.context 'context' do
45
+ ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
46
+ it 'tests common context invocations' do
47
+ expect(request.context).to be_empty?
48
+ end
49
+ end
50
+ RUBY
51
+
52
+ expect_correction(<<-RUBY)
53
+ RSpec.describe 'context' do
54
+ it 'tests common context invocations' do
55
+ expect(request.context).to be_empty?
56
+ end
57
+ end
58
+ RUBY
59
+ end
60
+
61
+ context 'without preferred methods' do
62
+ let(:cop_config) do
63
+ {
64
+ 'PreferredMethods' => {}
65
+ }
66
+ end
67
+
68
+ it 'allows all methods blocks' do
69
+ expect_no_offenses(<<-RUBY)
70
+ context 'is important' do
71
+ specify 'for someone to work' do
72
+ everyone.should have_some_leeway
73
+ end
74
+ end
75
+ RUBY
76
+ end
77
+ end
78
+ end
@@ -13,6 +13,16 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
13
13
  end
14
14
  end
15
15
  RUBY
16
+
17
+ expect_correction(<<-RUBY)
18
+ RSpec.describe Foo do
19
+ describe '#bar' do
20
+ end
21
+
22
+ describe '#baz' do
23
+ end
24
+ end
25
+ RUBY
16
26
  end
17
27
 
18
28
  it 'highlights single line formulations correctly' do
@@ -24,6 +34,15 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
24
34
  end
25
35
  end
26
36
  RUBY
37
+
38
+ expect_correction(<<-RUBY)
39
+ RSpec.describe Foo do
40
+ describe('#bar') { }
41
+
42
+ describe '#baz' do
43
+ end
44
+ end
45
+ RUBY
27
46
  end
28
47
 
29
48
  it 'checks for empty line after context' do
@@ -36,6 +55,16 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
36
55
  end
37
56
  end
38
57
  RUBY
58
+
59
+ expect_correction(<<-RUBY)
60
+ RSpec.context 'foo' do
61
+ context 'bar' do
62
+ end
63
+
64
+ context 'baz' do
65
+ end
66
+ end
67
+ RUBY
39
68
  end
40
69
 
41
70
  it 'approves empty line after describe' do
@@ -75,28 +104,18 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
75
104
  end
76
105
  end
77
106
  RUBY
78
- end
79
107
 
80
- bad_example = <<-RUBY
81
- RSpec.describe Foo do
82
- describe '#bar' do
83
- end
84
- describe '#baz' do
85
- end
86
- end
87
- RUBY
88
-
89
- good_example = <<-RUBY
90
- RSpec.describe Foo do
91
- describe '#bar' do
92
- end
108
+ expect_correction(<<-RUBY)
109
+ if RUBY_VERSION < 2.3
110
+ describe 'skips checks under old ruby' do
111
+ end
112
+ else
113
+ describe 'first check' do
114
+ end
93
115
 
94
- describe '#baz' do
116
+ describe 'second check' do
117
+ end
95
118
  end
96
- end
97
- RUBY
98
-
99
- include_examples 'autocorrect',
100
- bad_example,
101
- good_example
119
+ RUBY
120
+ end
102
121
  end
@@ -12,6 +12,15 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
12
12
  it { expect(a).to eq(b) }
13
13
  end
14
14
  RUBY
15
+
16
+ expect_correction(<<-RUBY)
17
+ RSpec.describe User do
18
+ let(:a) { a }
19
+ let(:b) { b }
20
+
21
+ it { expect(a).to eq(b) }
22
+ end
23
+ RUBY
15
24
  end
16
25
 
17
26
  it 'check for empty line after the last `let!`' do
@@ -25,6 +34,17 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
25
34
  it { expect(a).to eq(b) }
26
35
  end
27
36
  RUBY
37
+
38
+ expect_correction(<<-RUBY)
39
+ RSpec.describe User do
40
+ let(:a) { a }
41
+ let!(:b) do
42
+ b
43
+ end
44
+
45
+ it { expect(a).to eq(b) }
46
+ end
47
+ RUBY
28
48
  end
29
49
 
30
50
  it 'approves empty line after let' do
@@ -60,6 +80,40 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
60
80
  it { expect(a).to eq(b) }
61
81
  end
62
82
  RUBY
83
+
84
+ expect_correction(<<-RUBY)
85
+ RSpec.describe User do
86
+ let(:a) { a }
87
+ let(:b) { b }
88
+ # end of setup
89
+
90
+ it { expect(a).to eq(b) }
91
+ end
92
+ RUBY
93
+ end
94
+
95
+ it 'flags missing empty line after a multiline comment after last let' do
96
+ expect_offense(<<-RUBY)
97
+ RSpec.describe User do
98
+ let(:a) { a }
99
+ let(:b) { b }
100
+ # a multiline comment marking
101
+ # the end of setup
102
+ ^^^^^^^^^^^^^^^^^^ Add an empty line after the last `let` block.
103
+ it { expect(a).to eq(b) }
104
+ end
105
+ RUBY
106
+
107
+ expect_correction(<<-RUBY)
108
+ RSpec.describe User do
109
+ let(:a) { a }
110
+ let(:b) { b }
111
+ # a multiline comment marking
112
+ # the end of setup
113
+
114
+ it { expect(a).to eq(b) }
115
+ end
116
+ RUBY
63
117
  end
64
118
 
65
119
  it 'ignores empty lines between the lets' do
@@ -74,6 +128,18 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
74
128
  it { expect(a).to eq(b) }
75
129
  end
76
130
  RUBY
131
+
132
+ expect_correction(<<-RUBY)
133
+ RSpec.describe User do
134
+ let(:a) { a }
135
+
136
+ subject { described_class }
137
+
138
+ let!(:b) { b }
139
+
140
+ it { expect(a).to eq(b) }
141
+ end
142
+ RUBY
77
143
  end
78
144
 
79
145
  it 'handles let in tests' do
@@ -156,76 +222,18 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterFinalLet do
156
222
  end
157
223
  end
158
224
  RUBY
159
- end
160
-
161
- bad_example = <<-RUBY
162
- RSpec.describe User do
163
- let(:params) { foo }
164
- it 'has a new line' do
165
- end
166
- end
167
- RUBY
168
-
169
- good_example = <<-RUBY
170
- RSpec.describe User do
171
- let(:params) { foo }
172
225
 
173
- it 'has a new line' do
174
- end
175
- end
176
- RUBY
177
-
178
- include_examples 'autocorrect',
179
- bad_example,
180
- good_example
181
-
182
- bad_example = <<-RUBY
183
- RSpec.describe User do
184
- let(:params) { foo }
185
- # a multiline comment marking
186
- # the end of setup
187
- it 'has a new line' do
188
- end
189
- end
190
- RUBY
191
-
192
- good_example = <<-RUBY
193
- RSpec.describe User do
194
- let(:params) { foo }
195
- # a multiline comment marking
196
- # the end of setup
197
-
198
- it 'has a new line' do
199
- end
200
- end
201
- RUBY
202
-
203
- include_examples 'autocorrect',
204
- bad_example,
205
- good_example
206
-
207
- bad_example = <<-RUBY
208
- RSpec.describe User do
209
- let(:params) { <<-DOC }
210
- I'm super annoying!
211
- DOC
212
- it 'has a new line' do
213
- end
214
- end
215
- RUBY
216
-
217
- good_example = <<-RUBY
218
- RSpec.describe User do
219
- let(:params) { <<-DOC }
220
- I'm super annoying!
221
- DOC
226
+ expect_correction(<<-RUBY)
227
+ RSpec.describe 'silly heredoc syntax' do
228
+ let(:foo) { <<-BAR }
229
+ hello
230
+ world
231
+ BAR
222
232
 
223
- it 'has a new line' do
224
- end
233
+ it 'has tricky syntax' do
234
+ expect(foo).to eql(" hello\n world\n")
235
+ end
236
+ end
237
+ RUBY
225
238
  end
226
- RUBY
227
-
228
- include_examples 'autocorrect',
229
- bad_example,
230
- good_example
231
239
  end