rubocop-rspec 1.35.0 → 1.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/config/default.yml +11 -0
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +16 -0
- data/lib/rubocop/cop/rspec/context_method.rb +53 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +7 -10
- data/lib/rubocop/cop/rspec/described_class.rb +29 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +87 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +28 -12
- data/lib/rubocop/cop/rspec/expect_change.rb +8 -8
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +2 -9
- data/lib/rubocop/cop/rspec/focus.rb +5 -10
- data/lib/rubocop/cop/rspec/instance_variable.rb +2 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +13 -21
- data/lib/rubocop/cop/rspec/pending.rb +19 -25
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +7 -198
- data/Gemfile +0 -11
- data/Rakefile +0 -87
- data/rubocop-rspec.gemspec +0 -49
- data/spec/project/changelog_spec.rb +0 -76
- data/spec/project/default_config_spec.rb +0 -76
- data/spec/project/project_requires_spec.rb +0 -20
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +0 -51
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +0 -51
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -32
- data/spec/rubocop/cop/rspec/around_block_spec.rb +0 -121
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -81
- data/spec/rubocop/cop/rspec/be_spec.rb +0 -35
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +0 -52
- data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +0 -65
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +0 -130
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +0 -94
- data/spec/rubocop/cop/rspec/cop_spec.rb +0 -95
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -168
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -34
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +0 -44
- data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -352
- data/spec/rubocop/cop/rspec/dialect_spec.rb +0 -78
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -93
- data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +0 -121
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +0 -239
- data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +0 -133
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +0 -94
- data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -78
- data/spec/rubocop/cop/rspec/example_without_description_spec.rb +0 -92
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -173
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -150
- data/spec/rubocop/cop/rspec/expect_change_spec.rb +0 -86
- data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +0 -79
- data/spec/rubocop/cop/rspec/expect_output_spec.rb +0 -62
- data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +0 -208
- data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +0 -171
- data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -200
- data/spec/rubocop/cop/rspec/focus_spec.rb +0 -139
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -173
- data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +0 -150
- data/spec/rubocop/cop/rspec/implicit_block_expectation_spec.rb +0 -135
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +0 -102
- data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +0 -188
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +0 -61
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -95
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +0 -39
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +0 -47
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +0 -82
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -119
- data/spec/rubocop/cop/rspec/leaky_constant_declaration_spec.rb +0 -91
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +0 -137
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -23
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -45
- data/spec/rubocop/cop/rspec/message_spies_spec.rb +0 -151
- data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -30
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -261
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +0 -83
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -123
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -81
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -77
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +0 -91
- data/spec/rubocop/cop/rspec/pending_spec.rb +0 -186
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +0 -354
- data/spec/rubocop/cop/rspec/rails/http_status_spec.rb +0 -90
- data/spec/rubocop/cop/rspec/receive_counts_spec.rb +0 -138
- data/spec/rubocop/cop/rspec/receive_never_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/repeated_description_spec.rb +0 -76
- data/spec/rubocop/cop/rspec/repeated_example_spec.rb +0 -74
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +0 -289
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +0 -28
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +0 -98
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +0 -137
- data/spec/rubocop/cop/rspec/shared_examples_spec.rb +0 -75
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +0 -178
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -293
- data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +0 -177
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -86
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +0 -49
- data/spec/rubocop/cop/rspec/yield_spec.rb +0 -81
- data/spec/rubocop/rspec/config_formatter_spec.rb +0 -52
- data/spec/rubocop/rspec/description_extractor_spec.rb +0 -63
- data/spec/rubocop/rspec/example_group_spec.rb +0 -44
- data/spec/rubocop/rspec/example_spec.rb +0 -62
- data/spec/rubocop/rspec/hook_spec.rb +0 -53
- data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -53
- data/spec/rubocop/rspec/util/one_spec.rb +0 -23
- data/spec/rubocop/rspec/wording_spec.rb +0 -52
- data/spec/shared/autocorrect_behavior.rb +0 -9
- data/spec/shared/detects_style_behavior.rb +0 -9
- data/spec/shared/smoke_test_examples.rb +0 -27
- data/spec/smoke_tests/empty_spec.rb +0 -0
- data/spec/smoke_tests/factory_bot_spec.rb +0 -11
- data/spec/smoke_tests/no_tests_spec.rb +0 -4
- data/spec/smoke_tests/weird_rspec_spec.rb +0 -233
- data/spec/spec_helper.rb +0 -42
- data/spec/support/expect_offense.rb +0 -19
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
context 'when EnforcedStyle is is_expected' do
|
7
|
-
let(:cop_config) do
|
8
|
-
{ 'EnforcedStyle' => 'is_expected' }
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'flags it { should }' do
|
12
|
-
expect_offense(<<-RUBY)
|
13
|
-
it { should be_truthy }
|
14
|
-
^^^^^^ Prefer `is_expected.to` over `should`.
|
15
|
-
RUBY
|
16
|
-
|
17
|
-
expect_correction(<<-RUBY)
|
18
|
-
it { is_expected.to be_truthy }
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'flags it { should_not }' do
|
23
|
-
expect_offense(<<-RUBY)
|
24
|
-
it { should_not be_truthy }
|
25
|
-
^^^^^^^^^^ Prefer `is_expected.to_not` over `should_not`.
|
26
|
-
RUBY
|
27
|
-
|
28
|
-
expect_correction(<<-RUBY)
|
29
|
-
it { is_expected.to_not be_truthy }
|
30
|
-
RUBY
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'approves of is_expected.to' do
|
34
|
-
expect_no_offenses('it { is_expected.to be_truthy }')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'approves of is_expected.to_not' do
|
38
|
-
expect_no_offenses('it { is_expected.to_not be_truthy }')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'approves of is_expected.not_to' do
|
42
|
-
expect_no_offenses('it { is_expected.not_to be_truthy }')
|
43
|
-
end
|
44
|
-
|
45
|
-
include_examples 'detects style', 'it { should be_truthy }', 'should'
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when EnforcedStyle is should' do
|
49
|
-
let(:cop_config) do
|
50
|
-
{ 'EnforcedStyle' => 'should' }
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'flags it { is_expected.to }' do
|
54
|
-
expect_offense(<<-RUBY)
|
55
|
-
it { is_expected.to be_truthy }
|
56
|
-
^^^^^^^^^^^^^^ Prefer `should` over `is_expected.to`.
|
57
|
-
RUBY
|
58
|
-
|
59
|
-
expect_correction(<<-RUBY)
|
60
|
-
it { should be_truthy }
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'flags it { is_expected.to_not }' do
|
65
|
-
expect_offense(<<-RUBY)
|
66
|
-
it { is_expected.to_not be_truthy }
|
67
|
-
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.to_not`.
|
68
|
-
RUBY
|
69
|
-
|
70
|
-
expect_correction(<<-RUBY)
|
71
|
-
it { should_not be_truthy }
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'flags it { is_expected.not_to }' do
|
76
|
-
expect_offense(<<-RUBY)
|
77
|
-
it { is_expected.not_to be_truthy }
|
78
|
-
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.not_to`.
|
79
|
-
RUBY
|
80
|
-
|
81
|
-
expect_correction(<<-RUBY)
|
82
|
-
it { should_not be_truthy }
|
83
|
-
RUBY
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'approves of should' do
|
87
|
-
expect_no_offenses('it { should be_truthy }')
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'approves of should_not' do
|
91
|
-
expect_no_offenses('it { should_not be_truthy }')
|
92
|
-
end
|
93
|
-
|
94
|
-
include_examples 'detects style',
|
95
|
-
'it { is_expected.to be_truthy }',
|
96
|
-
'is_expected'
|
97
|
-
|
98
|
-
include_examples 'detects style',
|
99
|
-
'it { should be_truthy }',
|
100
|
-
'should'
|
101
|
-
end
|
102
|
-
end
|
@@ -1,188 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ImplicitSubject, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style }
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'with EnforcedStyle `single_line_only`' do
|
11
|
-
let(:enforced_style) { 'single_line_only' }
|
12
|
-
|
13
|
-
it 'flags `is_expected` in multi-line examples' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
it 'expect subject to be used' do
|
16
|
-
is_expected.to be_good
|
17
|
-
^^^^^^^^^^^ Don't use implicit subject.
|
18
|
-
end
|
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
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'allows `is_expected` inside `its` block, in multi-line examples' do
|
29
|
-
expect_no_offenses(<<-RUBY)
|
30
|
-
its(:quality) do
|
31
|
-
is_expected.to be :high
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'flags `should` in multi-line examples' do
|
37
|
-
expect_offense(<<-RUBY)
|
38
|
-
it 'expect subject to be used' do
|
39
|
-
should be_good
|
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
|
50
|
-
end
|
51
|
-
RUBY
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'allows `is_expected` in single-line examples' do
|
55
|
-
expect_no_offenses(<<-RUBY)
|
56
|
-
it { is_expected.to be_good }
|
57
|
-
RUBY
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'allows `should` in single-line examples' do
|
61
|
-
expect_no_offenses(<<-RUBY)
|
62
|
-
it { should be_good }
|
63
|
-
RUBY
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'does not flag methods called is_expected and should' do
|
67
|
-
expect_no_offenses(<<-RUBY)
|
68
|
-
it 'uses some similar sounding methods' do
|
69
|
-
expect(baz).to receive(:is_expected)
|
70
|
-
baz.is_expected
|
71
|
-
foo.should(deny_access)
|
72
|
-
end
|
73
|
-
RUBY
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'detects usage of `is_expected` inside helper methods' do
|
77
|
-
expect_offense(<<-RUBY)
|
78
|
-
def permits(actions)
|
79
|
-
actions.each { |action| is_expected.to permit_action(action) }
|
80
|
-
^^^^^^^^^^^ Don't use implicit subject.
|
81
|
-
end
|
82
|
-
RUBY
|
83
|
-
|
84
|
-
expect_correction(<<-RUBY)
|
85
|
-
def permits(actions)
|
86
|
-
actions.each { |action| expect(subject).to permit_action(action) }
|
87
|
-
end
|
88
|
-
RUBY
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'with EnforcedStyle `single_statement_only`' do
|
93
|
-
let(:enforced_style) { 'single_statement_only' }
|
94
|
-
|
95
|
-
it 'allows `is_expected` in multi-line example with single statement' do
|
96
|
-
expect_no_offenses(<<-RUBY)
|
97
|
-
it 'expect subject to be used' do
|
98
|
-
is_expected.to be_good
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'flags `is_expected` in multi-statement examples' do
|
104
|
-
expect_offense(<<-RUBY)
|
105
|
-
it 'expect subject to be used' do
|
106
|
-
subject.age = 18
|
107
|
-
is_expected.to be_valid
|
108
|
-
^^^^^^^^^^^ Don't use implicit subject.
|
109
|
-
end
|
110
|
-
RUBY
|
111
|
-
|
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
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'with EnforcedStyle `disallow`' do
|
122
|
-
let(:enforced_style) { 'disallow' }
|
123
|
-
|
124
|
-
it 'flags `is_expected` in multi-line examples' do
|
125
|
-
expect_offense(<<-RUBY)
|
126
|
-
it 'expect subject to be used' do
|
127
|
-
is_expected.to be_good
|
128
|
-
^^^^^^^^^^^ Don't use implicit subject.
|
129
|
-
end
|
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
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'flags `is_expected` in single-line examples' do
|
140
|
-
expect_offense(<<-RUBY)
|
141
|
-
it { is_expected.to be_good }
|
142
|
-
^^^^^^^^^^^ Don't use implicit subject.
|
143
|
-
RUBY
|
144
|
-
|
145
|
-
expect_correction(<<-RUBY)
|
146
|
-
it { expect(subject).to be_good }
|
147
|
-
RUBY
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'flags `should` in multi-line examples' do
|
151
|
-
expect_offense(<<-RUBY)
|
152
|
-
it 'expect subject to be used' do
|
153
|
-
should be_good
|
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
|
164
|
-
end
|
165
|
-
RUBY
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'flags `should` in single-line examples' do
|
169
|
-
expect_offense(<<-RUBY)
|
170
|
-
it { should be_good }
|
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
|
-
RUBY
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'allows `is_expected` inside `its` block' do
|
183
|
-
expect_no_offenses(<<-RUBY)
|
184
|
-
its(:quality) { is_expected.to be :high }
|
185
|
-
RUBY
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
context 'when used with `have_received`' do
|
7
|
-
it 'adds an offense for an instance_double with single argument' do
|
8
|
-
expect_offense(<<-RUBY)
|
9
|
-
it do
|
10
|
-
foo = instance_double(Foo).as_null_object
|
11
|
-
^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`.
|
12
|
-
expect(foo).to have_received(:bar)
|
13
|
-
end
|
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
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'adds an offense for an instance_double with multiple arguments' do
|
25
|
-
expect_offense(<<-RUBY)
|
26
|
-
it do
|
27
|
-
foo = instance_double(Foo, :name).as_null_object
|
28
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`.
|
29
|
-
expect(foo).to have_received(:bar)
|
30
|
-
end
|
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
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'ignores instance_double when it is not used with as_null_object' do
|
42
|
-
expect_no_offenses(<<-RUBY)
|
43
|
-
it do
|
44
|
-
foo = instance_double(Foo)
|
45
|
-
expect(bar).to have_received(:bar)
|
46
|
-
end
|
47
|
-
RUBY
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when not used with `have_received`' do
|
52
|
-
it 'does not add an offence' do
|
53
|
-
expect_no_offenses(<<-RUBY)
|
54
|
-
it do
|
55
|
-
foo = instance_double(Foo).as_null_object
|
56
|
-
expect(bar).to have_received(:bar)
|
57
|
-
end
|
58
|
-
RUBY
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'finds an instance variable inside a describe' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe MyClass do
|
9
|
-
before { @foo = [] }
|
10
|
-
it { expect(@foo).to be_empty }
|
11
|
-
^^^^ Replace instance variable with local variable or `let`.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'ignores non-spec blocks' do
|
17
|
-
expect_no_offenses(<<-RUBY)
|
18
|
-
not_rspec do
|
19
|
-
before { @foo = [] }
|
20
|
-
it { expect(@foo).to be_empty }
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'finds an instance variable inside a shared example' do
|
26
|
-
expect_offense(<<-RUBY)
|
27
|
-
shared_examples 'shared example' do
|
28
|
-
it { expect(@foo).to be_empty }
|
29
|
-
^^^^ Replace instance variable with local variable or `let`.
|
30
|
-
end
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'ignores an instance variable without describe' do
|
35
|
-
expect_no_offenses(<<-RUBY)
|
36
|
-
@foo = []
|
37
|
-
@foo.empty?
|
38
|
-
RUBY
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'ignores an instance variable inside a dynamic class' do
|
42
|
-
expect_no_offenses(<<-RUBY)
|
43
|
-
describe MyClass do
|
44
|
-
let(:object) do
|
45
|
-
Class.new(OtherClass) do
|
46
|
-
def initialize(resource)
|
47
|
-
@resource = resource
|
48
|
-
end
|
49
|
-
|
50
|
-
def serialize
|
51
|
-
@resource.to_json
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
RUBY
|
57
|
-
end
|
58
|
-
|
59
|
-
# Regression test for nevir/rubocop-rspec#115
|
60
|
-
it 'ignores instance variables outside of specs' do
|
61
|
-
expect_no_offenses(<<-RUBY, 'lib/source_code.rb')
|
62
|
-
feature do
|
63
|
-
@foo = bar
|
64
|
-
|
65
|
-
@foo
|
66
|
-
end
|
67
|
-
RUBY
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when configured with AssignmentOnly', :config do
|
71
|
-
subject(:cop) { described_class.new(config) }
|
72
|
-
|
73
|
-
let(:cop_config) do
|
74
|
-
{ 'AssignmentOnly' => true }
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'flags an instance variable when it is also assigned' do
|
78
|
-
expect_offense(<<-RUBY)
|
79
|
-
describe MyClass do
|
80
|
-
before { @foo = [] }
|
81
|
-
it { expect(@foo).to be_empty }
|
82
|
-
^^^^ Replace instance variable with local variable or `let`.
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'ignores an instance variable when it is not assigned' do
|
88
|
-
expect_no_offenses(<<-RUBY)
|
89
|
-
describe MyClass do
|
90
|
-
it { expect(@foo).to be_empty }
|
91
|
-
end
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::InvalidPredicateMatcher do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'registers an offense for double question' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
expect(foo).to be_something?
|
9
|
-
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
10
|
-
RUBY
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'registers an offense for double question with `not_to`' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
expect(foo).not_to be_something?
|
16
|
-
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'registers an offense for double question with `to_not`' do
|
21
|
-
expect_offense(<<-RUBY)
|
22
|
-
expect(foo).to_not be_something?
|
23
|
-
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
24
|
-
RUBY
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'registers an offense for double question with `have_something?`' do
|
28
|
-
expect_offense(<<-RUBY)
|
29
|
-
expect(foo).to have_something?
|
30
|
-
^^^^^^^^^^^^^^^ Omit `?` from `have_something?`.
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'accepts valid predicate matcher' do
|
35
|
-
expect_no_offenses(<<-RUBY)
|
36
|
-
expect(foo).to be_something
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
end
|