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,90 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::Rails::HttpStatus, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
context 'when EnforcedStyle is `symbolic`' do
|
7
|
-
let(:cop_config) { { 'EnforcedStyle' => 'symbolic' } }
|
8
|
-
|
9
|
-
it 'registers an offense when using numeric value' do
|
10
|
-
expect_offense(<<-RUBY)
|
11
|
-
it { is_expected.to have_http_status 200 }
|
12
|
-
^^^ Prefer `:ok` over `200` to describe HTTP status code.
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'does not register an offense when using symbolic value' do
|
17
|
-
expect_no_offenses(<<-RUBY)
|
18
|
-
it { is_expected.to have_http_status :ok }
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'does not register an offense when using custom HTTP code' do
|
23
|
-
expect_no_offenses(<<-RUBY)
|
24
|
-
it { is_expected.to have_http_status 550 }
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
include_examples 'autocorrect',
|
29
|
-
'it { is_expected.to have_http_status 200 }',
|
30
|
-
'it { is_expected.to have_http_status :ok }'
|
31
|
-
|
32
|
-
include_examples 'autocorrect',
|
33
|
-
'it { is_expected.to have_http_status 404 }',
|
34
|
-
'it { is_expected.to have_http_status :not_found }'
|
35
|
-
|
36
|
-
context 'with parenthesis' do
|
37
|
-
include_examples 'autocorrect',
|
38
|
-
'it { is_expected.to have_http_status(200) }',
|
39
|
-
'it { is_expected.to have_http_status(:ok) }'
|
40
|
-
|
41
|
-
include_examples 'autocorrect',
|
42
|
-
'it { is_expected.to have_http_status(404) }',
|
43
|
-
'it { is_expected.to have_http_status(:not_found) }'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when EnforcedStyle is `numeric`' do
|
48
|
-
let(:cop_config) { { 'EnforcedStyle' => 'numeric' } }
|
49
|
-
|
50
|
-
it 'registers an offense when using symbolic value' do
|
51
|
-
expect_offense(<<-RUBY)
|
52
|
-
it { is_expected.to have_http_status :ok }
|
53
|
-
^^^ Prefer `200` over `:ok` to describe HTTP status code.
|
54
|
-
RUBY
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'does not register an offense when using numeric value' do
|
58
|
-
expect_no_offenses(<<-RUBY)
|
59
|
-
it { is_expected.to have_http_status 200 }
|
60
|
-
RUBY
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'does not register an offense when using whitelisted symbols' do
|
64
|
-
expect_no_offenses(<<-RUBY)
|
65
|
-
it { is_expected.to have_http_status :error }
|
66
|
-
it { is_expected.to have_http_status :success }
|
67
|
-
it { is_expected.to have_http_status :missing }
|
68
|
-
it { is_expected.to have_http_status :redirect }
|
69
|
-
RUBY
|
70
|
-
end
|
71
|
-
|
72
|
-
include_examples 'autocorrect',
|
73
|
-
'it { is_expected.to have_http_status :ok }',
|
74
|
-
'it { is_expected.to have_http_status 200 }'
|
75
|
-
|
76
|
-
include_examples 'autocorrect',
|
77
|
-
'it { is_expected.to have_http_status :not_found }',
|
78
|
-
'it { is_expected.to have_http_status 404 }'
|
79
|
-
|
80
|
-
context 'with parenthesis' do
|
81
|
-
include_examples 'autocorrect',
|
82
|
-
'it { is_expected.to have_http_status(:ok) }',
|
83
|
-
'it { is_expected.to have_http_status(200) }'
|
84
|
-
|
85
|
-
include_examples 'autocorrect',
|
86
|
-
'it { is_expected.to have_http_status(:not_found) }',
|
87
|
-
'it { is_expected.to have_http_status(404) }'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ReceiveCounts do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags usage of `exactly(1).times`' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
expect(foo).to receive(:bar).exactly(1).times
|
9
|
-
^^^^^^^^^^^^^^^^^ Use `.once` instead of `.exactly(1).times`.
|
10
|
-
RUBY
|
11
|
-
|
12
|
-
expect_correction(<<-RUBY)
|
13
|
-
expect(foo).to receive(:bar).once
|
14
|
-
RUBY
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'flags usage of `exactly(2).times`' do
|
18
|
-
expect_offense(<<-RUBY)
|
19
|
-
expect(foo).to receive(:bar).exactly(2).times
|
20
|
-
^^^^^^^^^^^^^^^^^ Use `.twice` instead of `.exactly(2).times`.
|
21
|
-
RUBY
|
22
|
-
|
23
|
-
expect_correction(<<-RUBY)
|
24
|
-
expect(foo).to receive(:bar).twice
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'allows `exactly(3).times`' do
|
29
|
-
expect_no_offenses(<<-RUBY)
|
30
|
-
expect(foo).to receive(:bar).exactly(3).times
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'allows `exactly(n).times`' do
|
35
|
-
expect_no_offenses(<<-RUBY)
|
36
|
-
expect(foo).to receive(:bar).exactly(n).times
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'flags usage of `exactly(1).times` after `with`' do
|
41
|
-
expect_offense(<<-RUBY)
|
42
|
-
expect(foo).to receive(:bar).with(baz).exactly(1).times
|
43
|
-
^^^^^^^^^^^^^^^^^ Use `.once` instead of `.exactly(1).times`.
|
44
|
-
RUBY
|
45
|
-
|
46
|
-
expect_correction(<<-RUBY)
|
47
|
-
expect(foo).to receive(:bar).with(baz).once
|
48
|
-
RUBY
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'flags usage of `exactly(1).times` with return value' do
|
52
|
-
expect_offense(<<-RUBY)
|
53
|
-
expect(foo).to receive(:bar).exactly(1).times.and_return(true)
|
54
|
-
^^^^^^^^^^^^^^^^^ Use `.once` instead of `.exactly(1).times`.
|
55
|
-
RUBY
|
56
|
-
|
57
|
-
expect_correction(<<-RUBY)
|
58
|
-
expect(foo).to receive(:bar).once.and_return(true)
|
59
|
-
RUBY
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'flags usage of `exactly(1).times` with a block' do
|
63
|
-
expect_offense(<<-RUBY)
|
64
|
-
expect(foo).to receive(:bar).exactly(1).times { true }
|
65
|
-
^^^^^^^^^^^^^^^^^ Use `.once` instead of `.exactly(1).times`.
|
66
|
-
RUBY
|
67
|
-
|
68
|
-
expect_correction(<<-RUBY)
|
69
|
-
expect(foo).to receive(:bar).once { true }
|
70
|
-
RUBY
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'flags usage of `at_least(1).times`' do
|
74
|
-
expect_offense(<<-RUBY)
|
75
|
-
expect(foo).to receive(:bar).at_least(1).times
|
76
|
-
^^^^^^^^^^^^^^^^^^ Use `.at_least(:once)` instead of `.at_least(1).times`.
|
77
|
-
RUBY
|
78
|
-
|
79
|
-
expect_correction(<<-RUBY)
|
80
|
-
expect(foo).to receive(:bar).at_least(:once)
|
81
|
-
RUBY
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'flags usage of `at_least(2).times`' do
|
85
|
-
expect_offense(<<-RUBY)
|
86
|
-
expect(foo).to receive(:bar).at_least(2).times
|
87
|
-
^^^^^^^^^^^^^^^^^^ Use `.at_least(:twice)` instead of `.at_least(2).times`.
|
88
|
-
RUBY
|
89
|
-
|
90
|
-
expect_correction(<<-RUBY)
|
91
|
-
expect(foo).to receive(:bar).at_least(:twice)
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'flags usage of `at_least(2).times` with a block' do
|
96
|
-
expect_offense(<<-RUBY)
|
97
|
-
expect(foo).to receive(:bar).at_least(2).times { true }
|
98
|
-
^^^^^^^^^^^^^^^^^^ Use `.at_least(:twice)` instead of `.at_least(2).times`.
|
99
|
-
RUBY
|
100
|
-
|
101
|
-
expect_correction(<<-RUBY)
|
102
|
-
expect(foo).to receive(:bar).at_least(:twice) { true }
|
103
|
-
RUBY
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'flags usage of `at_most(1).times`' do
|
107
|
-
expect_offense(<<-RUBY)
|
108
|
-
expect(foo).to receive(:bar).at_most(1).times
|
109
|
-
^^^^^^^^^^^^^^^^^ Use `.at_most(:once)` instead of `.at_most(1).times`.
|
110
|
-
RUBY
|
111
|
-
|
112
|
-
expect_correction(<<-RUBY)
|
113
|
-
expect(foo).to receive(:bar).at_most(:once)
|
114
|
-
RUBY
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'flags usage of `at_most(2).times`' do
|
118
|
-
expect_offense(<<-RUBY)
|
119
|
-
expect(foo).to receive(:bar).at_most(2).times
|
120
|
-
^^^^^^^^^^^^^^^^^ Use `.at_most(:twice)` instead of `.at_most(2).times`.
|
121
|
-
RUBY
|
122
|
-
|
123
|
-
expect_correction(<<-RUBY)
|
124
|
-
expect(foo).to receive(:bar).at_most(:twice)
|
125
|
-
RUBY
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'allows exactly(1).times when not called on `receive`' do
|
129
|
-
expect_no_offenses(<<-RUBY)
|
130
|
-
expect(action).to have_published_event.exactly(1).times
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
|
134
|
-
# Does not auto-correct if not part of the RSpec API
|
135
|
-
include_examples 'autocorrect',
|
136
|
-
'expect(foo).to have_published_event(:bar).exactly(2).times',
|
137
|
-
'expect(foo).to have_published_event(:bar).exactly(2).times'
|
138
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ReceiveNever do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags usage of `never`' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
expect(foo).to receive(:bar).never
|
9
|
-
^^^^^ Use `not_to receive` instead of `never`.
|
10
|
-
RUBY
|
11
|
-
|
12
|
-
expect_correction(<<-RUBY)
|
13
|
-
expect(foo).not_to receive(:bar)
|
14
|
-
RUBY
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'flags usage of `never` after `with`' do
|
18
|
-
expect_offense(<<-RUBY)
|
19
|
-
expect(foo).to receive(:bar).with(baz).never
|
20
|
-
^^^^^ Use `not_to receive` instead of `never`.
|
21
|
-
RUBY
|
22
|
-
|
23
|
-
expect_correction(<<-RUBY)
|
24
|
-
expect(foo).not_to receive(:bar).with(baz)
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'flags usage of `never` with `is_expected`' do
|
29
|
-
expect_offense(<<-RUBY)
|
30
|
-
is_expected.to receive(:bar).with(baz).never
|
31
|
-
^^^^^ Use `not_to receive` instead of `never`.
|
32
|
-
RUBY
|
33
|
-
|
34
|
-
expect_correction(<<-RUBY)
|
35
|
-
is_expected.not_to receive(:bar).with(baz)
|
36
|
-
RUBY
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'flags usage of `never` with `expect_any_instance_of`' do
|
40
|
-
expect_offense(<<-RUBY)
|
41
|
-
expect_any_instance_of(Foo).to receive(:bar).with(baz).never
|
42
|
-
^^^^^ Use `not_to receive` instead of `never`.
|
43
|
-
RUBY
|
44
|
-
|
45
|
-
expect_correction(<<-RUBY)
|
46
|
-
expect_any_instance_of(Foo).not_to receive(:bar).with(baz)
|
47
|
-
RUBY
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'allows method called `never`' do
|
51
|
-
expect_no_offenses(<<-RUBY)
|
52
|
-
expect(foo).to receive(:bar).with(Value.never)
|
53
|
-
expect(foo.never).to eq(bar.never)
|
54
|
-
is_expected.to be never
|
55
|
-
RUBY
|
56
|
-
end
|
57
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::RepeatedDescription do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'registers an offense for repeated descriptions' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe 'doing x' do
|
9
|
-
it "does x" do
|
10
|
-
^^^^^^^^^^^ Don't repeat descriptions within an example group.
|
11
|
-
end
|
12
|
-
|
13
|
-
it "does x" do
|
14
|
-
^^^^^^^^^^^ Don't repeat descriptions within an example group.
|
15
|
-
end
|
16
|
-
end
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'registers offense for repeated descriptions separated by a context' do
|
21
|
-
expect_offense(<<-RUBY)
|
22
|
-
describe 'doing x' do
|
23
|
-
it "does x" do
|
24
|
-
^^^^^^^^^^^ Don't repeat descriptions within an example group.
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'during some use case' do
|
28
|
-
it "does x" do
|
29
|
-
# this should be fine
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "does x" do
|
34
|
-
^^^^^^^^^^^ Don't repeat descriptions within an example group.
|
35
|
-
end
|
36
|
-
end
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores descriptions repeated in a shared context' do
|
41
|
-
expect_no_offenses(<<-RUBY)
|
42
|
-
describe 'doing x' do
|
43
|
-
it "does x" do
|
44
|
-
end
|
45
|
-
|
46
|
-
shared_context 'shared behavior' do
|
47
|
-
it "does x" do
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
RUBY
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'ignores repeated descriptions in a nested context' do
|
55
|
-
expect_no_offenses(<<-RUBY)
|
56
|
-
describe 'doing x' do
|
57
|
-
it "does x" do
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'in a certain use case' do
|
61
|
-
it "does x" do
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
RUBY
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not flag tests which do not contain description strings' do
|
69
|
-
expect_no_offenses(<<-RUBY)
|
70
|
-
describe 'doing x' do
|
71
|
-
it { foo }
|
72
|
-
it { bar }
|
73
|
-
end
|
74
|
-
RUBY
|
75
|
-
end
|
76
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::RepeatedExample do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'registers an offense for repeated example' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe 'doing x' do
|
9
|
-
it "does x" do
|
10
|
-
^^^^^^^^^^^^^^ Don't repeat examples within an example group.
|
11
|
-
expect(foo).to be(bar)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "does y" do
|
15
|
-
^^^^^^^^^^^^^^ Don't repeat examples within an example group.
|
16
|
-
expect(foo).to be(bar)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'does not register a violation if rspec tag magic is involved' do
|
23
|
-
expect_no_offenses(<<-RUBY)
|
24
|
-
describe 'doing x' do
|
25
|
-
it "does x" do
|
26
|
-
expect(foo).to be(bar)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "does y", :focus do
|
30
|
-
expect(foo).to be(bar)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'does not flag examples with different implementations' do
|
37
|
-
expect_no_offenses(<<-RUBY)
|
38
|
-
describe 'doing x' do
|
39
|
-
it "does x" do
|
40
|
-
expect(foo).to have_attribute(foo: 1)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "does y" do
|
44
|
-
expect(foo).to have_attribute(bar: 2)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
RUBY
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'does not flag examples when different its arguments are used' do
|
51
|
-
expect_no_offenses(<<-RUBY)
|
52
|
-
describe 'doing x' do
|
53
|
-
its(:x) { is_expected.to be_present }
|
54
|
-
its(:y) { is_expected.to be_present }
|
55
|
-
end
|
56
|
-
RUBY
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'does not flag repeated examples in different scopes' do
|
60
|
-
expect_no_offenses(<<-RUBY)
|
61
|
-
describe 'doing x' do
|
62
|
-
it "does x" do
|
63
|
-
expect(foo).to be(bar)
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when the scope changes' do
|
67
|
-
it 'does not flag anything' do
|
68
|
-
expect(foo).to be(bar)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
end
|
@@ -1,289 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ReturnFromStub, :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 `and_return`' do
|
11
|
-
let(:enforced_style) { 'and_return' }
|
12
|
-
|
13
|
-
it 'finds static values returned from block' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
it do
|
16
|
-
allow(Foo).to receive(:bar) { 42 }
|
17
|
-
^ Use `and_return` for static values.
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
|
21
|
-
expect_correction(<<-RUBY)
|
22
|
-
it do
|
23
|
-
allow(Foo).to receive(:bar).and_return(42)
|
24
|
-
end
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'finds empty values returned from block' do
|
29
|
-
expect_offense(<<-RUBY)
|
30
|
-
it do
|
31
|
-
allow(Foo).to receive(:bar) {}
|
32
|
-
^ Use `and_return` for static values.
|
33
|
-
end
|
34
|
-
RUBY
|
35
|
-
|
36
|
-
expect_correction(<<-RUBY)
|
37
|
-
it do
|
38
|
-
allow(Foo).to receive(:bar).and_return(nil)
|
39
|
-
end
|
40
|
-
RUBY
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'finds array with only static values returned from block' do
|
44
|
-
expect_offense(<<-RUBY)
|
45
|
-
it do
|
46
|
-
allow(Foo).to receive(:bar) { [42, 43] }
|
47
|
-
^ Use `and_return` for static values.
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
|
51
|
-
expect_correction(<<-RUBY)
|
52
|
-
it do
|
53
|
-
allow(Foo).to receive(:bar).and_return([42, 43])
|
54
|
-
end
|
55
|
-
RUBY
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'finds hash with only static values returned from block' do
|
59
|
-
expect_offense(<<-RUBY)
|
60
|
-
it do
|
61
|
-
allow(Foo).to receive(:bar) { {a: 42, b: 43} }
|
62
|
-
^ Use `and_return` for static values.
|
63
|
-
end
|
64
|
-
RUBY
|
65
|
-
|
66
|
-
expect_correction(<<-RUBY)
|
67
|
-
it do
|
68
|
-
allow(Foo).to receive(:bar).and_return({a: 42, b: 43})
|
69
|
-
end
|
70
|
-
RUBY
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'finds static values in a block when there are chained methods' do
|
74
|
-
expect_offense(<<-RUBY)
|
75
|
-
it do
|
76
|
-
allow(Question).to receive(:meaning).with(:universe) { 42 }
|
77
|
-
^ Use `and_return` for static values.
|
78
|
-
end
|
79
|
-
RUBY
|
80
|
-
|
81
|
-
expect_correction(<<-RUBY)
|
82
|
-
it do
|
83
|
-
allow(Question).to receive(:meaning).with(:universe).and_return(42)
|
84
|
-
end
|
85
|
-
RUBY
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'finds constants returned from block' do
|
89
|
-
expect_offense(<<-RUBY)
|
90
|
-
it do
|
91
|
-
allow(Foo).to receive(:bar) { Life::MEANING }
|
92
|
-
^ Use `and_return` for static values.
|
93
|
-
end
|
94
|
-
RUBY
|
95
|
-
|
96
|
-
expect_correction(<<-RUBY)
|
97
|
-
it do
|
98
|
-
allow(Foo).to receive(:bar).and_return(Life::MEANING)
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'finds nested constants returned from block' do
|
104
|
-
expect_offense(<<-RUBY)
|
105
|
-
it do
|
106
|
-
allow(Foo).to receive(:bar) { {Life::MEANING => 42} }
|
107
|
-
^ Use `and_return` for static values.
|
108
|
-
end
|
109
|
-
RUBY
|
110
|
-
|
111
|
-
expect_correction(<<-RUBY)
|
112
|
-
it do
|
113
|
-
allow(Foo).to receive(:bar).and_return({Life::MEANING => 42})
|
114
|
-
end
|
115
|
-
RUBY
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'ignores dynamic values returned from block' do
|
119
|
-
expect_no_offenses(<<-RUBY)
|
120
|
-
it do
|
121
|
-
allow(Foo).to receive(:bar) { baz }
|
122
|
-
end
|
123
|
-
RUBY
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'ignores variables return from block' do
|
127
|
-
expect_no_offenses(<<-RUBY)
|
128
|
-
it do
|
129
|
-
$bar = 42
|
130
|
-
baz = 123
|
131
|
-
allow(Foo).to receive(:bar) { $bar }
|
132
|
-
allow(Foo).to receive(:baz) { baz }
|
133
|
-
end
|
134
|
-
RUBY
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'ignores array with dynamic values returned from block' do
|
138
|
-
expect_no_offenses(<<-RUBY)
|
139
|
-
it do
|
140
|
-
allow(Foo).to receive(:bar) { [42, baz] }
|
141
|
-
end
|
142
|
-
RUBY
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'ignores hash with dynamic values returned from block' do
|
146
|
-
expect_no_offenses(<<-RUBY)
|
147
|
-
it do
|
148
|
-
allow(Foo).to receive(:bar) { {a: 42, b: baz} }
|
149
|
-
end
|
150
|
-
RUBY
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'ignores block returning string with interpolation' do
|
154
|
-
expect_no_offenses(<<-RUBY)
|
155
|
-
it do
|
156
|
-
bar = 42
|
157
|
-
allow(Foo).to receive(:bar) { "You called \#{bar}" }
|
158
|
-
end
|
159
|
-
RUBY
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'finds concatenated strings with no variables' do
|
163
|
-
expect_offense(<<-RUBY)
|
164
|
-
it do
|
165
|
-
allow(Foo).to receive(:bar) do
|
166
|
-
^^ Use `and_return` for static values.
|
167
|
-
"You called" \
|
168
|
-
"me"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
RUBY
|
172
|
-
|
173
|
-
expect_correction(<<-RUBY)
|
174
|
-
it do
|
175
|
-
allow(Foo).to receive(:bar).and_return("You called" \
|
176
|
-
"me")
|
177
|
-
end
|
178
|
-
RUBY
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'ignores stubs without return value' do
|
182
|
-
expect_no_offenses(<<-RUBY)
|
183
|
-
it do
|
184
|
-
allow(Foo).to receive(:bar)
|
185
|
-
end
|
186
|
-
RUBY
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'handles stubs in a method' do
|
190
|
-
expect_no_offenses(<<-RUBY)
|
191
|
-
def stub_foo
|
192
|
-
allow(Foo).to receive(:bar)
|
193
|
-
end
|
194
|
-
RUBY
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'with EnforcedStyle `block`' do
|
199
|
-
let(:enforced_style) { 'block' }
|
200
|
-
|
201
|
-
it 'finds static values returned from method' do
|
202
|
-
expect_offense(<<-RUBY)
|
203
|
-
it do
|
204
|
-
allow(Foo).to receive(:bar).and_return(42)
|
205
|
-
^^^^^^^^^^ Use block for static values.
|
206
|
-
end
|
207
|
-
RUBY
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'finds static values returned from chained method' do
|
211
|
-
expect_offense(<<-RUBY)
|
212
|
-
it do
|
213
|
-
allow(Foo).to receive(:bar).with(1).and_return(42)
|
214
|
-
^^^^^^^^^^ Use block for static values.
|
215
|
-
end
|
216
|
-
RUBY
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'ignores dynamic values returned from method' do
|
220
|
-
expect_no_offenses(<<-RUBY)
|
221
|
-
it do
|
222
|
-
allow(Foo).to receive(:bar).and_return(baz)
|
223
|
-
end
|
224
|
-
RUBY
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'ignores string with interpolation returned from method' do
|
228
|
-
expect_no_offenses(<<-RUBY)
|
229
|
-
it do
|
230
|
-
bar = 42
|
231
|
-
allow(Foo).to receive(:bar).and_return("You called \#{bar}")
|
232
|
-
end
|
233
|
-
RUBY
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'ignores multiple values being returned from method' do
|
237
|
-
expect_no_offenses(<<-RUBY)
|
238
|
-
it do
|
239
|
-
allow(Foo).to receive(:bar).and_return(42, 43, 44)
|
240
|
-
end
|
241
|
-
RUBY
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'finds hash with only static values returned from method' do
|
245
|
-
expect_offense(<<-RUBY)
|
246
|
-
allow(Foo).to receive(:bar).and_return({ foo: 42 })
|
247
|
-
^^^^^^^^^^ Use block for static values.
|
248
|
-
allow(Foo).to receive(:bar).and_return(foo: 42)
|
249
|
-
^^^^^^^^^^ Use block for static values.
|
250
|
-
allow(Foo).to receive(:bar).and_return(
|
251
|
-
^^^^^^^^^^ Use block for static values.
|
252
|
-
a: 42,
|
253
|
-
b: 43
|
254
|
-
)
|
255
|
-
RUBY
|
256
|
-
|
257
|
-
expect_correction(<<-RUBY) # Not perfect, but good enough.
|
258
|
-
allow(Foo).to receive(:bar) { { foo: 42 } }
|
259
|
-
allow(Foo).to receive(:bar) { { foo: 42 } }
|
260
|
-
allow(Foo).to receive(:bar) { { a: 42,
|
261
|
-
b: 43 } }
|
262
|
-
RUBY
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'finds nil returned from method' do
|
266
|
-
expect_offense(<<-RUBY)
|
267
|
-
allow(Foo).to receive(:bar).and_return(nil)
|
268
|
-
^^^^^^^^^^ Use block for static values.
|
269
|
-
RUBY
|
270
|
-
|
271
|
-
expect_correction(<<-RUBY)
|
272
|
-
allow(Foo).to receive(:bar) { nil }
|
273
|
-
RUBY
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'finds concatenated strings with no variables' do
|
277
|
-
expect_offense(<<-RUBY)
|
278
|
-
allow(Foo).to receive(:bar).and_return('You called ' \\
|
279
|
-
^^^^^^^^^^ Use block for static values.
|
280
|
-
'me')
|
281
|
-
RUBY
|
282
|
-
|
283
|
-
expect_correction(<<-RUBY)
|
284
|
-
allow(Foo).to receive(:bar) { 'You called ' \\
|
285
|
-
'me' }
|
286
|
-
RUBY
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|