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
@@ -13,6 +13,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
13
13
  it { should be_truthy }
14
14
  ^^^^^^ Prefer `is_expected.to` over `should`.
15
15
  RUBY
16
+
17
+ expect_correction(<<-RUBY)
18
+ it { is_expected.to be_truthy }
19
+ RUBY
16
20
  end
17
21
 
18
22
  it 'flags it { should_not }' do
@@ -20,6 +24,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
20
24
  it { should_not be_truthy }
21
25
  ^^^^^^^^^^ Prefer `is_expected.to_not` over `should_not`.
22
26
  RUBY
27
+
28
+ expect_correction(<<-RUBY)
29
+ it { is_expected.to_not be_truthy }
30
+ RUBY
23
31
  end
24
32
 
25
33
  it 'approves of is_expected.to' do
@@ -35,13 +43,6 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
35
43
  end
36
44
 
37
45
  include_examples 'detects style', 'it { should be_truthy }', 'should'
38
- include_examples 'autocorrect',
39
- 'it { should be_truthy }',
40
- 'it { is_expected.to be_truthy }'
41
-
42
- include_examples 'autocorrect',
43
- 'it { should_not be_truthy }',
44
- 'it { is_expected.to_not be_truthy }'
45
46
  end
46
47
 
47
48
  context 'when EnforcedStyle is should' do
@@ -54,6 +55,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
54
55
  it { is_expected.to be_truthy }
55
56
  ^^^^^^^^^^^^^^ Prefer `should` over `is_expected.to`.
56
57
  RUBY
58
+
59
+ expect_correction(<<-RUBY)
60
+ it { should be_truthy }
61
+ RUBY
57
62
  end
58
63
 
59
64
  it 'flags it { is_expected.to_not }' do
@@ -61,6 +66,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
61
66
  it { is_expected.to_not be_truthy }
62
67
  ^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.to_not`.
63
68
  RUBY
69
+
70
+ expect_correction(<<-RUBY)
71
+ it { should_not be_truthy }
72
+ RUBY
64
73
  end
65
74
 
66
75
  it 'flags it { is_expected.not_to }' do
@@ -68,6 +77,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
68
77
  it { is_expected.not_to be_truthy }
69
78
  ^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.not_to`.
70
79
  RUBY
80
+
81
+ expect_correction(<<-RUBY)
82
+ it { should_not be_truthy }
83
+ RUBY
71
84
  end
72
85
 
73
86
  it 'approves of should' do
@@ -85,17 +98,5 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
85
98
  include_examples 'detects style',
86
99
  'it { should be_truthy }',
87
100
  'should'
88
-
89
- include_examples 'autocorrect',
90
- 'it { is_expected.to be_truthy }',
91
- 'it { should be_truthy }'
92
-
93
- include_examples 'autocorrect',
94
- 'it { is_expected.to_not be_truthy }',
95
- 'it { should_not be_truthy }'
96
-
97
- include_examples 'autocorrect',
98
- 'it { is_expected.not_to be_truthy }',
99
- 'it { should_not be_truthy }'
100
101
  end
101
102
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -15,6 +17,12 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
15
17
  ^^^^^^^^^^^ Don't use implicit subject.
16
18
  end
17
19
  RUBY
20
+
21
+ expect_correction(<<-RUBY)
22
+ it 'expect subject to be used' do
23
+ expect(subject).to be_good
24
+ end
25
+ RUBY
18
26
  end
19
27
 
20
28
  it 'allows `is_expected` inside `its` block, in multi-line examples' do
@@ -30,6 +38,15 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
30
38
  it 'expect subject to be used' do
31
39
  should be_good
32
40
  ^^^^^^^^^^^^^^ Don't use implicit subject.
41
+ should_not be_bad
42
+ ^^^^^^^^^^^^^^^^^ Don't use implicit subject.
43
+ end
44
+ RUBY
45
+
46
+ expect_correction(<<-RUBY)
47
+ it 'expect subject to be used' do
48
+ expect(subject).to be_good
49
+ expect(subject).not_to be_bad
33
50
  end
34
51
  RUBY
35
52
  end
@@ -63,41 +80,13 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
63
80
  ^^^^^^^^^^^ Don't use implicit subject.
64
81
  end
65
82
  RUBY
66
- end
67
83
 
68
- bad_code = <<-RUBY
69
- it 'works' do
70
- is_expected.to be_truthy
71
- end
72
- RUBY
73
-
74
- good_code = <<-RUBY
75
- it 'works' do
76
- expect(subject).to be_truthy
77
- end
78
- RUBY
79
-
80
- include_examples 'autocorrect',
81
- bad_code,
82
- good_code
83
-
84
- bad_code = <<-RUBY
85
- it 'works' do
86
- should be_truthy
87
- should_not be_falsy
88
- end
89
- RUBY
90
-
91
- good_code = <<-RUBY
92
- it 'works' do
93
- expect(subject).to be_truthy
94
- expect(subject).not_to be_falsy
95
- end
96
- RUBY
97
-
98
- include_examples 'autocorrect',
99
- bad_code,
100
- good_code
84
+ expect_correction(<<-RUBY)
85
+ def permits(actions)
86
+ actions.each { |action| expect(subject).to permit_action(action) }
87
+ end
88
+ RUBY
89
+ end
101
90
  end
