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,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style }
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'when the enforced style is `it_behaves_like`' do
|
11
|
-
let(:enforced_style) { :it_behaves_like }
|
12
|
-
|
13
|
-
it 'flags a violation for it_should_behave_like' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
it_should_behave_like 'a foo'
|
16
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_behaves_like` over `it_should_behave_like` when including examples in a nested context.
|
17
|
-
RUBY
|
18
|
-
|
19
|
-
expect_correction(<<-RUBY)
|
20
|
-
it_behaves_like 'a foo'
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'does not flag a violation for it_behaves_like' do
|
25
|
-
expect_no_offenses("it_behaves_like 'a foo'")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when the enforced style is `it_should_behave_like`' do
|
30
|
-
let(:enforced_style) { :it_should_behave_like }
|
31
|
-
|
32
|
-
it 'flags a violation for it_behaves_like' do
|
33
|
-
expect_offense(<<-RUBY)
|
34
|
-
it_behaves_like 'a foo'
|
35
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_should_behave_like` over `it_behaves_like` when including examples in a nested context.
|
36
|
-
RUBY
|
37
|
-
|
38
|
-
expect_correction(<<-RUBY)
|
39
|
-
it_should_behave_like 'a foo'
|
40
|
-
RUBY
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'does not flag a violation for it_behaves_like' do
|
44
|
-
expect_no_offenses("it_should_behave_like 'a foo'")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::IteratedExpectation do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags `each` with an expectation' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
it 'validates users' do
|
9
|
-
[user1, user2, user3].each { |user| expect(user).to be_valid }
|
10
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using the `all` matcher instead of iterating over an array.
|
11
|
-
end
|
12
|
-
RUBY
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'flags `each` when expectation calls method with arguments' do
|
16
|
-
expect_offense(<<-RUBY)
|
17
|
-
it 'validates users' do
|
18
|
-
[user1, user2, user3].each { |user| expect(user).to be_a(User) }
|
19
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using the `all` matcher instead of iterating over an array.
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'ignores `each` without expectation' do
|
25
|
-
expect_no_offenses(<<-RUBY)
|
26
|
-
it 'validates users' do
|
27
|
-
[user1, user2, user3].each { |user| allow(user).to receive(:method) }
|
28
|
-
end
|
29
|
-
RUBY
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'flags `each` with multiple expectations' do
|
33
|
-
expect_offense(<<-RUBY)
|
34
|
-
it 'validates users' do
|
35
|
-
[user1, user2, user3].each do |user|
|
36
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using the `all` matcher instead of iterating over an array.
|
37
|
-
expect(user).to receive(:method)
|
38
|
-
expect(user).to receive(:other_method)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'ignore `each` when the body does not contain only expectations' do
|
45
|
-
expect_no_offenses(<<-RUBY)
|
46
|
-
it 'validates users' do
|
47
|
-
[user1, user2, user3].each do |user|
|
48
|
-
allow(Something).to receive(:method).and_return(user)
|
49
|
-
expect(user).to receive(:method)
|
50
|
-
expect(user).to receive(:other_method)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'ignores `each` with expectation on property' do
|
57
|
-
expect_no_offenses(<<-RUBY)
|
58
|
-
it 'validates users' do
|
59
|
-
[user1, user2, user3].each { |user| expect(user.name).to be }
|
60
|
-
end
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'ignores assignments in the iteration' do
|
65
|
-
expect_no_offenses(<<-RUBY)
|
66
|
-
it 'validates users' do
|
67
|
-
[user1, user2, user3].each { |user| array = array.concat(user) }
|
68
|
-
end
|
69
|
-
RUBY
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'ignores `each` when there is a negative expectation' do
|
73
|
-
expect_no_offenses(<<-RUBY)
|
74
|
-
it 'validates users' do
|
75
|
-
[user1, user2, user3].each do |user|
|
76
|
-
expect(user).not_to receive(:method)
|
77
|
-
expect(user).to receive(:other_method)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
RUBY
|
81
|
-
end
|
82
|
-
end
|
@@ -1,119 +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_offense(<<-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
|
-
|
16
|
-
expect_correction(<<-RUBY)
|
17
|
-
RSpec.describe User do
|
18
|
-
subject { described_class.new }
|
19
|
-
let(:params) { foo }
|
20
|
-
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'checks subject below let!' do
|
26
|
-
expect_offense(<<-RUBY)
|
27
|
-
RSpec.describe User do
|
28
|
-
let!(:params) { foo }
|
29
|
-
|
30
|
-
subject { described_class.new }
|
31
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let!` declarations.
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
|
35
|
-
expect_correction(<<-RUBY)
|
36
|
-
RSpec.describe User do
|
37
|
-
subject { described_class.new }
|
38
|
-
let!(:params) { foo }
|
39
|
-
|
40
|
-
end
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'approves of subject above let' do
|
45
|
-
expect_no_offenses(<<-RUBY)
|
46
|
-
RSpec.describe User do
|
47
|
-
context 'blah' do
|
48
|
-
end
|
49
|
-
|
50
|
-
subject { described_class.new }
|
51
|
-
|
52
|
-
let(:params) { foo }
|
53
|
-
end
|
54
|
-
RUBY
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'handles subjects in contexts' do
|
58
|
-
expect_no_offenses(<<-RUBY)
|
59
|
-
RSpec.describe User do
|
60
|
-
let(:params) { foo }
|
61
|
-
|
62
|
-
context "when something happens" do
|
63
|
-
subject { described_class.new }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
RUBY
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'handles subjects in tests' do
|
70
|
-
expect_no_offenses(<<-RUBY)
|
71
|
-
RSpec.describe User do
|
72
|
-
# This shouldn't really ever happen in a sane codebase but I still
|
73
|
-
# want to avoid false positives
|
74
|
-
it "doesn't mind me calling a method called subject in the test" do
|
75
|
-
let(foo)
|
76
|
-
subject { bar }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
RUBY
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'checks subject below hook' do
|
83
|
-
expect_offense(<<-RUBY)
|
84
|
-
RSpec.describe User do
|
85
|
-
before { allow(Foo).to receive(:bar) }
|
86
|
-
|
87
|
-
subject { described_class.new }
|
88
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `before` declarations.
|
89
|
-
end
|
90
|
-
RUBY
|
91
|
-
|
92
|
-
expect_correction(<<-RUBY)
|
93
|
-
RSpec.describe User do
|
94
|
-
subject { described_class.new }
|
95
|
-
before { allow(Foo).to receive(:bar) }
|
96
|
-
|
97
|
-
end
|
98
|
-
RUBY
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'checks subject below example' do
|
102
|
-
expect_offense(<<-RUBY)
|
103
|
-
RSpec.describe User do
|
104
|
-
it { is_expected.to be_present }
|
105
|
-
|
106
|
-
subject { described_class.new }
|
107
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `it` declarations.
|
108
|
-
end
|
109
|
-
RUBY
|
110
|
-
|
111
|
-
expect_correction(<<-RUBY)
|
112
|
-
RSpec.describe User do
|
113
|
-
subject { described_class.new }
|
114
|
-
it { is_expected.to be_present }
|
115
|
-
|
116
|
-
end
|
117
|
-
RUBY
|
118
|
-
end
|
119
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::LeakyConstantDeclaration do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
describe 'constant assignment' do
|
7
|
-
it 'flags inside an example group' do
|
8
|
-
expect_offense(<<-RUBY)
|
9
|
-
describe SomeClass do
|
10
|
-
CONSTANT = "Accessible as ::CONSTANT".freeze
|
11
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Stub constant instead of declaring explicitly.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'flags inside shared example group' do
|
17
|
-
expect_offense(<<-RUBY)
|
18
|
-
RSpec.shared_examples 'shared example' do
|
19
|
-
CONSTANT = "Accessible as ::CONSTANT".freeze
|
20
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Stub constant instead of declaring explicitly.
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'flags inside an example' do
|
26
|
-
expect_offense(<<-RUBY)
|
27
|
-
describe SomeClass do
|
28
|
-
specify do
|
29
|
-
CONSTANT = "Accessible as ::CONSTANT".freeze
|
30
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Stub constant instead of declaring explicitly.
|
31
|
-
end
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'ignores outside of example/shared group' do
|
37
|
-
expect_no_offenses(<<-RUBY)
|
38
|
-
factory :some_class do
|
39
|
-
CONSTANT = "Accessible as ::CONSTANT".freeze
|
40
|
-
end
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'class defined' do
|
46
|
-
it 'flags inside an example group' do
|
47
|
-
expect_offense(<<-RUBY)
|
48
|
-
describe SomeClass do
|
49
|
-
class DummyClass < described_class
|
50
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Stub class constant instead of declaring explicitly.
|
51
|
-
end
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'ignores anonymous classes' do
|
57
|
-
expect_no_offenses(<<-RUBY)
|
58
|
-
describe SomeClass do
|
59
|
-
let(:dummy_playbook) do
|
60
|
-
Class.new do
|
61
|
-
def method
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
RUBY
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'flags namespaced class' do
|
70
|
-
expect_offense(<<-RUBY)
|
71
|
-
describe SomeClass do
|
72
|
-
class SomeModule::AnotherModule::DummyClass
|
73
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Stub class constant instead of declaring explicitly.
|
74
|
-
end
|
75
|
-
end
|
76
|
-
RUBY
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'module defined' do
|
81
|
-
it 'flags inside an example group' do
|
82
|
-
expect_offense(<<-RUBY)
|
83
|
-
describe SomeClass do
|
84
|
-
module DummyModule
|
85
|
-
^^^^^^^^^^^^^^^^^^ Stub module constant instead of declaring explicitly.
|
86
|
-
end
|
87
|
-
end
|
88
|
-
RUBY
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::LetBeforeExamples do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags `let` after `it`' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
it { is_expected.to be_after_let }
|
10
|
-
let(:foo) { bar }
|
11
|
-
^^^^^^^^^^^^^^^^^ Move `let` before the examples in the group.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
|
15
|
-
expect_correction(<<-RUBY)
|
16
|
-
RSpec.describe User do
|
17
|
-
let(:foo) { bar }
|
18
|
-
it { is_expected.to be_after_let }
|
19
|
-
end
|
20
|
-
RUBY
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'flags `let` after `context`' do
|
24
|
-
expect_offense(<<-RUBY)
|
25
|
-
RSpec.describe User do
|
26
|
-
context 'a context' do
|
27
|
-
it { is_expected.to be_after_let }
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:foo) { bar }
|
31
|
-
^^^^^^^^^^^^^^^^^ Move `let` before the examples in the group.
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
|
35
|
-
expect_correction(<<-RUBY)
|
36
|
-
RSpec.describe User do
|
37
|
-
let(:foo) { bar }
|
38
|
-
context 'a context' do
|
39
|
-
it { is_expected.to be_after_let }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'flags `let` after `include_examples`' do
|
47
|
-
expect_offense(<<-RUBY)
|
48
|
-
RSpec.describe User do
|
49
|
-
include_examples('should be after let')
|
50
|
-
|
51
|
-
let(:foo) { bar }
|
52
|
-
^^^^^^^^^^^^^^^^^ Move `let` before the examples in the group.
|
53
|
-
end
|
54
|
-
RUBY
|
55
|
-
|
56
|
-
expect_correction(<<-RUBY)
|
57
|
-
RSpec.describe User do
|
58
|
-
let(:foo) { bar }
|
59
|
-
include_examples('should be after let')
|
60
|
-
|
61
|
-
end
|
62
|
-
RUBY
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'does not flag `let` before the examples' do
|
66
|
-
expect_no_offenses(<<-RUBY)
|
67
|
-
RSpec.describe User do
|
68
|
-
let(:foo) { bar }
|
69
|
-
|
70
|
-
it { is_expected.to be_after_let }
|
71
|
-
|
72
|
-
context 'a context' do
|
73
|
-
it { is_expected.to work }
|
74
|
-
end
|
75
|
-
|
76
|
-
include_examples('everything is fine')
|
77
|
-
end
|
78
|
-
RUBY
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'does not flag `let` in a nested context' do
|
82
|
-
expect_no_offenses(<<-RUBY)
|
83
|
-
RSpec.describe User do
|
84
|
-
let(:foo) { bar }
|
85
|
-
|
86
|
-
context 'something else' do
|
87
|
-
let(:foo) { baz }
|
88
|
-
it { is_expected.to work }
|
89
|
-
end
|
90
|
-
|
91
|
-
include_examples('everything is fine')
|
92
|
-
end
|
93
|
-
RUBY
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'allows inclusion of context before `let`' do
|
97
|
-
expect_no_offenses(<<-RUBY)
|
98
|
-
RSpec.describe User do
|
99
|
-
include_context 'special user'
|
100
|
-
|
101
|
-
let(:foo) { bar }
|
102
|
-
end
|
103
|
-
RUBY
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'ignores single-line example blocks' do
|
107
|
-
expect_no_offenses(<<-RUBY)
|
108
|
-
RSpec.describe User do
|
109
|
-
include_examples 'special user' do
|
110
|
-
let(:foo) { bar }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
RUBY
|
114
|
-
end
|
115
|
-
|
116
|
-
bad_code = <<-RUBY
|
117
|
-
RSpec.describe User do
|
118
|
-
include_examples('should be after let')
|
119
|
-
|
120
|
-
let(:foo) { (<<-SOURCE) }
|
121
|
-
some long text here
|
122
|
-
SOURCE
|
123
|
-
end
|
124
|
-
RUBY
|
125
|
-
|
126
|
-
good_code = <<-RUBY
|
127
|
-
RSpec.describe User do
|
128
|
-
let(:foo) { (<<-SOURCE) }
|
129
|
-
some long text here
|
130
|
-
SOURCE
|
131
|
-
include_examples('should be after let')
|
132
|
-
|
133
|
-
end
|
134
|
-
RUBY
|
135
|
-
|
136
|
-
include_examples 'autocorrect', bad_code, good_code
|
137
|
-
end
|