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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +955 -79
- data/CODE_OF_CONDUCT.md +17 -0
- data/MIT-LICENSE.md +1 -2
- data/README.md +35 -35
- data/config/default.yml +940 -52
- data/config/obsoletion.yml +30 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +49 -0
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +49 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +10 -13
- data/lib/rubocop/cop/rspec/around_block.rb +97 -0
- data/lib/rubocop/cop/rspec/base.rb +26 -0
- data/lib/rubocop/cop/rspec/be.rb +39 -0
- data/lib/rubocop/cop/rspec/be_empty.rb +45 -0
- data/lib/rubocop/cop/rspec/be_eq.rb +47 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +18 -15
- data/lib/rubocop/cop/rspec/be_nil.rb +74 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +45 -0
- data/lib/rubocop/cop/rspec/change_by_zero.rb +184 -0
- data/lib/rubocop/cop/rspec/class_check.rb +101 -0
- data/lib/rubocop/cop/rspec/contain_exactly.rb +56 -0
- data/lib/rubocop/cop/rspec/context_method.rb +57 -0
- data/lib/rubocop/cop/rspec/context_wording.rb +117 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +52 -21
- data/lib/rubocop/cop/rspec/describe_method.rb +26 -11
- data/lib/rubocop/cop/rspec/describe_symbol.rb +37 -0
- data/lib/rubocop/cop/rspec/described_class.rb +181 -34
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +38 -0
- data/lib/rubocop/cop/rspec/dialect.rb +84 -0
- data/lib/rubocop/cop/rspec/duplicated_metadata.rb +58 -0
- data/lib/rubocop/cop/rspec/empty_example_group.rb +134 -47
- data/lib/rubocop/cop/rspec/empty_hook.rb +49 -0
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +82 -0
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +42 -0
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +40 -0
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +82 -0
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +36 -0
- data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
- data/lib/rubocop/cop/rspec/empty_output.rb +47 -0
- data/lib/rubocop/cop/rspec/eq.rb +47 -0
- data/lib/rubocop/cop/rspec/example_length.rb +38 -20
- data/lib/rubocop/cop/rspec/example_without_description.rb +98 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +117 -27
- data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +110 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +46 -20
- data/lib/rubocop/cop/rspec/expect_change.rb +86 -0
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +50 -0
- data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
- data/lib/rubocop/cop/rspec/expect_output.rb +50 -0
- data/lib/rubocop/cop/rspec/focus.rb +79 -25
- data/lib/rubocop/cop/rspec/hook_argument.rb +48 -36
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +81 -0
- data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +37 -0
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +68 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +100 -0
- data/lib/rubocop/cop/rspec/implicit_subject.rb +167 -0
- data/lib/rubocop/cop/rspec/indexed_let.rb +112 -0
- data/lib/rubocop/cop/rspec/instance_spy.rb +74 -0
- data/lib/rubocop/cop/rspec/instance_variable.rb +28 -14
- data/lib/rubocop/cop/rspec/is_expected_specify.rb +45 -0
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +49 -0
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +74 -0
- data/lib/rubocop/cop/rspec/leading_subject.rb +57 -29
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +127 -0
- data/lib/rubocop/cop/rspec/let_before_examples.rb +101 -0
- data/lib/rubocop/cop/rspec/let_setup.rb +32 -16
- data/lib/rubocop/cop/rspec/match_array.rb +59 -0
- data/lib/rubocop/cop/rspec/message_chain.rb +10 -15
- data/lib/rubocop/cop/rspec/message_expectation.rb +12 -9
- data/lib/rubocop/cop/rspec/message_spies.rb +88 -0
- data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +35 -0
- data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +59 -0
- data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
- data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
- data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +29 -0
- data/lib/rubocop/cop/rspec/mixin/location_help.rb +37 -0
- data/lib/rubocop/cop/rspec/mixin/metadata.rb +63 -0
- data/lib/rubocop/cop/rspec/mixin/namespace.rb +23 -0
- data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +39 -0
- data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +14 -12
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +86 -26
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +146 -0
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +97 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +107 -27
- data/lib/rubocop/cop/rspec/nested_groups.rb +84 -47
- data/lib/rubocop/cop/rspec/no_expectation_example.rb +102 -0
- data/lib/rubocop/cop/rspec/not_to_not.rb +30 -27
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +74 -0
- data/lib/rubocop/cop/rspec/pending.rb +80 -0
- data/lib/rubocop/cop/rspec/pending_without_reason.rb +159 -0
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +341 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +89 -0
- data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +41 -0
- data/lib/rubocop/cop/rspec/redundant_around.rb +65 -0
- data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +67 -0
- data/lib/rubocop/cop/rspec/remove_const.rb +39 -0
- data/lib/rubocop/cop/rspec/repeated_description.rb +98 -0
- data/lib/rubocop/cop/rspec/repeated_example.rb +53 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +100 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +96 -0
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +105 -0
- data/lib/rubocop/cop/rspec/repeated_subject_call.rb +125 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +169 -0
- data/lib/rubocop/cop/rspec/scattered_let.rb +59 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +92 -0
- data/lib/rubocop/cop/rspec/shared_context.rb +107 -0
- data/lib/rubocop/cop/rspec/shared_examples.rb +125 -0
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +93 -0
- data/lib/rubocop/cop/rspec/skip_block_inside_example.rb +46 -0
- data/lib/rubocop/cop/rspec/sort_metadata.rb +71 -0
- data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
- data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +176 -0
- data/lib/rubocop/cop/rspec/subject_declaration.rb +46 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +93 -74
- data/lib/rubocop/cop/rspec/undescriptive_literals_description.rb +69 -0
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +67 -0
- data/lib/rubocop/cop/rspec/variable_definition.rb +77 -0
- data/lib/rubocop/cop/rspec/variable_name.rb +68 -0
- data/lib/rubocop/cop/rspec/verified_double_reference.rb +111 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +28 -14
- data/lib/rubocop/cop/rspec/void_expect.rb +60 -0
- data/lib/rubocop/cop/rspec/yield.rb +82 -0
- data/lib/rubocop/cop/rspec_cops.rb +112 -0
- data/lib/rubocop/rspec/align_let_brace.rb +63 -0
- data/lib/rubocop/rspec/concept.rb +33 -0
- data/lib/rubocop/rspec/config_formatter.rb +27 -4
- data/lib/rubocop/rspec/cop/generator.rb +25 -0
- data/lib/rubocop/rspec/corrector/move_node.rb +51 -0
- data/lib/rubocop/rspec/description_extractor.rb +60 -18
- data/lib/rubocop/rspec/example.rb +37 -0
- data/lib/rubocop/rspec/example_group.rb +67 -0
- data/lib/rubocop/rspec/hook.rb +79 -0
- data/lib/rubocop/rspec/inject.rb +3 -1
- data/lib/rubocop/rspec/language.rb +184 -41
- data/lib/rubocop/rspec/node.rb +19 -0
- data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +29 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop/rspec/wording.rb +61 -19
- data/lib/rubocop/rspec.rb +6 -2
- data/lib/rubocop-rspec.rb +45 -34
- metadata +130 -195
- data/Gemfile +0 -13
- data/Rakefile +0 -48
- data/lib/rubocop/cop/rspec/file_path.rb +0 -83
- data/lib/rubocop/rspec/language/node_pattern.rb +0 -16
- data/lib/rubocop/rspec/spec_only.rb +0 -61
- data/lib/rubocop/rspec/top_level_describe.rb +0 -61
- data/lib/rubocop/rspec/util.rb +0 -19
- data/rubocop-rspec.gemspec +0 -42
- data/spec/expect_violation/expectation_spec.rb +0 -85
- data/spec/project/changelog_spec.rb +0 -81
- data/spec/project/default_config_spec.rb +0 -52
- data/spec/project/project_requires_spec.rb +0 -8
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -30
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -59
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -113
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -32
- data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -219
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -79
- data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -117
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -82
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -136
- data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -236
- data/spec/rubocop/cop/rspec/focus_spec.rb +0 -130
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -189
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -75
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -54
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -21
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -63
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -28
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -84
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -62
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -55
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -183
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -71
- data/spec/rubocop/rspec/config_formatter_spec.rb +0 -48
- data/spec/rubocop/rspec/description_extractor_spec.rb +0 -35
- data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -29
- data/spec/rubocop/rspec/spec_only_spec.rb +0 -97
- data/spec/rubocop/rspec/util/one_spec.rb +0 -21
- data/spec/rubocop/rspec/wording_spec.rb +0 -44
- data/spec/shared/rspec_only_cop_behavior.rb +0 -68
- data/spec/spec_helper.rb +0 -41
- data/spec/support/expect_violation.rb +0 -166
@@ -1,236 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::FilePath, :config do
|
2
|
-
subject(:cop) { described_class.new(config) }
|
3
|
-
|
4
|
-
shared_examples 'invalid spec path' do |source, expected:, actual:|
|
5
|
-
context "when `#{source}` is defined in #{actual}" do
|
6
|
-
before do
|
7
|
-
inspect_source(cop, source, actual)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'flags an offense' do
|
11
|
-
expect(cop.offenses.size).to eq(1)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'registers the offense on line 1' do
|
15
|
-
expect(cop.offenses.map(&:line)).to eq([1])
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'adds a message saying what the path should end with' do
|
19
|
-
expect(cop.messages).to eql(["Spec path should end with `#{expected}`"])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
include_examples 'invalid spec path',
|
25
|
-
"describe MyClass, 'foo' do; end",
|
26
|
-
expected: 'my_class*foo*_spec.rb',
|
27
|
-
actual: 'wrong_path_foo_spec.rb'
|
28
|
-
|
29
|
-
include_examples 'invalid spec path',
|
30
|
-
"describe MyClass, '#foo' do; end",
|
31
|
-
expected: 'my_class*foo*_spec.rb',
|
32
|
-
actual: 'wrong_class_foo_spec.rb'
|
33
|
-
|
34
|
-
include_examples 'invalid spec path',
|
35
|
-
"describe MyClass, '#foo' do; end",
|
36
|
-
expected: 'my_class*foo*_spec.rb',
|
37
|
-
actual: 'my_class/foo_spec.rb.rb'
|
38
|
-
|
39
|
-
include_examples 'invalid spec path',
|
40
|
-
"describe MyClass, '#foo' do; end",
|
41
|
-
expected: 'my_class*foo*_spec.rb',
|
42
|
-
actual: 'my_class/foo_specorb'
|
43
|
-
|
44
|
-
include_examples 'invalid spec path',
|
45
|
-
"describe MyClass, '#foo', blah: :blah do; end",
|
46
|
-
expected: 'my_class*foo*_spec.rb',
|
47
|
-
actual: 'wrong_class_foo_spec.rb'
|
48
|
-
|
49
|
-
include_examples 'invalid spec path',
|
50
|
-
'describe MyClass do; end',
|
51
|
-
expected: 'my_class*_spec.rb',
|
52
|
-
actual: 'wrong_class_spec.rb'
|
53
|
-
|
54
|
-
include_examples 'invalid spec path',
|
55
|
-
'describe MyClass, :foo do; end',
|
56
|
-
expected: 'my_class*_spec.rb',
|
57
|
-
actual: 'wrong_class_spec.rb'
|
58
|
-
|
59
|
-
it 'skips specs that do not describe a class / method' do
|
60
|
-
inspect_source(
|
61
|
-
cop,
|
62
|
-
"describe 'Test something' do; end",
|
63
|
-
'some/class/spec.rb'
|
64
|
-
)
|
65
|
-
expect(cop.offenses).to be_empty
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'skips specs that do have multiple top level describes' do
|
69
|
-
inspect_source(
|
70
|
-
cop,
|
71
|
-
[
|
72
|
-
"describe MyClass, 'do_this' do; end",
|
73
|
-
"describe MyClass, 'do_that' do; end"
|
74
|
-
],
|
75
|
-
'some/class/spec.rb'
|
76
|
-
)
|
77
|
-
expect(cop.offenses).to be_empty
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'checks class specs' do
|
81
|
-
inspect_source(
|
82
|
-
cop,
|
83
|
-
'describe Some::Class do; end',
|
84
|
-
'some/class_spec.rb'
|
85
|
-
)
|
86
|
-
expect(cop.offenses).to be_empty
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'handles CamelCaps class names' do
|
90
|
-
inspect_source(
|
91
|
-
cop,
|
92
|
-
'describe MyClass do; end',
|
93
|
-
'my_class_spec.rb'
|
94
|
-
)
|
95
|
-
expect(cop.offenses).to be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'handles ACRONYMClassNames' do
|
99
|
-
inspect_source(
|
100
|
-
cop,
|
101
|
-
'describe ABCOne::Two do; end',
|
102
|
-
'abc_one/two_spec.rb'
|
103
|
-
)
|
104
|
-
expect(cop.offenses).to be_empty
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'handles ALLCAPS class names' do
|
108
|
-
inspect_source(
|
109
|
-
cop,
|
110
|
-
'describe ALLCAPS do; end',
|
111
|
-
'allcaps_spec.rb'
|
112
|
-
)
|
113
|
-
expect(cop.offenses).to be_empty
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'handles alphanumeric class names' do
|
117
|
-
inspect_source(
|
118
|
-
cop,
|
119
|
-
'describe IPv4AndIPv6 do; end',
|
120
|
-
'i_pv4_and_i_pv6_spec.rb'
|
121
|
-
)
|
122
|
-
expect(cop.offenses).to be_empty
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'checks instance methods' do
|
126
|
-
inspect_source(
|
127
|
-
cop,
|
128
|
-
"describe Some::Class, '#inst' do; end",
|
129
|
-
'some/class/inst_spec.rb'
|
130
|
-
)
|
131
|
-
expect(cop.offenses).to be_empty
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'checks class methods' do
|
135
|
-
inspect_source(
|
136
|
-
cop,
|
137
|
-
"describe Some::Class, '.inst' do; end",
|
138
|
-
'some/class/inst_spec.rb'
|
139
|
-
)
|
140
|
-
expect(cop.offenses).to be_empty
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'allows flat hierarchies for instance methods' do
|
144
|
-
inspect_source(
|
145
|
-
cop,
|
146
|
-
"describe Some::Class, '#inst' do; end",
|
147
|
-
'some/class_inst_spec.rb'
|
148
|
-
)
|
149
|
-
expect(cop.offenses).to be_empty
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'allows flat hierarchies for class methods' do
|
153
|
-
inspect_source(
|
154
|
-
cop,
|
155
|
-
"describe Some::Class, '.inst' do; end",
|
156
|
-
'some/class_inst_spec.rb'
|
157
|
-
)
|
158
|
-
expect(cop.offenses).to be_empty
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'allows subdirs for instance methods' do
|
162
|
-
inspect_source(
|
163
|
-
cop,
|
164
|
-
"describe Some::Class, '#inst' do; end",
|
165
|
-
'some/class/instance_methods/inst_spec.rb'
|
166
|
-
)
|
167
|
-
expect(cop.offenses).to be_empty
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'allows subdirs for class methods' do
|
171
|
-
inspect_source(
|
172
|
-
cop,
|
173
|
-
"describe Some::Class, '.inst' do; end",
|
174
|
-
'some/class/class_methods/inst_spec.rb'
|
175
|
-
)
|
176
|
-
expect(cop.offenses).to be_empty
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'ignores non-alphanumeric characters' do
|
180
|
-
inspect_source(
|
181
|
-
cop,
|
182
|
-
"describe Some::Class, '#pred?' do; end",
|
183
|
-
'some/class/pred_spec.rb'
|
184
|
-
)
|
185
|
-
expect(cop.offenses).to be_empty
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'allows bang method' do
|
189
|
-
inspect_source(
|
190
|
-
cop,
|
191
|
-
"describe Some::Class, '#bang!' do; end",
|
192
|
-
'some/class/bang_spec.rb'
|
193
|
-
)
|
194
|
-
expect(cop.offenses).to be_empty
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'allows flexibility with predicates' do
|
198
|
-
inspect_source(
|
199
|
-
cop,
|
200
|
-
"describe Some::Class, '#thing?' do; end",
|
201
|
-
'some/class/thing_predicate_spec.rb'
|
202
|
-
)
|
203
|
-
expect(cop.offenses).to be_empty
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'allows flexibility with operators' do
|
207
|
-
inspect_source(
|
208
|
-
cop,
|
209
|
-
"describe MyLittleClass, '#<=>' do; end",
|
210
|
-
'my_little_class/spaceship_operator_spec.rb'
|
211
|
-
)
|
212
|
-
expect(cop.offenses).to be_empty
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'when configured' do
|
216
|
-
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
|
217
|
-
|
218
|
-
it 'respects custom module name transformation' do
|
219
|
-
inspect_source(
|
220
|
-
cop,
|
221
|
-
"describe FooFoo::Some::Class, '#bar' do; end",
|
222
|
-
'foofoo/some/class/bar_spec.rb'
|
223
|
-
)
|
224
|
-
expect(cop.offenses).to be_empty
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'ignores routing specs' do
|
228
|
-
inspect_source(
|
229
|
-
cop,
|
230
|
-
'describe MyController, "#foo", type: :routing do; end',
|
231
|
-
'foofoo/some/class/bar_spec.rb'
|
232
|
-
)
|
233
|
-
expect(cop.offenses).to be_empty
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::Focus do
|
2
|
-
subject(:cop) { described_class.new }
|
3
|
-
|
4
|
-
# rubocop:disable RSpec/ExampleLength
|
5
|
-
it 'flags all rspec example blocks with that include `focus: true`' do
|
6
|
-
expect_violation(<<-RUBY)
|
7
|
-
example 'test', meta: true, focus: true do; end
|
8
|
-
^^^^^^^^^^^ Focused spec found.
|
9
|
-
xit 'test', meta: true, focus: true do; end
|
10
|
-
^^^^^^^^^^^ Focused spec found.
|
11
|
-
describe 'test', meta: true, focus: true do; end
|
12
|
-
^^^^^^^^^^^ Focused spec found.
|
13
|
-
it 'test', meta: true, focus: true do; end
|
14
|
-
^^^^^^^^^^^ Focused spec found.
|
15
|
-
xspecify 'test', meta: true, focus: true do; end
|
16
|
-
^^^^^^^^^^^ Focused spec found.
|
17
|
-
specify 'test', meta: true, focus: true do; end
|
18
|
-
^^^^^^^^^^^ Focused spec found.
|
19
|
-
example_group 'test', meta: true, focus: true do; end
|
20
|
-
^^^^^^^^^^^ Focused spec found.
|
21
|
-
scenario 'test', meta: true, focus: true do; end
|
22
|
-
^^^^^^^^^^^ Focused spec found.
|
23
|
-
xexample 'test', meta: true, focus: true do; end
|
24
|
-
^^^^^^^^^^^ Focused spec found.
|
25
|
-
xdescribe 'test', meta: true, focus: true do; end
|
26
|
-
^^^^^^^^^^^ Focused spec found.
|
27
|
-
context 'test', meta: true, focus: true do; end
|
28
|
-
^^^^^^^^^^^ Focused spec found.
|
29
|
-
xcontext 'test', meta: true, focus: true do; end
|
30
|
-
^^^^^^^^^^^ Focused spec found.
|
31
|
-
feature 'test', meta: true, focus: true do; end
|
32
|
-
^^^^^^^^^^^ Focused spec found.
|
33
|
-
xfeature 'test', meta: true, focus: true do; end
|
34
|
-
^^^^^^^^^^^ Focused spec found.
|
35
|
-
xscenario 'test', meta: true, focus: true do; end
|
36
|
-
^^^^^^^^^^^ Focused spec found.
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'flags all rspec example blocks that include `:focus`' do
|
41
|
-
expect_violation(<<-RUBY)
|
42
|
-
example_group 'test', :focus do; end
|
43
|
-
^^^^^^ Focused spec found.
|
44
|
-
feature 'test', :focus do; end
|
45
|
-
^^^^^^ Focused spec found.
|
46
|
-
xexample 'test', :focus do; end
|
47
|
-
^^^^^^ Focused spec found.
|
48
|
-
xdescribe 'test', :focus do; end
|
49
|
-
^^^^^^ Focused spec found.
|
50
|
-
xscenario 'test', :focus do; end
|
51
|
-
^^^^^^ Focused spec found.
|
52
|
-
specify 'test', :focus do; end
|
53
|
-
^^^^^^ Focused spec found.
|
54
|
-
example 'test', :focus do; end
|
55
|
-
^^^^^^ Focused spec found.
|
56
|
-
xfeature 'test', :focus do; end
|
57
|
-
^^^^^^ Focused spec found.
|
58
|
-
xspecify 'test', :focus do; end
|
59
|
-
^^^^^^ Focused spec found.
|
60
|
-
scenario 'test', :focus do; end
|
61
|
-
^^^^^^ Focused spec found.
|
62
|
-
describe 'test', :focus do; end
|
63
|
-
^^^^^^ Focused spec found.
|
64
|
-
xit 'test', :focus do; end
|
65
|
-
^^^^^^ Focused spec found.
|
66
|
-
context 'test', :focus do; end
|
67
|
-
^^^^^^ Focused spec found.
|
68
|
-
xcontext 'test', :focus do; end
|
69
|
-
^^^^^^ Focused spec found.
|
70
|
-
it 'test', :focus do; end
|
71
|
-
^^^^^^ Focused spec found.
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'does not flag unfocused specs' do
|
76
|
-
expect_no_violations(<<-RUBY)
|
77
|
-
xcontext 'test' do; end
|
78
|
-
xscenario 'test' do; end
|
79
|
-
xspecify 'test' do; end
|
80
|
-
describe 'test' do; end
|
81
|
-
example 'test' do; end
|
82
|
-
xexample 'test' do; end
|
83
|
-
scenario 'test' do; end
|
84
|
-
specify 'test' do; end
|
85
|
-
xit 'test' do; end
|
86
|
-
feature 'test' do; end
|
87
|
-
xfeature 'test' do; end
|
88
|
-
context 'test' do; end
|
89
|
-
it 'test' do; end
|
90
|
-
example_group 'test' do; end
|
91
|
-
xdescribe 'test' do; end
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'does not flag a method that is focused twice' do
|
96
|
-
expect_violation(<<-RUBY)
|
97
|
-
fit "foo", :focus do
|
98
|
-
^^^^^^^^^^^^^^^^^ Focused spec found.
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'ignores non-rspec code with :focus blocks' do
|
104
|
-
expect_no_violations(<<-RUBY)
|
105
|
-
some_method "foo", focus: true do
|
106
|
-
end
|
107
|
-
RUBY
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'flags focused block types' do
|
111
|
-
expect_violation(<<-RUBY)
|
112
|
-
fdescribe 'test' do; end
|
113
|
-
^^^^^^^^^^^^^^^^ Focused spec found.
|
114
|
-
ffeature 'test' do; end
|
115
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
116
|
-
fcontext 'test' do; end
|
117
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
118
|
-
fit 'test' do; end
|
119
|
-
^^^^^^^^^^ Focused spec found.
|
120
|
-
fscenario 'test' do; end
|
121
|
-
^^^^^^^^^^^^^^^^ Focused spec found.
|
122
|
-
fexample 'test' do; end
|
123
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
124
|
-
fspecify 'test' do; end
|
125
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
126
|
-
focus 'test' do; end
|
127
|
-
^^^^^^^^^^^^ Focused spec found.
|
128
|
-
RUBY
|
129
|
-
end
|
130
|
-
end
|
@@ -1,189 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe RuboCop::Cop::RSpec::HookArgument, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style }
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:enforced_style) { :implicit }
|
11
|
-
|
12
|
-
shared_examples 'ignored hooks' do
|
13
|
-
it 'ignores :context and :suite' do
|
14
|
-
expect_no_violations(<<-RUBY)
|
15
|
-
before(:suite) { true }
|
16
|
-
after(:suite) { true }
|
17
|
-
before(:context) { true }
|
18
|
-
after(:context) { true }
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'ignores hooks with more than one argument' do
|
23
|
-
expect_no_violations(<<-RUBY)
|
24
|
-
before(:each, :something_custom) { true }
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'ignores non-rspec hooks' do
|
29
|
-
expect_no_violations(<<-RUBY)
|
30
|
-
setup(:each) { true }
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
shared_examples 'generated config' do |source, detected_style|
|
36
|
-
it 'generates a todo based on the detected style' do
|
37
|
-
inspect_source(cop, source, 'foo_spec.rb')
|
38
|
-
|
39
|
-
expect(cop.config_to_allow_offenses)
|
40
|
-
.to eq('EnforcedStyle' => detected_style)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
shared_examples 'hook autocorrect' do |output|
|
45
|
-
it 'autocorrects :each to EnforcedStyle' do
|
46
|
-
corrected =
|
47
|
-
autocorrect_source(cop, 'before(:each) { }', 'spec/foo_spec.rb')
|
48
|
-
|
49
|
-
expect(corrected).to eql(output)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'autocorrects :example to EnforcedStyle' do
|
53
|
-
corrected =
|
54
|
-
autocorrect_source(cop, 'before(:example) { }', 'spec/foo_spec.rb')
|
55
|
-
|
56
|
-
expect(corrected).to eql(output)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'autocorrects :implicit to EnforcedStyle' do
|
60
|
-
corrected =
|
61
|
-
autocorrect_source(cop, 'before { }', 'spec/foo_spec.rb')
|
62
|
-
|
63
|
-
expect(corrected).to eql(output)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
shared_examples 'an example hook' do
|
68
|
-
include_examples 'ignored hooks'
|
69
|
-
include_examples 'generated config', 'before(:each) { foo }', 'each'
|
70
|
-
include_examples 'generated config', 'before(:example) { foo }', 'example'
|
71
|
-
include_examples 'generated config', 'before { foo }', 'implicit'
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when EnforcedStyle is :implicit' do
|
75
|
-
let(:enforced_style) { :implicit }
|
76
|
-
|
77
|
-
it 'detects :each for hooks' do
|
78
|
-
expect_violation(<<-RUBY)
|
79
|
-
before(:each) { true }
|
80
|
-
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
81
|
-
after(:each) { true }
|
82
|
-
^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
83
|
-
around(:each) { true }
|
84
|
-
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
85
|
-
RUBY
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'detects :example for hooks' do
|
89
|
-
expect_violation(<<-RUBY)
|
90
|
-
before(:example) { true }
|
91
|
-
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
92
|
-
after(:example) { true }
|
93
|
-
^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
94
|
-
around(:example) { true }
|
95
|
-
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
96
|
-
RUBY
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'does not flag hooks without default scopes' do
|
100
|
-
expect_no_violations(<<-RUBY)
|
101
|
-
before { true }
|
102
|
-
after { true }
|
103
|
-
before { true }
|
104
|
-
after { true }
|
105
|
-
RUBY
|
106
|
-
end
|
107
|
-
|
108
|
-
include_examples 'an example hook'
|
109
|
-
include_examples 'hook autocorrect', 'before { }'
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'when EnforcedStyle is :each' do
|
113
|
-
let(:enforced_style) { :each }
|
114
|
-
|
115
|
-
it 'detects :each for hooks' do
|
116
|
-
expect_no_violations(<<-RUBY)
|
117
|
-
before(:each) { true }
|
118
|
-
after(:each) { true }
|
119
|
-
around(:each) { true }
|
120
|
-
RUBY
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'detects :example for hooks' do
|
124
|
-
expect_violation(<<-RUBY)
|
125
|
-
before(:example) { true }
|
126
|
-
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
127
|
-
after(:example) { true }
|
128
|
-
^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
129
|
-
around(:example) { true }
|
130
|
-
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'does not flag hooks without default scopes' do
|
135
|
-
expect_violation(<<-RUBY)
|
136
|
-
before { true }
|
137
|
-
^^^^^^ Use `:each` for RSpec hooks.
|
138
|
-
after { true }
|
139
|
-
^^^^^ Use `:each` for RSpec hooks.
|
140
|
-
before { true }
|
141
|
-
^^^^^^ Use `:each` for RSpec hooks.
|
142
|
-
after { true }
|
143
|
-
^^^^^ Use `:each` for RSpec hooks.
|
144
|
-
RUBY
|
145
|
-
end
|
146
|
-
|
147
|
-
include_examples 'an example hook'
|
148
|
-
include_examples 'hook autocorrect', 'before(:each) { }'
|
149
|
-
end
|
150
|
-
|
151
|
-
context 'when EnforcedStyle is :example' do
|
152
|
-
let(:enforced_style) { :example }
|
153
|
-
|
154
|
-
it 'detects :example for hooks' do
|
155
|
-
expect_no_violations(<<-RUBY)
|
156
|
-
before(:example) { true }
|
157
|
-
after(:example) { true }
|
158
|
-
around(:example) { true }
|
159
|
-
RUBY
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'detects :each for hooks' do
|
163
|
-
expect_violation(<<-RUBY)
|
164
|
-
before(:each) { true }
|
165
|
-
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
166
|
-
after(:each) { true }
|
167
|
-
^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
168
|
-
around(:each) { true }
|
169
|
-
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
170
|
-
RUBY
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'does not flag hooks without default scopes' do
|
174
|
-
expect_violation(<<-RUBY)
|
175
|
-
before { true }
|
176
|
-
^^^^^^ Use `:example` for RSpec hooks.
|
177
|
-
after { true }
|
178
|
-
^^^^^ Use `:example` for RSpec hooks.
|
179
|
-
before { true }
|
180
|
-
^^^^^^ Use `:example` for RSpec hooks.
|
181
|
-
after { true }
|
182
|
-
^^^^^ Use `:example` for RSpec hooks.
|
183
|
-
RUBY
|
184
|
-
end
|
185
|
-
|
186
|
-
include_examples 'an example hook'
|
187
|
-
include_examples 'hook autocorrect', 'before(:example) { }'
|
188
|
-
end
|
189
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
describe RuboCop::Cop::RSpec::InstanceVariable do
|
2
|
-
subject(:cop) { described_class.new }
|
3
|
-
|
4
|
-
it 'finds an instance variable inside a describe' do
|
5
|
-
expect_violation(<<-RUBY)
|
6
|
-
describe MyClass do
|
7
|
-
before { @foo = [] }
|
8
|
-
it { expect(@foo).to be_empty }
|
9
|
-
^^^^ Use `let` instead of an instance variable
|
10
|
-
end
|
11
|
-
RUBY
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'ignores non-spec blocks' do
|
15
|
-
expect_no_violations(<<-RUBY)
|
16
|
-
not_rspec do
|
17
|
-
before { @foo = [] }
|
18
|
-
it { expect(@foo).to be_empty }
|
19
|
-
end
|
20
|
-
RUBY
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'finds an instance variable inside a shared example' do
|
24
|
-
expect_violation(<<-RUBY)
|
25
|
-
shared_examples 'shared example' do
|
26
|
-
it { expect(@foo).to be_empty }
|
27
|
-
^^^^ Use `let` instead of an instance variable
|
28
|
-
end
|
29
|
-
RUBY
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'ignores an instance variable without describe' do
|
33
|
-
expect_no_violations(<<-RUBY)
|
34
|
-
@foo = []
|
35
|
-
@foo.empty?
|
36
|
-
RUBY
|
37
|
-
end
|
38
|
-
|
39
|
-
# Regression test for nevir/rubocop-rspec#115
|
40
|
-
it 'ignores instance variables outside of specs' do
|
41
|
-
expect_no_violations(<<-RUBY, filename: 'lib/source_code.rb')
|
42
|
-
feature do
|
43
|
-
@foo = bar
|
44
|
-
|
45
|
-
@foo
|
46
|
-
end
|
47
|
-
RUBY
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when configured with AssignmentOnly', :config do
|
51
|
-
subject(:cop) { described_class.new(config) }
|
52
|
-
|
53
|
-
let(:cop_config) do
|
54
|
-
{ 'AssignmentOnly' => true }
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'flags an instance variable when it is also assigned' do
|
58
|
-
expect_violation(<<-RUBY)
|
59
|
-
describe MyClass do
|
60
|
-
before { @foo = [] }
|
61
|
-
it { expect(@foo).to be_empty }
|
62
|
-
^^^^ Use `let` instead of an instance variable
|
63
|
-
end
|
64
|
-
RUBY
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'ignores an instance variable when it is not assigned' do
|
68
|
-
expect_no_violations(<<-RUBY)
|
69
|
-
describe MyClass do
|
70
|
-
it { expect(@foo).to be_empty }
|
71
|
-
end
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'checks subject below let' do
|
7
|
-
expect_violation(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
let(:params) { foo }
|
10
|
-
|
11
|
-
subject { described_class.new }
|
12
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations
|
13
|
-
end
|
14
|
-
RUBY
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'approves of subject above let' do
|
18
|
-
expect_no_violations(<<-RUBY)
|
19
|
-
RSpec.describe User do
|
20
|
-
context 'blah' do
|
21
|
-
end
|
22
|
-
|
23
|
-
subject { described_class.new }
|
24
|
-
|
25
|
-
let(:params) { foo }
|
26
|
-
end
|
27
|
-
RUBY
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'handles subjects in contexts' do
|
31
|
-
expect_no_violations(<<-RUBY)
|
32
|
-
RSpec.describe User do
|
33
|
-
let(:params) { foo }
|
34
|
-
|
35
|
-
context "when something happens" do
|
36
|
-
subject { described_class.new }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
RUBY
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'handles subjects in tests' do
|
43
|
-
expect_no_violations(<<-RUBY)
|
44
|
-
RSpec.describe User do
|
45
|
-
# This shouldn't really ever happen in a sane codebase but I still
|
46
|
-
# want to avoid false positives
|
47
|
-
it "doesn't mind me calling a method called subject in the test" do
|
48
|
-
let(foo)
|
49
|
-
subject { bar }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
end
|