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,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::MultipleSubjects do
|
4
|
-
let(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'registers an offense for every overwritten subject' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe 'hello there' do
|
9
|
-
subject(:foo) { 1 }
|
10
|
-
^^^^^^^^^^^^^^^^^^^ Do not set more than one subject per example group
|
11
|
-
subject(:bar) { 2 }
|
12
|
-
^^^^^^^^^^^^^^^^^^^ Do not set more than one subject per example group
|
13
|
-
subject { 3 }
|
14
|
-
^^^^^^^^^^^^^ Do not set more than one subject per example group
|
15
|
-
subject(:baz) { 4 }
|
16
|
-
|
17
|
-
describe 'baz' do
|
18
|
-
subject(:norf) { 1 }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
|
23
|
-
expect_correction(<<-RUBY)
|
24
|
-
describe 'hello there' do
|
25
|
-
let(:foo) { 1 }
|
26
|
-
let(:bar) { 2 }
|
27
|
-
subject(:baz) { 4 }
|
28
|
-
|
29
|
-
describe 'baz' do
|
30
|
-
subject(:norf) { 1 }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'does not try to autocorrect subject!' do
|
37
|
-
source = <<-RUBY
|
38
|
-
describe Foo do
|
39
|
-
subject! { a }
|
40
|
-
^^^^^^^^^^^^^^ Do not set more than one subject per example group
|
41
|
-
subject! { b }
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
|
45
|
-
expect_offense(source)
|
46
|
-
expect_no_corrections
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'does not flag shared example groups' do
|
50
|
-
expect_no_offenses(<<-RUBY)
|
51
|
-
describe Foo do
|
52
|
-
it_behaves_like 'user' do
|
53
|
-
subject { described_class.new(user, described_class) }
|
54
|
-
|
55
|
-
it { expect(subject).not_to be_accessible }
|
56
|
-
end
|
57
|
-
|
58
|
-
it_behaves_like 'admin' do
|
59
|
-
subject { described_class.new(user, described_class) }
|
60
|
-
|
61
|
-
it { expect(subject).to be_accessible }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
RUBY
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'autocorrects' do
|
68
|
-
expect_offense(<<-RUBY)
|
69
|
-
describe 'hello there' do
|
70
|
-
subject { 1 }
|
71
|
-
^^^^^^^^^^^^^ Do not set more than one subject per example group
|
72
|
-
subject { 2 }
|
73
|
-
^^^^^^^^^^^^^ Do not set more than one subject per example group
|
74
|
-
subject { 3 }
|
75
|
-
end
|
76
|
-
RUBY
|
77
|
-
expect_correction(<<-RUBY)
|
78
|
-
describe 'hello there' do
|
79
|
-
subject { 3 }
|
80
|
-
end
|
81
|
-
RUBY
|
82
|
-
end
|
83
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::NamedSubject, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
shared_examples_for 'checking subject outside of shared examples' do
|
7
|
-
it 'checks `it` and `specify` for explicit subject usage' do
|
8
|
-
expect_offense(<<-RUBY)
|
9
|
-
RSpec.describe User do
|
10
|
-
subject { described_class.new }
|
11
|
-
|
12
|
-
it "is valid" do
|
13
|
-
expect(subject.valid?).to be(true)
|
14
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
15
|
-
end
|
16
|
-
|
17
|
-
specify do
|
18
|
-
expect(subject.valid?).to be(true)
|
19
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
20
|
-
end
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'checks before and after for explicit subject usage' do
|
26
|
-
expect_offense(<<-RUBY)
|
27
|
-
RSpec.describe User do
|
28
|
-
subject { described_class.new }
|
29
|
-
|
30
|
-
before(:each) do
|
31
|
-
do_something_with(subject)
|
32
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
33
|
-
end
|
34
|
-
|
35
|
-
after do
|
36
|
-
do_something_with(subject)
|
37
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
38
|
-
end
|
39
|
-
end
|
40
|
-
RUBY
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'checks around(:each) for explicit subject usage' do
|
44
|
-
expect_offense(<<-RUBY)
|
45
|
-
RSpec.describe User do
|
46
|
-
subject { described_class.new }
|
47
|
-
|
48
|
-
around(:each) do |test|
|
49
|
-
do_something_with(subject)
|
50
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
51
|
-
end
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'ignores subject when not wrapped inside a test' do
|
57
|
-
expect_no_offenses(<<-RUBY)
|
58
|
-
def foo
|
59
|
-
it(subject)
|
60
|
-
end
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'when IgnoreSharedExamples is false' do
|
66
|
-
let(:cop_config) { { 'IgnoreSharedExamples' => false } }
|
67
|
-
|
68
|
-
it_behaves_like 'checking subject outside of shared examples'
|
69
|
-
|
70
|
-
it 'checks shared_examples for explicit subject usage' do
|
71
|
-
expect_offense(<<-RUBY)
|
72
|
-
RSpec.describe User do
|
73
|
-
subject(:new_user) { described_class.new }
|
74
|
-
|
75
|
-
shared_examples_for 'a valid new user' do
|
76
|
-
it "is a User" do
|
77
|
-
expect(subject).to be_a(User)
|
78
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
79
|
-
end
|
80
|
-
|
81
|
-
it "is valid" do
|
82
|
-
expect(subject.valid?).to be(true)
|
83
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
84
|
-
end
|
85
|
-
|
86
|
-
it "is new" do
|
87
|
-
expect(subject).to be_new_record
|
88
|
-
^^^^^^^ Name your test subject if you need to reference it explicitly.
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when IgnoreSharedExamples is true' do
|
97
|
-
let(:cop_config) { { 'IgnoreSharedExamples' => true } }
|
98
|
-
|
99
|
-
it_behaves_like 'checking subject outside of shared examples'
|
100
|
-
|
101
|
-
it 'ignores explicit subject in shared_examples' do
|
102
|
-
expect_no_offenses(<<-RUBY)
|
103
|
-
RSpec.describe User do
|
104
|
-
subject(:new_user) { described_class.new }
|
105
|
-
|
106
|
-
shared_examples_for 'a valid new user' do
|
107
|
-
it "is a User" do
|
108
|
-
expect(subject).to be_a(User)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "is valid" do
|
112
|
-
expect(subject.valid?).to be(true)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "is new" do
|
116
|
-
expect(subject).to be_new_record
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
RUBY
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::NestedGroups, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
it 'flags nested contexts' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe MyClass do
|
9
|
-
context 'when foo' do
|
10
|
-
context 'when bar' do
|
11
|
-
context 'when baz' do
|
12
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [4/3].
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'when qux' do
|
18
|
-
context 'when norf' do
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'support --auto-gen-config' do
|
26
|
-
inspect_source(<<-RUBY, 'spec/foo_spec.rb')
|
27
|
-
describe MyClass do
|
28
|
-
context 'when foo' do
|
29
|
-
context 'when bar' do
|
30
|
-
context 'when baz' do
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
|
37
|
-
expect(cop.config_to_allow_offenses[:exclude_limit]).to eq('Max' => 4)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores non-spec context methods' do
|
41
|
-
expect_no_offenses(<<-RUBY)
|
42
|
-
class MyThingy
|
43
|
-
context 'this is not rspec' do
|
44
|
-
context 'but it uses contexts' do
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
RUBY
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when Max is configured as 2' do
|
52
|
-
let(:cop_config) { { 'Max' => '2' } }
|
53
|
-
|
54
|
-
it 'flags two levels of nesting' do
|
55
|
-
expect_offense(<<-RUBY)
|
56
|
-
describe MyClass do
|
57
|
-
context 'when foo' do
|
58
|
-
context 'when bar' do
|
59
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [3/2].
|
60
|
-
context 'when baz' do
|
61
|
-
^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [4/2].
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
RUBY
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when configured with MaxNesting' do
|
71
|
-
let(:cop_config) { { 'MaxNesting' => '1' } }
|
72
|
-
|
73
|
-
it 'emits a deprecation warning' do
|
74
|
-
expect { inspect_source('describe(Foo) { }', 'foo_spec.rb') }
|
75
|
-
.to output(
|
76
|
-
'Configuration key `MaxNesting` for RSpec/NestedGroups is ' \
|
77
|
-
"deprecated in favor of `Max`. Please use that instead.\n"
|
78
|
-
).to_stderr
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::NotToNot, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
context 'when EnforcedStyle is `not_to`' do
|
7
|
-
let(:cop_config) { { 'EnforcedStyle' => 'not_to' } }
|
8
|
-
|
9
|
-
it 'detects the `to_not` offense' do
|
10
|
-
expect_offense(<<-RUBY)
|
11
|
-
it { expect(false).to_not be_true }
|
12
|
-
^^^^^^ Prefer `not_to` over `to_not`.
|
13
|
-
RUBY
|
14
|
-
|
15
|
-
expect_correction(<<-RUBY)
|
16
|
-
it { expect(false).not_to be_true }
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'detects the `to_not` offense on an expect block' do
|
21
|
-
expect_offense(<<-RUBY)
|
22
|
-
expect {
|
23
|
-
2 + 2
|
24
|
-
}.to_not raise_error
|
25
|
-
^^^^^^ Prefer `not_to` over `to_not`.
|
26
|
-
RUBY
|
27
|
-
|
28
|
-
expect_correction(<<-RUBY)
|
29
|
-
expect {
|
30
|
-
2 + 2
|
31
|
-
}.not_to raise_error
|
32
|
-
RUBY
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'detects no offense when using `not_to`' do
|
36
|
-
expect_no_offenses(<<-RUBY)
|
37
|
-
it { expect(false).not_to be_true }
|
38
|
-
RUBY
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when AcceptedMethod is `to_not`' do
|
43
|
-
let(:cop_config) { { 'EnforcedStyle' => 'to_not' } }
|
44
|
-
|
45
|
-
it 'detects the `not_to` offense' do
|
46
|
-
expect_offense(<<-RUBY)
|
47
|
-
it { expect(false).not_to be_true }
|
48
|
-
^^^^^^ Prefer `to_not` over `not_to`.
|
49
|
-
RUBY
|
50
|
-
|
51
|
-
expect_correction(<<-RUBY)
|
52
|
-
it { expect(false).to_not be_true }
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'detects the `not_to` offense on an expect block' do
|
57
|
-
expect_offense(<<-RUBY)
|
58
|
-
expect {
|
59
|
-
2 + 2
|
60
|
-
}.not_to raise_error
|
61
|
-
^^^^^^ Prefer `to_not` over `not_to`.
|
62
|
-
RUBY
|
63
|
-
|
64
|
-
expect_correction(<<-RUBY)
|
65
|
-
expect {
|
66
|
-
2 + 2
|
67
|
-
}.to_not raise_error
|
68
|
-
RUBY
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'detects no offense when using `to_not`' do
|
72
|
-
expect_no_offenses(<<-RUBY)
|
73
|
-
it { expect(false).to_not be_true }
|
74
|
-
RUBY
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::OverwritingSetup do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'finds overwriten `let`' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
let(:a) { a }
|
10
|
-
let(:a) { b }
|
11
|
-
^^^^^^^^^^^^^ `a` is already defined.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'finds overwriten `subject`' do
|
17
|
-
expect_offense(<<-RUBY)
|
18
|
-
RSpec.describe User do
|
19
|
-
subject(:a) { a }
|
20
|
-
|
21
|
-
let(:a) { b }
|
22
|
-
^^^^^^^^^^^^^ `a` is already defined.
|
23
|
-
end
|
24
|
-
RUBY
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'works with `subject!` and `let!`' do
|
28
|
-
expect_offense(<<-RUBY)
|
29
|
-
RSpec.describe User do
|
30
|
-
subject!(:a) { a }
|
31
|
-
|
32
|
-
let!(:a) { b }
|
33
|
-
^^^^^^^^^^^^^^ `a` is already defined.
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'finds `let!` overwriting `let`' do
|
39
|
-
expect_offense(<<-RUBY)
|
40
|
-
RSpec.describe User do
|
41
|
-
let(:a) { b }
|
42
|
-
let!(:a) { b }
|
43
|
-
^^^^^^^^^^^^^^ `a` is already defined.
|
44
|
-
end
|
45
|
-
RUBY
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'ignores overwriting in different context' do
|
49
|
-
expect_no_offenses(<<-RUBY)
|
50
|
-
RSpec.describe User do
|
51
|
-
let(:a) { a }
|
52
|
-
|
53
|
-
context `different` do
|
54
|
-
let(:a) { b }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
RUBY
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'handles unnamed subjects' do
|
61
|
-
expect_offense(<<-RUBY)
|
62
|
-
RSpec.describe User do
|
63
|
-
subject { a }
|
64
|
-
|
65
|
-
let(:subject) { b }
|
66
|
-
^^^^^^^^^^^^^^^^^^^ `subject` is already defined.
|
67
|
-
end
|
68
|
-
RUBY
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'handles dynamic names for `let`' do
|
72
|
-
expect_no_offenses(<<-RUBY)
|
73
|
-
RSpec.describe User do
|
74
|
-
subject(:name) { a }
|
75
|
-
|
76
|
-
let(name) { b }
|
77
|
-
end
|
78
|
-
RUBY
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'handles string arguments' do
|
82
|
-
expect_offense(<<-RUBY)
|
83
|
-
RSpec.describe User do
|
84
|
-
subject(:name) { a }
|
85
|
-
|
86
|
-
let("name") { b }
|
87
|
-
^^^^^^^^^^^^^^^^^ `name` is already defined.
|
88
|
-
end
|
89
|
-
RUBY
|
90
|
-
end
|
91
|
-
end
|