102
91
 
103
92
  context 'with EnforcedStyle `single_statement_only`' do
@@ -119,29 +108,14 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
119
108
  ^^^^^^^^^^^ Don't use implicit subject.
120
109
  end
121
110
  RUBY
122
- end
123
111
 
124
- bad_code = <<-RUBY
125
- it 'is valid' do
126
- subject.age = 18
127
- is_expected.to be_valid
128
- end
129
- RUBY
130
-
131
- good_code = <<-RUBY
132
- it 'is valid' do
133
- subject.age = 18
134
- expect(subject).to be_valid
135
- end
136
- RUBY
137
-
138
- include_examples 'autocorrect',
139
- bad_code,
140
- good_code
141
-
142
- include_examples 'autocorrect',
143
- bad_code,
144
- good_code
112
+ expect_correction(<<-RUBY)
113
+ it 'expect subject to be used' do
114
+ subject.age = 18
115
+ expect(subject).to be_valid
116
+ end
117
+ RUBY
118
+ end
145
119
  end
146
120
 
147
121
  context 'with EnforcedStyle `disallow`' do
@@ -154,6 +128,12 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
154
128
  ^^^^^^^^^^^ Don't use implicit subject.
155
129
  end
156
130
  RUBY
131
+
132
+ expect_correction(<<-RUBY)
133
+ it 'expect subject to be used' do
134
+ expect(subject).to be_good
135
+ end
136
+ RUBY
157
137
  end
158
138
 
159
139
  it 'flags `is_expected` in single-line examples' do
@@ -161,6 +141,10 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
161
141
  it { is_expected.to be_good }
162
142
  ^^^^^^^^^^^ Don't use implicit subject.
163
143
  RUBY
144
+
145
+ expect_correction(<<-RUBY)
146
+ it { expect(subject).to be_good }
147
+ RUBY
164
148
  end
165
149
 
166
150
  it 'flags `should` in multi-line examples' do
@@ -168,6 +152,15 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
168
152
  it 'expect subject to be used' do
169
153
  should be_good
170
154
  ^^^^^^^^^^^^^^ Don't use implicit subject.
155
+ should_not be_bad
156
+ ^^^^^^^^^^^^^^^^^ Don't use implicit subject.
157
+ end
158
+ RUBY
159
+
160
+ expect_correction(<<-RUBY)
161
+ it 'expect subject to be used' do
162
+ expect(subject).to be_good
163
+ expect(subject).not_to be_bad
171
164
  end
172
165
  RUBY
173
166
  end
@@ -176,6 +169,13 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
176
169
  expect_offense(<<-RUBY)
177
170
  it { should be_good }
178
171
  ^^^^^^^^^^^^^^ Don't use implicit subject.
172
+ it { should_not be_bad }
173
+ ^^^^^^^^^^^^^^^^^ Don't use implicit subject.
174
+ RUBY
175
+
176
+ expect_correction(<<-RUBY)
177
+ it { expect(subject).to be_good }
178
+ it { expect(subject).not_to be_bad }
179
179
  RUBY
180
180
  end
181
181
 
@@ -184,17 +184,5 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
184
184
  its(:quality) { is_expected.to be :high }
185
185
  RUBY
186
186
  end
187
-
188
- include_examples 'autocorrect',
189
- 'it { is_expected.to be_truthy }',
190
- 'it { expect(subject).to be_truthy }'
191
-
192
- include_examples 'autocorrect',
193
- 'it { should be_truthy }',
194
- 'it { expect(subject).to be_truthy }'
195
-
196
- include_examples 'autocorrect',
197
- 'it { should_not be_truthy }',
198
- 'it { expect(subject).not_to be_truthy }'
199
187
  end
200
188
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -10,6 +12,13 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
10
12
  expect(foo).to have_received(:bar)
11
13
  end
12
14
  RUBY
15
+
16
+ expect_correction(<<-RUBY)
17
+ it do
18
+ foo = instance_spy(Foo)
19
+ expect(foo).to have_received(:bar)
20
+ end
21
+ RUBY
13
22
  end
14
23
 
15
24
  it 'adds an offense for an instance_double with multiple arguments' do
@@ -20,6 +29,13 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
20
29
  expect(foo).to have_received(:bar)
21
30
  end
22
31
  RUBY
32
+
33
+ expect_correction(<<-RUBY)
34
+ it do
35
+ foo = instance_spy(Foo, :name)
36
+ expect(foo).to have_received(:bar)
37
+ end
38
+ RUBY
23
39
  end
24
40
 
25
41
  it 'ignores instance_double when it is not used with as_null_object' do
@@ -42,19 +58,4 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
42
58
  RUBY
43
59
  end
44
60
  end
