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,173 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style }
|
8
|
-
end
|
9
|
-
|
10
|
-
shared_examples 'ignored hooks' do
|
11
|
-
it 'ignores :context and :suite' do
|
12
|
-
expect_no_offenses(<<-RUBY)
|
13
|
-
before(:suite) { true }
|
14
|
-
after(:suite) { true }
|
15
|
-
before(:context) { true }
|
16
|
-
after(:context) { true }
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'ignores hooks with more than one argument' do
|
21
|
-
expect_no_offenses(<<-RUBY)
|
22
|
-
before(:each, :something_custom) { true }
|
23
|
-
RUBY
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'ignores non-rspec hooks' do
|
27
|
-
expect_no_offenses(<<-RUBY)
|
28
|
-
setup(:each) { true }
|
29
|
-
RUBY
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
shared_examples 'hook autocorrect' do |output|
|
34
|
-
include_examples 'autocorrect', 'before(:each) { }', output
|
35
|
-
include_examples 'autocorrect', 'before(:example) { }', output
|
36
|
-
include_examples 'autocorrect', 'before { }', output
|
37
|
-
|
38
|
-
include_examples 'autocorrect', 'config.before(:each) { }',
|
39
|
-
'config.' + output
|
40
|
-
include_examples 'autocorrect', 'config.before(:example) { }',
|
41
|
-
'config.' + output
|
42
|
-
include_examples 'autocorrect', 'config.before { }',
|
43
|
-
'config.' + output
|
44
|
-
end
|
45
|
-
|
46
|
-
shared_examples 'an example hook' do
|
47
|
-
include_examples 'ignored hooks'
|
48
|
-
include_examples 'detects style', 'before(:each) { foo }', 'each'
|
49
|
-
include_examples 'detects style', 'before(:example) { foo }', 'example'
|
50
|
-
include_examples 'detects style', 'before { foo }', 'implicit'
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when EnforcedStyle is :implicit' do
|
54
|
-
let(:enforced_style) { :implicit }
|
55
|
-
|
56
|
-
it 'detects :each for hooks' do
|
57
|
-
expect_offense(<<-RUBY)
|
58
|
-
before(:each) { true }
|
59
|
-
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
60
|
-
after(:each) { true }
|
61
|
-
^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
62
|
-
around(:each) { true }
|
63
|
-
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
64
|
-
config.after(:each) { true }
|
65
|
-
^^^^^^^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
66
|
-
RUBY
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'detects :example for hooks' do
|
70
|
-
expect_offense(<<-RUBY)
|
71
|
-
before(:example) { true }
|
72
|
-
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
73
|
-
after(:example) { true }
|
74
|
-
^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
75
|
-
around(:example) { true }
|
76
|
-
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
77
|
-
config.before(:example) { true }
|
78
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
79
|
-
RUBY
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'does not flag hooks without default scopes' do
|
83
|
-
expect_no_offenses(<<-RUBY)
|
84
|
-
before { true }
|
85
|
-
after { true }
|
86
|
-
config.before { true }
|
87
|
-
RUBY
|
88
|
-
end
|
89
|
-
|
90
|
-
include_examples 'an example hook'
|
91
|
-
include_examples 'hook autocorrect', 'before { }'
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'when EnforcedStyle is :each' do
|
95
|
-
let(:enforced_style) { :each }
|
96
|
-
|
97
|
-
it 'detects :each for hooks' do
|
98
|
-
expect_no_offenses(<<-RUBY)
|
99
|
-
before(:each) { true }
|
100
|
-
after(:each) { true }
|
101
|
-
around(:each) { true }
|
102
|
-
config.before(:each) { true }
|
103
|
-
RUBY
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'detects :example for hooks' do
|
107
|
-
expect_offense(<<-RUBY)
|
108
|
-
before(:example) { true }
|
109
|
-
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
110
|
-
after(:example) { true }
|
111
|
-
^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
112
|
-
around(:example) { true }
|
113
|
-
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
114
|
-
config.before(:example) { true }
|
115
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
116
|
-
RUBY
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'detects hooks without default scopes' do
|
120
|
-
expect_offense(<<-RUBY)
|
121
|
-
before { true }
|
122
|
-
^^^^^^ Use `:each` for RSpec hooks.
|
123
|
-
after { true }
|
124
|
-
^^^^^ Use `:each` for RSpec hooks.
|
125
|
-
config.before { true }
|
126
|
-
^^^^^^ Use `:each` for RSpec hooks.
|
127
|
-
RUBY
|
128
|
-
end
|
129
|
-
|
130
|
-
include_examples 'an example hook'
|
131
|
-
include_examples 'hook autocorrect', 'before(:each) { }'
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'when EnforcedStyle is :example' do
|
135
|
-
let(:enforced_style) { :example }
|
136
|
-
|
137
|
-
it 'detects :example for hooks' do
|
138
|
-
expect_no_offenses(<<-RUBY)
|
139
|
-
before(:example) { true }
|
140
|
-
after(:example) { true }
|
141
|
-
around(:example) { true }
|
142
|
-
config.before(:example) { true }
|
143
|
-
RUBY
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'detects :each for hooks' do
|
147
|
-
expect_offense(<<-RUBY)
|
148
|
-
before(:each) { true }
|
149
|
-
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
150
|
-
after(:each) { true }
|
151
|
-
^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
152
|
-
around(:each) { true }
|
153
|
-
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
154
|
-
config.before(:each) { true }
|
155
|
-
^^^^^^^^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
156
|
-
RUBY
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'does not flag hooks without default scopes' do
|
160
|
-
expect_offense(<<-RUBY)
|
161
|
-
before { true }
|
162
|
-
^^^^^^ Use `:example` for RSpec hooks.
|
163
|
-
after { true }
|
164
|
-
^^^^^ Use `:example` for RSpec hooks.
|
165
|
-
config.before { true }
|
166
|
-
^^^^^^ Use `:example` for RSpec hooks.
|
167
|
-
RUBY
|
168
|
-
end
|
169
|
-
|
170
|
-
include_examples 'an example hook'
|
171
|
-
include_examples 'hook autocorrect', 'before(:example) { }'
|
172
|
-
end
|
173
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::HooksBeforeExamples do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags `before` after `it`' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
RSpec.describe User do
|
9
|
-
it { is_expected.to be_after_before_hook }
|
10
|
-
before { setup }
|
11
|
-
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
|
15
|
-
expect_correction(<<-RUBY)
|
16
|
-
RSpec.describe User do
|
17
|
-
before { setup }
|
18
|
-
it { is_expected.to be_after_before_hook }
|
19
|
-
end
|
20
|
-
RUBY
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'flags `before` after `context`' do
|
24
|
-
expect_offense(<<-RUBY)
|
25
|
-
RSpec.describe User do
|
26
|
-
context 'a context' do
|
27
|
-
it { is_expected.to be_after_before_hook }
|
28
|
-
end
|
29
|
-
|
30
|
-
before { setup }
|
31
|
-
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
|
35
|
-
expect_correction(<<-RUBY)
|
36
|
-
RSpec.describe User do
|
37
|
-
before { setup }
|
38
|
-
context 'a context' do
|
39
|
-
it { is_expected.to be_after_before_hook }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'flags `before` after `include_examples`' do
|
47
|
-
expect_offense(<<-RUBY)
|
48
|
-
RSpec.describe User do
|
49
|
-
include_examples('should be after before-hook')
|
50
|
-
|
51
|
-
before { setup }
|
52
|
-
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
53
|
-
end
|
54
|
-
RUBY
|
55
|
-
|
56
|
-
expect_correction(<<-RUBY)
|
57
|
-
RSpec.describe User do
|
58
|
-
before { setup }
|
59
|
-
include_examples('should be after before-hook')
|
60
|
-
|
61
|
-
end
|
62
|
-
RUBY
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'flags `after` after an example' do
|
66
|
-
expect_offense(<<-RUBY)
|
67
|
-
RSpec.describe User do
|
68
|
-
it { is_expected.to be_after_after_hook }
|
69
|
-
after { cleanup }
|
70
|
-
^^^^^^^^^^^^^^^^^ Move `after` above the examples in the group.
|
71
|
-
end
|
72
|
-
RUBY
|
73
|
-
|
74
|
-
expect_correction(<<-RUBY)
|
75
|
-
RSpec.describe User do
|
76
|
-
after { cleanup }
|
77
|
-
it { is_expected.to be_after_after_hook }
|
78
|
-
end
|
79
|
-
RUBY
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'flags scoped hook after an example' do
|
83
|
-
expect_offense(<<-RUBY)
|
84
|
-
RSpec.describe User do
|
85
|
-
it { is_expected.to be_after_before_hook }
|
86
|
-
before(:each) { cleanup }
|
87
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
88
|
-
end
|
89
|
-
RUBY
|
90
|
-
|
91
|
-
expect_correction(<<-RUBY)
|
92
|
-
RSpec.describe User do
|
93
|
-
before(:each) { cleanup }
|
94
|
-
it { is_expected.to be_after_before_hook }
|
95
|
-
end
|
96
|
-
RUBY
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'does not flag hooks before the examples' do
|
100
|
-
expect_no_offenses(<<-RUBY)
|
101
|
-
RSpec.describe User do
|
102
|
-
before(:each) { setup }
|
103
|
-
after(:each) { cleanup }
|
104
|
-
|
105
|
-
it { is_expected.to be_after_hooks }
|
106
|
-
|
107
|
-
context 'a context' do
|
108
|
-
it { is_expected.to work }
|
109
|
-
end
|
110
|
-
|
111
|
-
include_examples('everything is fine')
|
112
|
-
end
|
113
|
-
RUBY
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'does not flag `before` in a nested context' do
|
117
|
-
expect_no_offenses(<<-RUBY)
|
118
|
-
RSpec.describe User do
|
119
|
-
before { setup }
|
120
|
-
|
121
|
-
context 'something else' do
|
122
|
-
before { additional_setup }
|
123
|
-
it { is_expected.to work }
|
124
|
-
end
|
125
|
-
|
126
|
-
include_examples('everything is fine')
|
127
|
-
end
|
128
|
-
RUBY
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'allows inclusion of context before hooks' do
|
132
|
-
expect_no_offenses(<<-RUBY)
|
133
|
-
RSpec.describe User do
|
134
|
-
include_context 'special user'
|
135
|
-
|
136
|
-
before { setup }
|
137
|
-
end
|
138
|
-
RUBY
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'ignores single-line example blocks' do
|
142
|
-
expect_no_offenses(<<-RUBY)
|
143
|
-
RSpec.describe User do
|
144
|
-
include_examples 'special user' do
|
145
|
-
before { setup }
|
146
|
-
end
|
147
|
-
end
|
148
|
-
RUBY
|
149
|
-
end
|
150
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::ImplicitBlockExpectation do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags lambda in subject' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe do
|
9
|
-
subject { -> { boom } }
|
10
|
-
it { is_expected.to change { something }.to(new_value) }
|
11
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'ignores non-lambda subject' do
|
17
|
-
expect_no_offenses(<<-RUBY)
|
18
|
-
describe do
|
19
|
-
subject { 'normal' }
|
20
|
-
it { is_expected.to eq(something) }
|
21
|
-
end
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'flags lambda in subject!' do
|
26
|
-
expect_offense(<<-RUBY)
|
27
|
-
describe do
|
28
|
-
subject! { -> { boom } }
|
29
|
-
it { is_expected.to change { something }.to(new_value) }
|
30
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
31
|
-
end
|
32
|
-
RUBY
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'flags literal lambda' do
|
36
|
-
expect_offense(<<-RUBY)
|
37
|
-
describe do
|
38
|
-
subject! { lambda { boom } }
|
39
|
-
it { is_expected.to change { something }.to(new_value) }
|
40
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
41
|
-
end
|
42
|
-
RUBY
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'flags proc' do
|
46
|
-
expect_offense(<<-RUBY)
|
47
|
-
describe do
|
48
|
-
subject! { proc { boom } }
|
49
|
-
it { is_expected.to change { something }.to(new_value) }
|
50
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'flags Proc.new' do
|
56
|
-
expect_offense(<<-RUBY)
|
57
|
-
describe do
|
58
|
-
subject! { Proc.new { boom } }
|
59
|
-
it { is_expected.to change { something }.to(new_value) }
|
60
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
61
|
-
end
|
62
|
-
RUBY
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'flags named subject' do
|
66
|
-
expect_offense(<<-RUBY)
|
67
|
-
describe do
|
68
|
-
subject(:name) { -> { boom } }
|
69
|
-
it { is_expected.to change { something }.to(new_value) }
|
70
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
71
|
-
end
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'flags when subject is defined in the outer example group' do
|
76
|
-
expect_offense(<<-RUBY)
|
77
|
-
describe do
|
78
|
-
subject { -> { boom } }
|
79
|
-
context do
|
80
|
-
it { is_expected.to change { something }.to(new_value) }
|
81
|
-
^^^^^^^^^^^ Avoid implicit block expectations.
|
82
|
-
end
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'ignores normal local subject' do
|
88
|
-
expect_no_offenses(<<-RUBY)
|
89
|
-
describe do
|
90
|
-
subject { -> { boom } }
|
91
|
-
context do
|
92
|
-
subject { 'normal' }
|
93
|
-
it { is_expected.to eq(something) }
|
94
|
-
end
|
95
|
-
end
|
96
|
-
RUBY
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'ignores named subject with deeply nested lambda' do
|
100
|
-
expect_no_offenses(<<-RUBY)
|
101
|
-
describe do
|
102
|
-
subject { {hash: -> { boom }} }
|
103
|
-
it { is_expected.to be(something) }
|
104
|
-
end
|
105
|
-
RUBY
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'flags with `should` as implicit subject' do
|
109
|
-
expect_offense(<<-RUBY)
|
110
|
-
describe do
|
111
|
-
subject { -> { boom } }
|
112
|
-
it { should change { something }.to(new_value) }
|
113
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid implicit block expectations.
|
114
|
-
end
|
115
|
-
RUBY
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'flags with `should_not` as implicit subject' do
|
119
|
-
expect_offense(<<-RUBY)
|
120
|
-
describe do
|
121
|
-
subject { -> { boom } }
|
122
|
-
it { should_not change { something }.to(new_value) }
|
123
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid implicit block expectations.
|
124
|
-
end
|
125
|
-
RUBY
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'ignores when there is no subject defined' do
|
129
|
-
expect_no_offenses(<<-RUBY)
|
130
|
-
shared_examples 'subject is defined somewhere else' do
|
131
|
-
it { is_expected.to change { something }.to(new_value) }
|
132
|
-
end
|
133
|
-
RUBY
|
134
|
-
end
|
135
|
-
end
|