rubocop-rspec 1.7.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +955 -79
  3. data/CODE_OF_CONDUCT.md +17 -0
  4. data/MIT-LICENSE.md +1 -2
  5. data/README.md +35 -35
  6. data/config/default.yml +940 -52
  7. data/config/obsoletion.yml +30 -0
  8. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +49 -0
  9. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +49 -0
  10. data/lib/rubocop/cop/rspec/any_instance.rb +10 -13
  11. data/lib/rubocop/cop/rspec/around_block.rb +97 -0
  12. data/lib/rubocop/cop/rspec/base.rb +26 -0
  13. data/lib/rubocop/cop/rspec/be.rb +39 -0
  14. data/lib/rubocop/cop/rspec/be_empty.rb +45 -0
  15. data/lib/rubocop/cop/rspec/be_eq.rb +47 -0
  16. data/lib/rubocop/cop/rspec/be_eql.rb +18 -15
  17. data/lib/rubocop/cop/rspec/be_nil.rb +74 -0
  18. data/lib/rubocop/cop/rspec/before_after_all.rb +45 -0
  19. data/lib/rubocop/cop/rspec/change_by_zero.rb +184 -0
  20. data/lib/rubocop/cop/rspec/class_check.rb +101 -0
  21. data/lib/rubocop/cop/rspec/contain_exactly.rb +56 -0
  22. data/lib/rubocop/cop/rspec/context_method.rb +57 -0
  23. data/lib/rubocop/cop/rspec/context_wording.rb +117 -0
  24. data/lib/rubocop/cop/rspec/describe_class.rb +52 -21
  25. data/lib/rubocop/cop/rspec/describe_method.rb +26 -11
  26. data/lib/rubocop/cop/rspec/describe_symbol.rb +37 -0
  27. data/lib/rubocop/cop/rspec/described_class.rb +181 -34
  28. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +38 -0
  29. data/lib/rubocop/cop/rspec/dialect.rb +84 -0
  30. data/lib/rubocop/cop/rspec/duplicated_metadata.rb +58 -0
  31. data/lib/rubocop/cop/rspec/empty_example_group.rb +134 -47
  32. data/lib/rubocop/cop/rspec/empty_hook.rb +49 -0
  33. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +82 -0
  34. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +42 -0
  35. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +40 -0
  36. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +82 -0
  37. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +36 -0
  38. data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
  39. data/lib/rubocop/cop/rspec/empty_output.rb +47 -0
  40. data/lib/rubocop/cop/rspec/eq.rb +47 -0
  41. data/lib/rubocop/cop/rspec/example_length.rb +38 -20
  42. data/lib/rubocop/cop/rspec/example_without_description.rb +98 -0
  43. data/lib/rubocop/cop/rspec/example_wording.rb +117 -27
  44. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +110 -0
  45. data/lib/rubocop/cop/rspec/expect_actual.rb +46 -20
  46. data/lib/rubocop/cop/rspec/expect_change.rb +86 -0
  47. data/lib/rubocop/cop/rspec/expect_in_hook.rb +50 -0
  48. data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
  49. data/lib/rubocop/cop/rspec/expect_output.rb +50 -0
  50. data/lib/rubocop/cop/rspec/focus.rb +79 -25
  51. data/lib/rubocop/cop/rspec/hook_argument.rb +48 -36
  52. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +81 -0
  53. data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +37 -0
  54. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +68 -0
  55. data/lib/rubocop/cop/rspec/implicit_expect.rb +100 -0
  56. data/lib/rubocop/cop/rspec/implicit_subject.rb +167 -0
  57. data/lib/rubocop/cop/rspec/indexed_let.rb +112 -0
  58. data/lib/rubocop/cop/rspec/instance_spy.rb +74 -0
  59. data/lib/rubocop/cop/rspec/instance_variable.rb +28 -14
  60. data/lib/rubocop/cop/rspec/is_expected_specify.rb +45 -0
  61. data/lib/rubocop/cop/rspec/it_behaves_like.rb +49 -0
  62. data/lib/rubocop/cop/rspec/iterated_expectation.rb +74 -0
  63. data/lib/rubocop/cop/rspec/leading_subject.rb +57 -29
  64. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +127 -0
  65. data/lib/rubocop/cop/rspec/let_before_examples.rb +101 -0
  66. data/lib/rubocop/cop/rspec/let_setup.rb +32 -16
  67. data/lib/rubocop/cop/rspec/match_array.rb +59 -0
  68. data/lib/rubocop/cop/rspec/message_chain.rb +10 -15
  69. data/lib/rubocop/cop/rspec/message_expectation.rb +12 -9
  70. data/lib/rubocop/cop/rspec/message_spies.rb +88 -0
  71. data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
  72. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +35 -0
  73. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  74. data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
  75. data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +59 -0
  76. data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
  77. data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
  78. data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +29 -0
  79. data/lib/rubocop/cop/rspec/mixin/location_help.rb +37 -0
  80. data/lib/rubocop/cop/rspec/mixin/metadata.rb +63 -0
  81. data/lib/rubocop/cop/rspec/mixin/namespace.rb +23 -0
  82. data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +39 -0
  83. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
  84. data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
  85. data/lib/rubocop/cop/rspec/multiple_describes.rb +14 -12
  86. data/lib/rubocop/cop/rspec/multiple_expectations.rb +86 -26
  87. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +146 -0
  88. data/lib/rubocop/cop/rspec/multiple_subjects.rb +97 -0
  89. data/lib/rubocop/cop/rspec/named_subject.rb +107 -27
  90. data/lib/rubocop/cop/rspec/nested_groups.rb +84 -47
  91. data/lib/rubocop/cop/rspec/no_expectation_example.rb +102 -0
  92. data/lib/rubocop/cop/rspec/not_to_not.rb +30 -27
  93. data/lib/rubocop/cop/rspec/overwriting_setup.rb +74 -0
  94. data/lib/rubocop/cop/rspec/pending.rb +80 -0
  95. data/lib/rubocop/cop/rspec/pending_without_reason.rb +159 -0
  96. data/lib/rubocop/cop/rspec/predicate_matcher.rb +341 -0
  97. data/lib/rubocop/cop/rspec/receive_counts.rb +89 -0
  98. data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
  99. data/lib/rubocop/cop/rspec/receive_never.rb +41 -0
  100. data/lib/rubocop/cop/rspec/redundant_around.rb +65 -0
  101. data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +67 -0
  102. data/lib/rubocop/cop/rspec/remove_const.rb +39 -0
  103. data/lib/rubocop/cop/rspec/repeated_description.rb +98 -0
  104. data/lib/rubocop/cop/rspec/repeated_example.rb +53 -0
  105. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +100 -0
  106. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +96 -0
  107. data/lib/rubocop/cop/rspec/repeated_include_example.rb +105 -0
  108. data/lib/rubocop/cop/rspec/repeated_subject_call.rb +125 -0
  109. data/lib/rubocop/cop/rspec/return_from_stub.rb +169 -0
  110. data/lib/rubocop/cop/rspec/scattered_let.rb +59 -0
  111. data/lib/rubocop/cop/rspec/scattered_setup.rb +92 -0
  112. data/lib/rubocop/cop/rspec/shared_context.rb +107 -0
  113. data/lib/rubocop/cop/rspec/shared_examples.rb +125 -0
  114. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +93 -0
  115. data/lib/rubocop/cop/rspec/skip_block_inside_example.rb +46 -0
  116. data/lib/rubocop/cop/rspec/sort_metadata.rb +71 -0
  117. data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
  118. data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
  119. data/lib/rubocop/cop/rspec/stubbed_mock.rb +176 -0
  120. data/lib/rubocop/cop/rspec/subject_declaration.rb +46 -0
  121. data/lib/rubocop/cop/rspec/subject_stub.rb +93 -74
  122. data/lib/rubocop/cop/rspec/undescriptive_literals_description.rb +69 -0
  123. data/lib/rubocop/cop/rspec/unspecified_exception.rb +67 -0
  124. data/lib/rubocop/cop/rspec/variable_definition.rb +77 -0
  125. data/lib/rubocop/cop/rspec/variable_name.rb +68 -0
  126. data/lib/rubocop/cop/rspec/verified_double_reference.rb +111 -0
  127. data/lib/rubocop/cop/rspec/verified_doubles.rb +28 -14
  128. data/lib/rubocop/cop/rspec/void_expect.rb +60 -0
  129. data/lib/rubocop/cop/rspec/yield.rb +82 -0
  130. data/lib/rubocop/cop/rspec_cops.rb +112 -0
  131. data/lib/rubocop/rspec/align_let_brace.rb +63 -0
  132. data/lib/rubocop/rspec/concept.rb +33 -0
  133. data/lib/rubocop/rspec/config_formatter.rb +27 -4
  134. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  135. data/lib/rubocop/rspec/corrector/move_node.rb +51 -0
  136. data/lib/rubocop/rspec/description_extractor.rb +60 -18
  137. data/lib/rubocop/rspec/example.rb +37 -0
  138. data/lib/rubocop/rspec/example_group.rb +67 -0
  139. data/lib/rubocop/rspec/hook.rb +79 -0
  140. data/lib/rubocop/rspec/inject.rb +3 -1
  141. data/lib/rubocop/rspec/language.rb +184 -41
  142. data/lib/rubocop/rspec/node.rb +19 -0
  143. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +29 -0
  144. data/lib/rubocop/rspec/version.rb +1 -1
  145. data/lib/rubocop/rspec/wording.rb +61 -19
  146. data/lib/rubocop/rspec.rb +6 -2
  147. data/lib/rubocop-rspec.rb +45 -34
  148. metadata +130 -195
  149. data/Gemfile +0 -13
  150. data/Rakefile +0 -48
  151. data/lib/rubocop/cop/rspec/file_path.rb +0 -83
  152. data/lib/rubocop/rspec/language/node_pattern.rb +0 -16
  153. data/lib/rubocop/rspec/spec_only.rb +0 -61
  154. data/lib/rubocop/rspec/top_level_describe.rb +0 -61
  155. data/lib/rubocop/rspec/util.rb +0 -19
  156. data/rubocop-rspec.gemspec +0 -42
  157. data/spec/expect_violation/expectation_spec.rb +0 -85
  158. data/spec/project/changelog_spec.rb +0 -81
  159. data/spec/project/default_config_spec.rb +0 -52
  160. data/spec/project/project_requires_spec.rb +0 -8
  161. data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -30
  162. data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -59
  163. data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -113
  164. data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -32
  165. data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -219
  166. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -79
  167. data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -117
  168. data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -82
  169. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -136
  170. data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -236
  171. data/spec/rubocop/cop/rspec/focus_spec.rb +0 -130
  172. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -189
  173. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -75
  174. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -54
  175. data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
  176. data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -21
  177. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -63
  178. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -28
  179. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -84
  180. data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -62
  181. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -55
  182. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -57
  183. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -183
  184. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -71
  185. data/spec/rubocop/rspec/config_formatter_spec.rb +0 -48
  186. data/spec/rubocop/rspec/description_extractor_spec.rb +0 -35
  187. data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -29
  188. data/spec/rubocop/rspec/spec_only_spec.rb +0 -97
  189. data/spec/rubocop/rspec/util/one_spec.rb +0 -21
  190. data/spec/rubocop/rspec/wording_spec.rb +0 -44
  191. data/spec/shared/rspec_only_cop_behavior.rb +0 -68
  192. data/spec/spec_helper.rb +0 -41
  193. data/spec/support/expect_violation.rb +0 -166