45
-
46
- original = <<-RUBY
47
- it do
48
- foo = instance_double(Foo, :name).as_null_object
49
- expect(foo).to have_received(:bar)
50
- end
51
- RUBY
52
- corrected = <<-RUBY
53
- it do
54
- foo = instance_spy(Foo, :name)
55
- expect(foo).to have_received(:bar)
56
- end
57
- RUBY
58
-
59
- include_examples 'autocorrect', original, corrected
60
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::InstanceVariable 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::InvalidPredicateMatcher 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::ItBehavesLike, :config do
2
4
  subject(:cop) { described_class.new(config) }
3
5
 
@@ -13,17 +15,15 @@ RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do
13
15
  it_should_behave_like 'a foo'
14
16
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_behaves_like` over `it_should_behave_like` when including examples in a nested context.
15
17
  RUBY
18
+
19
+ expect_correction(<<-RUBY)
20
+ it_behaves_like 'a foo'
21
+ RUBY
16
22
  end
17
23
 
18
24
  it 'does not flag a violation for it_behaves_like' do
19
25
  expect_no_offenses("it_behaves_like 'a foo'")
20
26
  end
21
-
22
- include_examples(
23
- 'autocorrect',
24
- "foo(); it_should_behave_like 'a foo'",
25
- "foo(); it_behaves_like 'a foo'"
26
- )
27
27
  end
28
28
 
29
29
  context 'when the enforced style is `it_should_behave_like`' do
@@ -34,16 +34,14 @@ RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do
34
34
  it_behaves_like 'a foo'
35
35
  ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_should_behave_like` over `it_behaves_like` when including examples in a nested context.
36
36
  RUBY
37
+
38
+ expect_correction(<<-RUBY)
39
+ it_should_behave_like 'a foo'
40
+ RUBY
37
41
  end
38
42
 
39
43
  it 'does not flag a violation for it_behaves_like' do
40
44
  expect_no_offenses("it_should_behave_like 'a foo'")
41
45
  end
42
-
43
- include_examples(
44
- 'autocorrect',
45
- "foo(); it_behaves_like 'a foo'",
46
- "foo(); it_should_behave_like 'a foo'"
47
- )
48
46
  end
49
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe RuboCop::Cop::RSpec::IteratedExpectation do
2
4
  subject(:cop) { described_class.new }
3
5
 
@@ -12,6 +12,14 @@ RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
12
12
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations.
13
13
  end
14
14
  RUBY
15
+
16
+ expect_correction(<<-RUBY)
17
+ RSpec.describe User do
18
+ subject { described_class.new }
19
+ let(:params) { foo }
20
+
21
+ end
22
+ RUBY
15
23
  end
16
24
 
17
25
  it 'checks subject below let!' do
@@ -23,6 +31,14 @@ RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
23
31
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let!` declarations.
24
32
  end
25
33
  RUBY
34
+
35
+ expect_correction(<<-RUBY)
36
+ RSpec.describe User do
37
+ subject { described_class.new }
38
+ let!(:params) { foo }
39
+
40
+ end
41
+ RUBY
26
42
  end
27
43
 
28
44
  it 'approves of subject above let' do
@@ -72,6 +88,14 @@ RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
72
88
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `before` declarations.
73
89
  end
74
90
  RUBY
91
+
92
+ expect_correction(<<-RUBY)
93
+ RSpec.describe User do
94
+ subject { described_class.new }
95
+ before { allow(Foo).to receive(:bar) }
96
+
97
+ end
98
+ RUBY
75
99
  end
76
100
 
77
101
  it 'checks subject below example' do
@@ -83,53 +107,13 @@ RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
83
107
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `it` declarations.
84
108
  end
85
109
  RUBY
86
- end
87
110
 
88
- bad_code = <<-RUBY
89
- RSpec.describe User do
90
- before { allow(Foo).to receive(:bar) }
91
- let(:params) { foo }
92
- let(:bar) { baz }
93
-
94
- subject { described_class.new }
95
- it { is_expected.to do_something }
96
- end
97
- RUBY
98
-
99
- good_code = <<-RUBY
100
- RSpec.describe User do
101
- subject { described_class.new }
102
- before { allow(Foo).to receive(:bar) }
103
- let(:params) { foo }
104
- let(:bar) { baz }
105
-
106
- it { is_expected.to do_something }
107
- end
108
- RUBY
109
-
110
- include_examples 'autocorrect', bad_code, good_code
111
-
112
- bad_code = <<-RUBY
113
- RSpec.describe User do
114
- let(:params) { foo }
115
- let(:bar) { baz }
116
- subject do
117
- described_class.new
118
- end
119
- it { is_expected.to do_something }
120
- end
121
- RUBY
122
-
123
- good_code = <<-RUBY
124
- RSpec.describe User do
125
- subject do
126
- described_class.new
127
- end
128
- let(:params) { foo }
129
- let(:bar) { baz }
130
- it { is_expected.to do_something }
131
- end
132
- RUBY
111
+ expect_correction(<<-RUBY)
112
+ RSpec.describe User do
113
+ subject { described_class.new }
114
+ it { is_expected.to be_present }
133
115
 
134
- include_examples 'autocorrect', bad_code, good_code
116
+ end
117
+ RUBY
118
+ end
135
119
  end