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,133 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterHook do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'checks for empty line after `before` hook' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
before { do_something }
|
10
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Add an empty line after `before`.
|
11
|
-
it { does_something }
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
|
15
|
-
expect_correction(<<-RUBY)
|
16
|
-
RSpec.describe User do
|
17
|
-
before { do_something }
|
18
|
-
|
19
|
-
it { does_something }
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'checks for empty line after `after` hook' do
|
25
|
-
expect_offense(<<-RUBY)
|
26
|
-
RSpec.describe User do
|
27
|
-
after { do_something }
|
28
|
-
^^^^^^^^^^^^^^^^^^^^^^ Add an empty line after `after`.
|
29
|
-
it { does_something }
|
30
|
-
end
|
31
|
-
RUBY
|
32
|
-
|
33
|
-
expect_correction(<<-RUBY)
|
34
|
-
RSpec.describe User do
|
35
|
-
after { do_something }
|
36
|
-
|
37
|
-
it { does_something }
|
38
|
-
end
|
39
|
-
RUBY
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'checks for empty line after `around` hook' do
|
43
|
-
expect_offense(<<-RUBY)
|
44
|
-
RSpec.describe User do
|
45
|
-
around { |test| test.run }
|
46
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an empty line after `around`.
|
47
|
-
it { does_something }
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
|
51
|
-
expect_correction(<<-RUBY)
|
52
|
-
RSpec.describe User do
|
53
|
-
around { |test| test.run }
|
54
|
-
|
55
|
-
it { does_something }
|
56
|
-
end
|
57
|
-
RUBY
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'approves empty line after `before` hook' do
|
61
|
-
expect_no_offenses(<<-RUBY)
|
62
|
-
RSpec.describe User do
|
63
|
-
before { do_something }
|
64
|
-
|
65
|
-
it { does_something }
|
66
|
-
end
|
67
|
-
RUBY
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'approves empty line after `after` hook' do
|
71
|
-
expect_no_offenses(<<-RUBY)
|
72
|
-
RSpec.describe User do
|
73
|
-
after { do_something }
|
74
|
-
|
75
|
-
it { does_something }
|
76
|
-
end
|
77
|
-
RUBY
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'approves empty line after `around` hook' do
|
81
|
-
expect_no_offenses(<<-RUBY)
|
82
|
-
RSpec.describe User do
|
83
|
-
around { |test| test.run }
|
84
|
-
|
85
|
-
it { does_something }
|
86
|
-
end
|
87
|
-
RUBY
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'handles multiline `before` block' do
|
91
|
-
expect_no_offenses(<<-RUBY)
|
92
|
-
RSpec.describe User do
|
93
|
-
before do
|
94
|
-
do_something
|
95
|
-
end
|
96
|
-
|
97
|
-
it { does_something }
|
98
|
-
end
|
99
|
-
RUBY
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'handles multiline `after` block' do
|
103
|
-
expect_no_offenses(<<-RUBY)
|
104
|
-
RSpec.describe User do
|
105
|
-
after do
|
106
|
-
do_something
|
107
|
-
end
|
108
|
-
|
109
|
-
it { does_something }
|
110
|
-
end
|
111
|
-
RUBY
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'handles multiline `around` block' do
|
115
|
-
expect_no_offenses(<<-RUBY)
|
116
|
-
RSpec.describe User do
|
117
|
-
around do |test|
|
118
|
-
test.run
|
119
|
-
end
|
120
|
-
|
121
|
-
it { does_something }
|
122
|
-
end
|
123
|
-
RUBY
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'handles `before` being the latest node' do
|
127
|
-
expect_no_offenses(<<-RUBY)
|
128
|
-
RSpec.describe User do
|
129
|
-
before { do_something }
|
130
|
-
end
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'checks for empty line after subject' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
subject { described_class.new }
|
10
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line after `subject`.
|
11
|
-
let(:params) { foo }
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
|
15
|
-
expect_correction(<<-RUBY)
|
16
|
-
RSpec.describe User do
|
17
|
-
subject { described_class.new }
|
18
|
-
|
19
|
-
let(:params) { foo }
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'checks for empty line after subject!' do
|
25
|
-
expect_offense(<<-RUBY)
|
26
|
-
RSpec.describe User do
|
27
|
-
subject! { described_class.new }
|
28
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line after `subject`.
|
29
|
-
let(:params) { foo }
|
30
|
-
end
|
31
|
-
RUBY
|
32
|
-
|
33
|
-
expect_correction(<<-RUBY)
|
34
|
-
RSpec.describe User do
|
35
|
-
subject! { described_class.new }
|
36
|
-
|
37
|
-
let(:params) { foo }
|
38
|
-
end
|
39
|
-
RUBY
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'approves empty line after subject' do
|
43
|
-
expect_no_offenses(<<-RUBY)
|
44
|
-
RSpec.describe User do
|
45
|
-
subject { described_class.new }
|
46
|
-
|
47
|
-
let(:params) { foo }
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'approves empty line after subject!' do
|
53
|
-
expect_no_offenses(<<-RUBY)
|
54
|
-
RSpec.describe User do
|
55
|
-
subject! { described_class.new }
|
56
|
-
|
57
|
-
let(:params) { foo }
|
58
|
-
end
|
59
|
-
RUBY
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'handles subjects in tests' do
|
63
|
-
expect_no_offenses(<<-RUBY)
|
64
|
-
RSpec.describe User do
|
65
|
-
# This shouldn't really ever happen in a sane codebase but I still
|
66
|
-
# want to avoid false positives
|
67
|
-
it "doesn't mind me calling a method called subject in the test" do
|
68
|
-
subject { bar }
|
69
|
-
let(foo)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'handles multiline subject block' do
|
76
|
-
expect_no_offenses(<<-RUBY)
|
77
|
-
RSpec.describe User do
|
78
|
-
subject do
|
79
|
-
described_class.new
|
80
|
-
end
|
81
|
-
|
82
|
-
let(:params) { foo }
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'handles subject being the latest node' do
|
88
|
-
expect_no_offenses(<<-RUBY)
|
89
|
-
RSpec.describe User do
|
90
|
-
subject { described_user }
|
91
|
-
end
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ExampleLength, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) { { 'Max' => 3 } }
|
7
|
-
|
8
|
-
it 'ignores non-spec blocks' do
|
9
|
-
expect_no_offenses(<<-RUBY)
|
10
|
-
foo do
|
11
|
-
line 1
|
12
|
-
line 2
|
13
|
-
line 3
|
14
|
-
line 4
|
15
|
-
end
|
16
|
-
RUBY
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'allows an empty example' do
|
20
|
-
expect_no_offenses(<<-RUBY)
|
21
|
-
it do
|
22
|
-
end
|
23
|
-
RUBY
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'allows a short example' do
|
27
|
-
expect_no_offenses(<<-RUBY)
|
28
|
-
it do
|
29
|
-
line 1
|
30
|
-
line 2
|
31
|
-
line 3
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'ignores comments' do
|
37
|
-
expect_no_offenses(<<-RUBY)
|
38
|
-
it do
|
39
|
-
line 1
|
40
|
-
line 2
|
41
|
-
# comment
|
42
|
-
line 3
|
43
|
-
end
|
44
|
-
RUBY
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when inspecting large examples' do
|
48
|
-
it 'flags the example' do
|
49
|
-
expect_offense(<<-RUBY)
|
50
|
-
it do
|
51
|
-
^^^^^ Example has too many lines [4/3].
|
52
|
-
line 1
|
53
|
-
line 2
|
54
|
-
line 3
|
55
|
-
line 4
|
56
|
-
end
|
57
|
-
RUBY
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with CountComments enabled' do
|
62
|
-
let(:cop_config) do
|
63
|
-
{ 'Max' => 3, 'CountComments' => true }
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'flags the example' do
|
67
|
-
expect_offense(<<-RUBY)
|
68
|
-
it do
|
69
|
-
^^^^^ Example has too many lines [4/3].
|
70
|
-
line 1
|
71
|
-
line 2
|
72
|
-
# comment
|
73
|
-
line 3
|
74
|
-
end
|
75
|
-
RUBY
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ExampleWithoutDescription, :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 `always_allow`' do
|
11
|
-
let(:enforced_style) { 'always_allow' }
|
12
|
-
|
13
|
-
it 'flags empty strings for description' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
it '' do
|
16
|
-
^^ Omit the argument when you want to have auto-generated description.
|
17
|
-
expect(subject).to be_good
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'ignores `it` with a description' do
|
23
|
-
expect_no_offenses(<<-RUBY)
|
24
|
-
it 'is good' do
|
25
|
-
expect(subject).to be_good
|
26
|
-
end
|
27
|
-
RUBY
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'ignores `it` without an argument' do
|
31
|
-
expect_no_offenses(<<-RUBY)
|
32
|
-
it do
|
33
|
-
expect(subject).to be_good
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with EnforcedStyle `single_line_only`' do
|
40
|
-
let(:enforced_style) { 'single_line_only' }
|
41
|
-
|
42
|
-
it 'flags missing description in multi-line examples' do
|
43
|
-
expect_offense(<<-RUBY)
|
44
|
-
it do
|
45
|
-
^^ Add a description.
|
46
|
-
expect(subject).to be_good
|
47
|
-
end
|
48
|
-
RUBY
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'ignores missing description in single-line examples' do
|
52
|
-
expect_no_offenses(<<-RUBY)
|
53
|
-
it { expect(subject).to be_good }
|
54
|
-
RUBY
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'flags example with an empty string for description' do
|
58
|
-
expect_offense(<<-RUBY)
|
59
|
-
it('') { expect(subject).to be_good }
|
60
|
-
^^ Omit the argument when you want to have auto-generated description.
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'with EnforcedStyle `disallow`' do
|
66
|
-
let(:enforced_style) { 'disallow' }
|
67
|
-
|
68
|
-
it 'flags missing description in multi-line examples' do
|
69
|
-
expect_offense(<<-RUBY)
|
70
|
-
it do
|
71
|
-
^^ Add a description.
|
72
|
-
expect(subject).to be_good
|
73
|
-
end
|
74
|
-
RUBY
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'flags missing description in single-line examples' do
|
78
|
-
expect_offense(<<-RUBY)
|
79
|
-
it { expect(subject).to be_good }
|
80
|
-
^^ Add a description.
|
81
|
-
RUBY
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'ignores `it` with a description' do
|
85
|
-
expect_no_offenses(<<-RUBY)
|
86
|
-
it 'is good' do
|
87
|
-
expect(subject).to be_good
|
88
|
-
end
|
89
|
-
RUBY
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
context 'with configuration' do
|
7
|
-
let(:cop_config) do
|
8
|
-
{
|
9
|
-
'CustomTransform' => { 'have' => 'has' },
|
10
|
-
'IgnoredWords' => %w[only really]
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'ignores non-example blocks' do
|
15
|
-
expect_no_offenses('foo "should do something" do; end')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'finds description with `should` at the beginning' do
|
19
|
-
expect_offense(<<-RUBY)
|
20
|
-
it 'should do something' do
|
21
|
-
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
22
|
-
end
|
23
|
-
RUBY
|
24
|
-
|
25
|
-
expect_correction(<<-RUBY)
|
26
|
-
it 'does something' do
|
27
|
-
end
|
28
|
-
RUBY
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'finds interpolated description with `should` at the beginning' do
|
32
|
-
expect_offense(<<-'RUBY')
|
33
|
-
it "should do #{:stuff}" do
|
34
|
-
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
35
|
-
end
|
36
|
-
RUBY
|
37
|
-
|
38
|
-
expect_correction(<<-'RUBY')
|
39
|
-
it "does #{:stuff}" do
|
40
|
-
end
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'finds description with `Should` at the beginning' do
|
45
|
-
expect_offense(<<-RUBY)
|
46
|
-
it 'Should do something' do
|
47
|
-
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
|
51
|
-
expect_correction(<<-RUBY)
|
52
|
-
it 'does something' do
|
53
|
-
end
|
54
|
-
RUBY
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'finds description with `shouldn\'t` at the beginning' do
|
58
|
-
expect_offense(<<-RUBY)
|
59
|
-
it "shouldn't do something" do
|
60
|
-
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
61
|
-
end
|
62
|
-
RUBY
|
63
|
-
|
64
|
-
expect_correction(<<-RUBY)
|
65
|
-
it "does not do something" do
|
66
|
-
end
|
67
|
-
RUBY
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'finds description with `SHOULDN\'T` at the beginning' do
|
71
|
-
expect_offense(<<-RUBY)
|
72
|
-
it "SHOULDN'T do something" do
|
73
|
-
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
74
|
-
end
|
75
|
-
RUBY
|
76
|
-
|
77
|
-
expect_correction(<<-RUBY)
|
78
|
-
it "DOES NOT do something" do
|
79
|
-
end
|
80
|
-
RUBY
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'flags a lone should' do
|
84
|
-
expect_offense(<<-RUBY)
|
85
|
-
it 'should' do
|
86
|
-
^^^^^^ Do not use should when describing your tests.
|
87
|
-
end
|
88
|
-
RUBY
|
89
|
-
|
90
|
-
expect_correction(<<-RUBY)
|
91
|
-
it '' do
|
92
|
-
end
|
93
|
-
RUBY
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'flags a lone should not' do
|
97
|
-
expect_offense(<<-RUBY)
|
98
|
-
it 'should not' do
|
99
|
-
^^^^^^^^^^ Do not use should when describing your tests.
|
100
|
-
end
|
101
|
-
RUBY
|
102
|
-
|
103
|
-
expect_correction(<<-RUBY)
|
104
|
-
it 'does not' do
|
105
|
-
end
|
106
|
-
RUBY
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'finds leading its' do
|
110
|
-
expect_offense(<<-RUBY)
|
111
|
-
it "it does something" do
|
112
|
-
^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
|
113
|
-
end
|
114
|
-
RUBY
|
115
|
-
|
116
|
-
expect_correction(<<-RUBY)
|
117
|
-
it "does something" do
|
118
|
-
end
|
119
|
-
RUBY
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'finds leading it in interpolated description' do
|
123
|
-
expect_offense(<<-'RUBY')
|
124
|
-
it "it does #{action}" do
|
125
|
-
^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
|
126
|
-
end
|
127
|
-
RUBY
|
128
|
-
|
129
|
-
expect_correction(<<-'RUBY')
|
130
|
-
it "does #{action}" do
|
131
|
-
end
|
132
|
-
RUBY
|
133
|
-
end
|
134
|
-
|
135
|
-
it "skips words beginning with 'it'" do
|
136
|
-
expect_no_offenses(<<-RUBY)
|
137
|
-
it 'itemizes items' do
|
138
|
-
end
|
139
|
-
RUBY
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'skips descriptions without `should` at the beginning' do
|
143
|
-
expect_no_offenses(<<-RUBY)
|
144
|
-
it 'finds no should here' do
|
145
|
-
end
|
146
|
-
RUBY
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'skips descriptions starting with words that begin with `should`' do
|
150
|
-
expect_no_offenses(<<-RUBY)
|
151
|
-
it 'shoulders the burden' do
|
152
|
-
end
|
153
|
-
RUBY
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'skips interpolated description without literal `should` at the start' do
|
157
|
-
expect_no_offenses(<<-'RUBY')
|
158
|
-
it "#{should} not be here" do
|
159
|
-
end
|
160
|
-
RUBY
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'when configuration is empty' do
|
165
|
-
include_examples 'autocorrect',
|
166
|
-
'it "should have trait" do end',
|
167
|
-
'it "haves trait" do end'
|
168
|
-
|
169
|
-
include_examples 'autocorrect',
|
170
|
-
'it "should only fail" do end',
|
171
|
-
'it "onlies fail" do end'
|
172
|
-
end
|
173
|
-
end
|