@@ -1,219 +0,0 @@
1
- describe RuboCop::Cop::RSpec::DescribedClass, :config do
2
- subject(:cop) { described_class.new(config) }
3
-
4
- shared_examples 'SkipBlocks enabled' do
5
- it 'does not flag violations within non-rspec blocks' do
6
- expect_violation(<<-RUBY)
7
- describe MyClass do
8
- controller(ApplicationController) do
9
- bar = MyClass
10
- end
11
-
12
- before do
13
- MyClass
14
- ^^^^^^^ Use `described_class` instead of `MyClass`
15
-
16
- Foo.custom_block do
17
- MyClass
18
- end
19
- end
20
- end
21
- RUBY
22
- end
23
- end
24
-
25
- shared_examples 'SkipBlocks disabled' do
26
- it 'flags violations within all blocks' do
27
- expect_violation(<<-RUBY)
28
- describe MyClass do
29
- controller(ApplicationController) do
30
- bar = MyClass
31
- ^^^^^^^ Use `described_class` instead of `MyClass`
32
- end
33
-
34
- before(:each) do
35
- MyClass
36
- ^^^^^^^ Use `described_class` instead of `MyClass`
37
-
38
- Foo.custom_block do
39
- MyClass
40
- ^^^^^^^ Use `described_class` instead of `MyClass`
41
- end
42
- end
43
- end
44
- RUBY
45
- end
46
- end
47
-
48
- context 'when SkipBlocks is `true`' do
49
- let(:cop_config) { { 'SkipBlocks' => true } }
50
-
51
- include_examples 'SkipBlocks enabled'
52
- end
53
-
54
- context 'when SkipBlocks anything besides `true`' do
55
- let(:cop_config) { { 'SkipBlocks' => 'yes' } }
56
-
57
- include_examples 'SkipBlocks disabled'
58
- end
59
-
60
- context 'when SkipBlocks is not set' do
61
- let(:cop_config) { Hash.new }
62
-
63
- include_examples 'SkipBlocks disabled'
64
- end
65
-
66
- context 'when SkipBlocks is `false`' do
67
- let(:cop_config) { { 'SkipBlocks' => false } }
68
-
69
- include_examples 'SkipBlocks disabled'
70
- end
71
-
72
- it 'checks for the use of the described class' do
73
- expect_violation(<<-RUBY)
74
- describe MyClass do
75
- include MyClass
76
- ^^^^^^^ Use `described_class` instead of `MyClass`
77
-
78
- subject { MyClass.do_something }
79
- ^^^^^^^ Use `described_class` instead of `MyClass`
80
-
81
- before { MyClass.do_something }
82
- ^^^^^^^ Use `described_class` instead of `MyClass`
83
- end
84
- RUBY
85
- end
86
-
87
- it 'ignores described class as string' do
88
- expect_no_violations(<<-RUBY)
89
- describe MyClass do
90
- subject { "MyClass" }
91
- end
92
- RUBY
93
- end
94
-
95
- it 'ignores describe that do not reference to a class' do
96
- expect_no_violations(<<-RUBY)
97
- describe "MyClass" do
98
- subject { "MyClass" }
99
- end
100
- RUBY
101
- end
102
-
103
- it 'ignores class if the scope is changing' do
104
- expect_no_violations(<<-RUBY)
105
- describe MyClass do
106
- Class.new { foo = MyClass }
107
- Module.new { bar = MyClass }
108
-
109
- def method
110
- include MyClass
111
- end
112
-
113
- class OtherClass
114
- include MyClass
115
- end
116
-
117
- module MyModle
118
- include MyClass
119
- end
120
- end
121
- RUBY
122
- end
123
-
124
- it 'only takes class from top level describes' do
125
- expect_violation(<<-RUBY)
126
- describe MyClass do
127
- describe MyClass::Foo do
128
- subject { MyClass::Foo }
129
-
130
- let(:foo) { MyClass }
131
- ^^^^^^^ Use `described_class` instead of `MyClass`
132
- end
133
- end
134
- RUBY
135
- end
136
-
137
- it 'ignores subclasses' do
138
- expect_no_violations(<<-RUBY)
139
- describe MyClass do
140
- subject { MyClass::SubClass }
141
- end
142
- RUBY
143
- end
144
-
145
- it 'ignores if namespace is not matching' do
146
- expect_no_violations(<<-RUBY)
147
- describe MyNamespace::MyClass do
148
- subject { ::MyClass }
149
- let(:foo) { MyClass }
150
- end
151
- RUBY
152
- end
153
-
154
- it 'checks for the use of described class with namespace' do
155
- expect_violation(<<-RUBY)
156
- describe MyNamespace::MyClass do
157
- subject { MyNamespace::MyClass }
158
- ^^^^^^^^^^^^^^^^^^^^ Use `described_class` instead of `MyNamespace::MyClass`
159
- end
160
- RUBY
161
- end
162
-
163
- it 'does not flag violations within a scope change' do
164
- expect_no_violations(<<-RUBY)
165
- describe MyNamespace::MyClass do
166
- before do
167
- class Foo
168
- thing = MyNamespace::MyClass.new
169
- end
170
- end
171
- end
172
- RUBY
173
- end
174
-
175
- it 'does not flag violations within a scope change' do
176
- expect_no_violations(<<-RUBY)
177
- describe do
178
- before do
179
- MyNamespace::MyClass.new
180
- end
181
- end
182
- RUBY
183
- end
184
-
185
- it 'checks for the use of described class with module' do
186
- skip
187
-
188
- expect_violation(<<-RUBY)
189
- module MyNamespace
190
- describe MyClass do
191
- subject { MyNamespace::MyClass }
192
- ^^^^^^^^^^^^^^^^^^^^ Use `described_class` instead of `MyNamespace::MyClass`
193
- end
194
- end
195
- RUBY
196
- end
197
-
198
- it 'autocorrects an offenses' do
199
- new_source = autocorrect_source(
200
- cop,
201
- [
202
- 'describe MyClass do',
203
- ' include MyClass',
204
- ' subject { MyClass.do_something }',
205
- ' before { MyClass.do_something }',
206
- 'end'
207
- ], 'spec/foo_spec.rb'
208
- )
209
- expect(new_source).to eq(
210
- [
211
- 'describe MyClass do',
212
- ' include described_class',
213
- ' subject { described_class.do_something }',
214
- ' before { described_class.do_something }',
215
- 'end'
216
- ].join("\n")
217
- )
218
- end
219
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe RuboCop::Cop::RSpec::EmptyExampleGroup, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- it 'flags an empty context' do
7
- expect_violation(<<-RUBY)
8
- describe Foo do
9
- context 'when bar' do
10
- ^^^^^^^^^^^^^^^^^^ Empty example group detected.
11
-
12
- let(:foo) { bar }
13
- end
14
-
15
- describe '#thingy?' do
16
- specify do
17
- expect(whatever.thingy?).to be(true)
18
- end
19
- end
20
-
21
- it { should be_true }
22
- end
23
- RUBY
24
- end
25
-
26
- it 'flags an empty top level describe' do
27
- expect_violation(<<-RUBY)
28
- describe Foo do
29
- ^^^^^^^^^^^^ Empty example group detected.
30
- end
31
- RUBY
32
- end
33
-
34
- it 'does not flag include_examples' do
35
- expect_no_violations(<<-RUBY)
36
- describe Foo do
37
- context "when something is true" do
38
- include_examples "some expectations"
39
- end
40
-
41
- context "when something else is true" do
42
- include_context "some expectations"
43
- end
44
-
45
- context "when a third thing is true" do
46
- it_behaves_like "some thingy"
47
- end
48
- end
49
- RUBY
50
- end
51
-
52
- it 'does not recognize custom include methods by default' do
53
- expect_violation(<<-RUBY)
54
- describe Foo do
55
- ^^^^^^^^^^^^ Empty example group detected.
56
- context "when I do something clever" do
57
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Empty example group detected.
58
- it_has_special_behavior
59
- end
60
- end
61
- RUBY
62
- end
63
-
64
- context 'when a custom include method is specified' do
65
- let(:cop_config) do
66
- { 'CustomIncludeMethods' => %w(it_has_special_behavior) }
67
- end
68
-
69
- it 'does not flag an otherwise empty example group' do
70
- expect_no_violations(<<-RUBY)
71
- describe Foo do
72
- context "when I do something clever" do
73
- it_has_special_behavior
74
- end
75
- end
76
- RUBY
77
- end
78
- end
79
- end
@@ -1,117 +0,0 @@
1
- describe RuboCop::Cop::RSpec::ExampleLength, :config do
2
- subject(:cop) { described_class.new(config) }
3
-
4
- let(:cop_config) { { 'Max' => 3 } }
5
-
6
- it 'ignores non-spec blocks' do
7
- inspect_source(
8
- cop,
9
- [
10
- 'foo do',
11
- ' line 1',
12
- ' line 2',
13
- ' line 3',
14
- ' line 4',
15
- 'end'
16
- ],
17
- 'foo_spec.rb'
18
- )
19
-
20
- expect(cop.offenses).to be_empty
21
- end
22
-
23
- it 'allows an empty example' do
24
- inspect_source(
25
- cop,
26
- [
27
- 'it do',
28
- 'end'
29
- ],
30
- 'foo_spec.rb'
31
- )
32
- expect(cop.offenses).to be_empty
33
- end
34
-
35
- it 'allows a short example' do
36
- inspect_source(
37
- cop,
38
- [
39
- 'it do',
40
- ' line 1',
41
- ' line 2',
42
- ' line 3',
43
- 'end'
44
- ],
45
- 'spec/foo_spec.rb'
46
- )
47
- expect(cop.offenses).to be_empty
48
- end
49
-
50
- it 'ignores comments' do
51
- inspect_source(
52
- cop,
53
- [
54
- 'it do',
55
- ' line 1',
56
- ' line 2',
57
- ' # comment',
58
- ' line 3',
59
- 'end'
60
- ],
61
- 'spec/foo_spec.rb'
62
- )
63
- expect(cop.offenses).to be_empty
64
- end
65
-
66
- shared_examples 'large example violation' do
67
- before do
68
- inspect_source(cop, source, 'spec/foo_spec.rb')
69
- end
70
-
71
- it 'flags an offense' do
72
- expect(cop.offenses.size).to eq(1)
73
- end
74
-
75
- it 'registers the offense on line 1' do
76
- expect(cop.offenses.map(&:line)).to eq([1])
77
- end
78
-
79
- it 'adds a message saying the example has too many lines' do
80
- expect(cop.messages).to eq(['Example has too many lines. [4/3]'])
81
- end
82
- end
83
-
84
- context 'when inspecting large examples' do
85
- let(:source) do
86
- [
87
- 'it do',
88
- ' line 1',
89
- ' line 2',
90
- ' line 3',
91
- ' line 4',
92
- 'end'
93
- ]
94
- end
95
-
96
- include_examples 'large example violation'
97
- end
98
-
99
- context 'with CountComments enabled' do
100
- let(:cop_config) do
101
- { 'Max' => 3, 'CountComments' => true }
102
- end
103
-
104
- let(:source) do
105
- [
106
- 'it do',
107
- ' line 1',
108
- ' line 2',
109
- ' # comment',
110
- ' line 3',
111
- 'end'
112
- ]
113
- end
114
-
115
- include_examples 'large example violation'
116
- end
117
- end
@@ -1,82 +0,0 @@
1
- describe RuboCop::Cop::RSpec::ExampleWording, :config do
2
- subject(:cop) { described_class.new(config) }
3
-
4
- context 'with configuration' do
5
- let(:cop_config) do
6
- {
7
- 'CustomTransform' => { 'have' => 'has', 'not' => 'does not' },
8
- 'IgnoredWords' => %w(only really)
9
- }
10
- end
11
-
12
- it 'ignores non-example blocks' do
13
- expect_no_violations('foo "should do something" do; end')
14
- end
15
-
16
- it 'finds description with `should` at the beginning' do
17
- expect_violation(<<-RUBY)
18
- it 'should do something' do
19
- ^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
20
- end
21
- RUBY
22
- end
23
-
24
- it 'finds description with `Should` at the beginning' do
25
- expect_violation(<<-RUBY)
26
- it 'Should do something' do
27
- ^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
28
- end
29
- RUBY
30
- end
31
-
32
- it 'finds description with `shouldn\'t` at the beginning' do
33
- expect_violation(<<-RUBY)
34
- it "shouldn't do something" do
35
- ^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
36
- end
37
- RUBY
38
- end
39
-
40
- it 'skips descriptions without `should` at the beginning' do
41
- expect_no_violations(<<-RUBY)
42
- it 'finds no should here' do
43
- end
44
- RUBY
45
- end
46
-
47
- it 'corrects `it "should only have"` to it "only has"' do
48
- corrected =
49
- autocorrect_source(
50
- cop,
51
- 'it "should only have trait" do end',
52
- 'spec/foo_spec.rb'
53
- )
54
-
55
- expect(corrected).to eql('it "only has trait" do end')
56
- end
57
- end
58
-
59
- context 'when configuration is empty' do
60
- it 'only does not correct "have"' do
61
- corrected =
62
- autocorrect_source(
63
- cop,
64
- 'it "should have trait" do end',
65
- 'spec/foo_spec.rb'
66
- )
67
-
68
- expect(corrected).to eql('it "haves trait" do end')
69
- end
70
-
71
- it 'only does not make an exception for the word "only"' do
72
- corrected =
73
- autocorrect_source(
74
- cop,
75
- 'it "should only fail" do end',
76
- 'spec/foo_spec.rb'
77
- )
78
-
79
- expect(corrected).to eql('it "onlies fail" do end')
80
- end
81
- end
82
- end
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe RuboCop::Cop::RSpec::ExpectActual do
4
- subject(:cop) { described_class.new }
5
-
6
- it 'flags numeric literal values within expect(...)' do
7
- expect_violation(<<-RUBY)
8
- describe Foo do
9
- it 'uses expect incorrectly' do
10
- expect(123).to eq(bar)
11
- ^^^ Provide the actual you are testing to `expect(...)`
12
- expect(12.3).to eq(bar)
13
- ^^^^ Provide the actual you are testing to `expect(...)`
14
- expect(1i).to eq(bar)
15
- ^^ Provide the actual you are testing to `expect(...)`
16
- expect(1r).to eq(bar)
17
- ^^ Provide the actual you are testing to `expect(...)`
18
- end
19
- end
20
- RUBY
21
- end
22
-
23
- it 'flags boolean literal values within expect(...)' do
24
- expect_violation(<<-RUBY)
25
- describe Foo do
26
- it 'uses expect incorrectly' do
27
- expect(true).to eq(bar)
28
- ^^^^ Provide the actual you are testing to `expect(...)`
29
- expect(false).to eq(bar)
30
- ^^^^^ Provide the actual you are testing to `expect(...)`
31
- end
32
- end
33
- RUBY
34
- end
35
-
36
- it 'flags string and symbol literal values within expect(...)' do
37
- expect_violation(<<-RUBY)
38
- describe Foo do
39
- it 'uses expect incorrectly' do
40
- expect("foo").to eq(bar)
41
- ^^^^^ Provide the actual you are testing to `expect(...)`
42
- expect(:foo).to eq(bar)
43
- ^^^^ Provide the actual you are testing to `expect(...)`
44
- end
45
- end
46
- RUBY
47
- end
48
-
49
- it 'flags literal nil value within expect(...)' do
50
- expect_violation(<<-RUBY)
51
- describe Foo do
52
- it 'uses expect incorrectly' do
53
- expect(nil).to eq(bar)
54
- ^^^ Provide the actual you are testing to `expect(...)`
55
- end
56
- end
57
- RUBY
58
- end
59
-
60
- it 'does not flag dynamic values within expect(...)' do
61
- expect_no_violations(<<-'RUBY')
62
- describe Foo do
63
- it 'uses expect correctly' do
64
- expect(foo).to eq(bar)
65
- expect("foo#{baz}").to eq(bar)
66
- expect(:"foo#{baz}").to eq(bar)
67
- end
68
- end
69
- RUBY
70
- end
71
-
72
- it 'flags arrays containing only literal values within expect(...)' do
73
- expect_violation(<<-RUBY)
74
- describe Foo do
75
- it 'uses expect incorrectly' do
76
- expect([123]).to eq(bar)
77
- ^^^^^ Provide the actual you are testing to `expect(...)`
78
- expect([[123]]).to eq(bar)
79
- ^^^^^^^ Provide the actual you are testing to `expect(...)`
80
- end
81
- end
82
- RUBY
83
- end
84
-
85
- it 'flags hashes containing only literal values within expect(...)' do
86
- expect_violation(<<-RUBY)
87
- describe Foo do
88
- it 'uses expect incorrectly' do
89
- expect(foo: 1, bar: 2).to eq(bar)
90
- ^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
91
- expect(foo: 1, bar: [{}]).to eq(bar)
92
- ^^^^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
93
- end
94
- end
95
- RUBY
96
- end
97
-
98
- it 'flags ranges containing only literal values within expect(...)' do
99
- expect_violation(<<-RUBY)
100
- describe Foo do
101
- it 'uses expect incorrectly' do
102
- expect(1..2).to eq(bar)
103
- ^^^^ Provide the actual you are testing to `expect(...)`
104
- expect(1...2).to eq(bar)
105
- ^^^^^ Provide the actual you are testing to `expect(...)`
106
- end
107
- end
108
- RUBY
109
- end
110
-
111
- it 'flags regexps containing only literal values within expect(...)' do
112
- expect_violation(<<-RUBY)
113
- describe Foo do
114
- it 'uses expect incorrectly' do
115
- expect(/foo|bar/).to eq(bar)
116
- ^^^^^^^^^ Provide the actual you are testing to `expect(...)`
117
- end
118
- end
119
- RUBY
120
- end
121
-
122
- it 'does not flag complex values with dynamic parts within expect(...)' do
123
- expect_no_violations(<<-'RUBY')
124
- describe Foo do
125
- it 'uses expect incorrectly' do
126
- expect([foo]).to eq(bar)
127
- expect([[foo]]).to eq(bar)
128
- expect(foo: 1, bar: foo).to eq(bar)
129
- expect(1..foo).to eq(bar)
130
- expect(1...foo).to eq(bar)
131
- expect(/foo|#{bar}/).to eq(bar)
132
- end
133
- end
134
- RUBY
135
- end
136
- end