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,186 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::Pending do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags xcontext' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
xcontext 'test' do
|
9
|
-
^^^^^^^^^^^^^^^ Pending spec found.
|
10
|
-
end
|
11
|
-
RUBY
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'flags xdescribe' do
|
15
|
-
expect_offense(<<-RUBY)
|
16
|
-
xdescribe 'test' do
|
17
|
-
^^^^^^^^^^^^^^^^ Pending spec found.
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'flags xexample' do
|
23
|
-
expect_offense(<<-RUBY)
|
24
|
-
xexample 'test' do
|
25
|
-
^^^^^^^^^^^^^^^ Pending spec found.
|
26
|
-
end
|
27
|
-
RUBY
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'flags xfeature' do
|
31
|
-
expect_offense(<<-RUBY)
|
32
|
-
xfeature 'test' do
|
33
|
-
^^^^^^^^^^^^^^^ Pending spec found.
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'flags xit' do
|
39
|
-
expect_offense(<<-RUBY)
|
40
|
-
xit 'test' do
|
41
|
-
^^^^^^^^^^ Pending spec found.
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'flags xscenario' do
|
47
|
-
expect_offense(<<-RUBY)
|
48
|
-
xscenario 'test' do
|
49
|
-
^^^^^^^^^^^^^^^^ Pending spec found.
|
50
|
-
end
|
51
|
-
RUBY
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'flags xspecify' do
|
55
|
-
expect_offense(<<-RUBY)
|
56
|
-
xspecify 'test' do
|
57
|
-
^^^^^^^^^^^^^^^ Pending spec found.
|
58
|
-
end
|
59
|
-
RUBY
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'flags skip inside of an it' do
|
63
|
-
expect_offense(<<-RUBY)
|
64
|
-
it 'test' do
|
65
|
-
skip
|
66
|
-
^^^^ Pending spec found.
|
67
|
-
end
|
68
|
-
RUBY
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'flags skip blocks' do
|
72
|
-
expect_offense(<<-RUBY)
|
73
|
-
skip 'test' do
|
74
|
-
^^^^^^^^^^^ Pending spec found.
|
75
|
-
end
|
76
|
-
RUBY
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'flags blocks with skip symbol metadata' do
|
80
|
-
expect_offense(<<-RUBY)
|
81
|
-
it 'test', :skip do
|
82
|
-
^^^^^^^^^^^^^^^^ Pending spec found.
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'flags describe with skip symbol metadata' do
|
88
|
-
expect_offense(<<-RUBY)
|
89
|
-
RSpec.describe 'test', :skip do
|
90
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Pending spec found.
|
91
|
-
end
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'flags blocks with pending symbol metadata' do
|
96
|
-
expect_offense(<<-RUBY)
|
97
|
-
it 'test', :pending do
|
98
|
-
^^^^^^^^^^^^^^^^^^^ Pending spec found.
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'flags blocks with skip: true metadata' do
|
104
|
-
expect_offense(<<-RUBY)
|
105
|
-
it 'test', skip: true do
|
106
|
-
^^^^^^^^^^^^^^^^^^^^^ Pending spec found.
|
107
|
-
end
|
108
|
-
RUBY
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'flags pending blocks' do
|
112
|
-
expect_offense(<<-RUBY)
|
113
|
-
pending 'test' do
|
114
|
-
^^^^^^^^^^^^^^ Pending spec found.
|
115
|
-
end
|
116
|
-
RUBY
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'flags pending examples when receiver is explicit' do
|
120
|
-
expect_offense(<<-RUBY)
|
121
|
-
RSpec.xit 'test' do
|
122
|
-
^^^^^^^^^^^^^^^^ Pending spec found.
|
123
|
-
end
|
124
|
-
RUBY
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'does not flag describe' do
|
128
|
-
expect_no_offenses(<<-RUBY)
|
129
|
-
describe 'test' do; end
|
130
|
-
RUBY
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'does not flag example' do
|
134
|
-
expect_no_offenses(<<-RUBY)
|
135
|
-
example 'test' do; end
|
136
|
-
RUBY
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'does not flag scenario' do
|
140
|
-
expect_no_offenses(<<-RUBY)
|
141
|
-
scenario 'test' do; end
|
142
|
-
RUBY
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'does not flag specify' do
|
146
|
-
expect_no_offenses(<<-RUBY)
|
147
|
-
specify 'test' do; end
|
148
|
-
RUBY
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'does not flag feature' do
|
152
|
-
expect_no_offenses(<<-RUBY)
|
153
|
-
feature 'test' do; end
|
154
|
-
RUBY
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'does not flag context' do
|
158
|
-
expect_no_offenses(<<-RUBY)
|
159
|
-
context 'test' do; end
|
160
|
-
RUBY
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'does not flag it' do
|
164
|
-
expect_no_offenses(<<-RUBY)
|
165
|
-
it 'test' do; end
|
166
|
-
RUBY
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'does not flag it with skip: false metadata' do
|
170
|
-
expect_no_offenses(<<-RUBY)
|
171
|
-
it 'test', skip: false do; end
|
172
|
-
RUBY
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'does not flag example_group' do
|
176
|
-
expect_no_offenses(<<-RUBY)
|
177
|
-
example_group 'test' do; end
|
178
|
-
RUBY
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'does not flag method called pending' do
|
182
|
-
expect_no_offenses(<<-RUBY)
|
183
|
-
subject { Project.pending }
|
184
|
-
RUBY
|
185
|
-
end
|
186
|
-
end
|
@@ -1,354 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::PredicateMatcher, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style,
|
8
|
-
'Strict' => strict }
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'when enforced style is `inflected`' do
|
12
|
-
let(:enforced_style) { 'inflected' }
|
13
|
-
|
14
|
-
shared_examples 'inflected common' do
|
15
|
-
it 'registers an offense for a predicate method in actual' do
|
16
|
-
expect_offense(<<-RUBY)
|
17
|
-
expect(foo.empty?).to be_truthy
|
18
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
19
|
-
expect(foo.empty?).not_to be_truthy
|
20
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
21
|
-
expect(foo.empty?).to_not be_truthy
|
22
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
23
|
-
expect(foo.empty?).to be_falsey
|
24
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'registers an offense for a predicate method with built-in equiv' do
|
29
|
-
expect_offense(<<-RUBY)
|
30
|
-
expect(foo.exist?).to be_truthy
|
31
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `exist` matcher over `exist?`.
|
32
|
-
expect(foo.exists?).to be_truthy
|
33
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `exist` matcher over `exists?`.
|
34
|
-
expect(foo.has_something?).to be_truthy
|
35
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `have_something` matcher over `has_something?`.
|
36
|
-
expect(foo.include?(something)).to be_truthy
|
37
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `include` matcher over `include?`.
|
38
|
-
expect(foo.respond_to?(:bar)).to be_truthy
|
39
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `respond_to` matcher over `respond_to?`.
|
40
|
-
RUBY
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'registers an offense for a predicate method with argument' do
|
44
|
-
expect_offense(<<-RUBY)
|
45
|
-
expect(foo.something?('foo')).to be_truthy
|
46
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_something` matcher over `something?`.
|
47
|
-
expect(foo.something?('foo', 'bar')).to be_truthy
|
48
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_something` matcher over `something?`.
|
49
|
-
expect(foo.has_key?('foo')).to be_truthy
|
50
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `have_key` matcher over `has_key?`.
|
51
|
-
RUBY
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'registers an offense for a predicate method with a block' do
|
55
|
-
expect_offense(<<-RUBY)
|
56
|
-
expect(foo.all?(&:present?)).to be_truthy
|
57
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_all` matcher over `all?`.
|
58
|
-
expect(foo.all? { |x| x.present? }).to be_truthy
|
59
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_all` matcher over `all?`.
|
60
|
-
expect(foo.all? { present }).to be_truthy
|
61
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_all` matcher over `all?`.
|
62
|
-
expect(foo.something?(x) { |y| y.present? }).to be_truthy
|
63
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_something` matcher over `something?`.
|
64
|
-
RUBY
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'accepts a predicate method that is not ckeced true/false' do
|
68
|
-
expect_no_offenses(<<-RUBY)
|
69
|
-
expect(foo.something?).to eq "something"
|
70
|
-
expect(foo.has_something?).to eq "something"
|
71
|
-
RUBY
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'accepts non-predicate method' do
|
75
|
-
expect_no_offenses(<<-RUBY)
|
76
|
-
expect(foo.something).to be(true)
|
77
|
-
expect(foo.has_something).to be(true)
|
78
|
-
RUBY
|
79
|
-
end
|
80
|
-
|
81
|
-
include_examples 'autocorrect',
|
82
|
-
'expect(foo.empty?).to be_truthy',
|
83
|
-
'expect(foo).to be_empty'
|
84
|
-
include_examples 'autocorrect',
|
85
|
-
'expect(foo.empty?).not_to be_truthy',
|
86
|
-
'expect(foo).not_to be_empty'
|
87
|
-
include_examples 'autocorrect',
|
88
|
-
'expect(foo.empty?).to_not be_truthy',
|
89
|
-
'expect(foo).not_to be_empty'
|
90
|
-
include_examples 'autocorrect',
|
91
|
-
'expect(foo.empty?).to be_falsey',
|
92
|
-
'expect(foo).not_to be_empty'
|
93
|
-
include_examples 'autocorrect',
|
94
|
-
'expect(foo.empty?).not_to be_falsey',
|
95
|
-
'expect(foo).to be_empty'
|
96
|
-
include_examples 'autocorrect',
|
97
|
-
'expect(foo.empty?).not_to a_truthy_value',
|
98
|
-
'expect(foo).not_to be_empty'
|
99
|
-
|
100
|
-
include_examples 'autocorrect',
|
101
|
-
'expect(foo.is_a?(Array)).to be_truthy',
|
102
|
-
'expect(foo).to be_a(Array)'
|
103
|
-
|
104
|
-
include_examples 'autocorrect',
|
105
|
-
'expect(foo.instance_of?(Array)).to be_truthy',
|
106
|
-
'expect(foo).to be_an_instance_of(Array)'
|
107
|
-
|
108
|
-
include_examples 'autocorrect',
|
109
|
-
'expect(foo.has_something?).to be_truthy',
|
110
|
-
'expect(foo).to have_something'
|
111
|
-
include_examples 'autocorrect',
|
112
|
-
'expect(foo.has_something?).not_to be_truthy',
|
113
|
-
'expect(foo).not_to have_something'
|
114
|
-
include_examples 'autocorrect',
|
115
|
-
'expect(foo.include?(something)).to be_truthy',
|
116
|
-
'expect(foo).to include(something)'
|
117
|
-
include_examples 'autocorrect',
|
118
|
-
'expect(foo.respond_to?(:bar)).to be_truthy',
|
119
|
-
'expect(foo).to respond_to(:bar)'
|
120
|
-
include_examples 'autocorrect',
|
121
|
-
'expect(foo.exists?).to be_truthy',
|
122
|
-
'expect(foo).to exist'
|
123
|
-
|
124
|
-
include_examples 'autocorrect',
|
125
|
-
'expect(foo.something?()).to be_truthy',
|
126
|
-
'expect(foo).to be_something()'
|
127
|
-
include_examples 'autocorrect',
|
128
|
-
'expect(foo.something? 1, 2).to be_truthy',
|
129
|
-
'expect(foo).to be_something 1, 2'
|
130
|
-
include_examples 'autocorrect',
|
131
|
-
'expect(foo.has_key?("foo")).to be_truthy',
|
132
|
-
'expect(foo).to have_key("foo")'
|
133
|
-
include_examples 'autocorrect',
|
134
|
-
'expect(foo.something?(1, 2)).to be_truthy',
|
135
|
-
'expect(foo).to be_something(1, 2)'
|
136
|
-
|
137
|
-
include_examples 'autocorrect',
|
138
|
-
'expect(foo.all? { |x| x.present? }).to be_truthy',
|
139
|
-
'expect(foo).to be_all { |x| x.present? }'
|
140
|
-
include_examples 'autocorrect',
|
141
|
-
'expect(foo.all?(n) { |x| x.present? }).to be_truthy',
|
142
|
-
'expect(foo).to be_all(n) { |x| x.present? }'
|
143
|
-
include_examples 'autocorrect',
|
144
|
-
'expect(foo.all? { present }).to be_truthy',
|
145
|
-
'expect(foo).to be_all { present }'
|
146
|
-
include_examples 'autocorrect',
|
147
|
-
'expect(foo.all? { }).to be_truthy',
|
148
|
-
'expect(foo).to be_all { }'
|
149
|
-
include_examples 'autocorrect',
|
150
|
-
<<-BEFORE, <<-AFTER
|
151
|
-
expect(foo.all? do |x|
|
152
|
-
x + 1
|
153
|
-
x >= 2
|
154
|
-
end).to be_truthy
|
155
|
-
BEFORE
|
156
|
-
expect(foo).to be_all do |x|
|
157
|
-
x + 1
|
158
|
-
x >= 2
|
159
|
-
end
|
160
|
-
AFTER
|
161
|
-
include_examples 'autocorrect',
|
162
|
-
'expect(foo.all? do; end).to be_truthy',
|
163
|
-
'expect(foo).to be_all do; end'
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'when strict is true' do
|
167
|
-
let(:strict) { true }
|
168
|
-
|
169
|
-
include_examples 'inflected common'
|
170
|
-
|
171
|
-
it 'accepts strict checking boolean matcher' do
|
172
|
-
expect_no_offenses(<<-RUBY)
|
173
|
-
expect(foo.empty?).to eq(true)
|
174
|
-
expect(foo.empty?).to be(true)
|
175
|
-
expect(foo.empty?).to be(false)
|
176
|
-
expect(foo.empty?).not_to be true
|
177
|
-
expect(foo.empty?).not_to be false
|
178
|
-
RUBY
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context 'when strict is false' do
|
183
|
-
let(:strict) { false }
|
184
|
-
|
185
|
-
include_examples 'inflected common'
|
186
|
-
|
187
|
-
it 'registers an offense for a predicate method in actual' do
|
188
|
-
expect_offense(<<-RUBY)
|
189
|
-
expect(foo.empty?).to eq(true)
|
190
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
191
|
-
expect(foo.empty?).to be(true)
|
192
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
193
|
-
expect(foo.empty?).to be(false)
|
194
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
195
|
-
expect(foo.empty?).not_to be true
|
196
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
197
|
-
expect(foo.empty?).not_to be false
|
198
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `be_empty` matcher over `empty?`.
|
199
|
-
RUBY
|
200
|
-
end
|
201
|
-
|
202
|
-
include_examples 'autocorrect',
|
203
|
-
'expect(foo.empty?).to eq(true)',
|
204
|
-
'expect(foo).to be_empty'
|
205
|
-
include_examples 'autocorrect',
|
206
|
-
'expect(foo.empty?).to eq(false)',
|
207
|
-
'expect(foo).not_to be_empty'
|
208
|
-
include_examples 'autocorrect',
|
209
|
-
'expect(foo.empty?).to be(true)',
|
210
|
-
'expect(foo).to be_empty'
|
211
|
-
include_examples 'autocorrect',
|
212
|
-
'expect(foo.empty?).to be(false)',
|
213
|
-
'expect(foo).not_to be_empty'
|
214
|
-
include_examples 'autocorrect',
|
215
|
-
'expect(foo.empty?).not_to be(true)',
|
216
|
-
'expect(foo).not_to be_empty'
|
217
|
-
include_examples 'autocorrect',
|
218
|
-
'expect(foo.empty?).not_to be(false)',
|
219
|
-
'expect(foo).to be_empty'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'when enforced style is `explicit`' do
|
224
|
-
let(:enforced_style) { 'explicit' }
|
225
|
-
|
226
|
-
shared_examples 'explicit common' do
|
227
|
-
it 'registers an offense for a predicate mather' do
|
228
|
-
expect_offense(<<-RUBY)
|
229
|
-
expect(foo).to be_empty
|
230
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `empty?` over `be_empty` matcher.
|
231
|
-
expect(foo).not_to be_empty
|
232
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `empty?` over `be_empty` matcher.
|
233
|
-
expect(foo).to have_something
|
234
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `has_something?` over `have_something` matcher.
|
235
|
-
RUBY
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'registers an offense for a predicate mather with argument' do
|
239
|
-
expect_offense(<<-RUBY)
|
240
|
-
expect(foo).to be_something(1, 2)
|
241
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `something?` over `be_something` matcher.
|
242
|
-
expect(foo).to have_key(1)
|
243
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `has_key?` over `have_key` matcher.
|
244
|
-
RUBY
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'registers an offense for a predicate matcher with a block' do
|
248
|
-
expect_offense(<<-RUBY)
|
249
|
-
expect(foo).to be_all(&:present?)
|
250
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `all?` over `be_all` matcher.
|
251
|
-
expect(foo).to be_all { |x| x.present? }
|
252
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `all?` over `be_all` matcher.
|
253
|
-
expect(foo).to be_all { present }
|
254
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `all?` over `be_all` matcher.
|
255
|
-
expect(foo).to be_something(x) { |y| y.present? }
|
256
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `something?` over `be_something` matcher.
|
257
|
-
RUBY
|
258
|
-
end
|
259
|
-
|
260
|
-
it 'accepts built in matchers' do
|
261
|
-
expect_no_offenses(<<-RUBY)
|
262
|
-
expect(foo).to be_truthy
|
263
|
-
expect(foo).to be_falsey
|
264
|
-
expect(foo).to be_falsy
|
265
|
-
expect(foo).to have_attributes(name: 'foo')
|
266
|
-
expect(foo).to have_received(:foo)
|
267
|
-
expect(foo).to be_between(1, 10)
|
268
|
-
expect(foo).to be_within(0.1).of(10.0)
|
269
|
-
expect(foo).to exist
|
270
|
-
RUBY
|
271
|
-
end
|
272
|
-
|
273
|
-
it 'accepts non-predicate matcher' do
|
274
|
-
expect_no_offenses(<<-RUBY)
|
275
|
-
expect(foo).to be(true)
|
276
|
-
RUBY
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
shared_examples 'explicit autocorrect' do |matcher_true, matcher_false|
|
281
|
-
include_examples 'autocorrect',
|
282
|
-
'expect(foo).to be_something',
|
283
|
-
"expect(foo.something?).to #{matcher_true}"
|
284
|
-
include_examples 'autocorrect',
|
285
|
-
'expect(foo).not_to be_something',
|
286
|
-
"expect(foo.something?).to #{matcher_false}"
|
287
|
-
include_examples 'autocorrect',
|
288
|
-
'expect(foo).to have_something',
|
289
|
-
"expect(foo.has_something?).to #{matcher_true}"
|
290
|
-
|
291
|
-
include_examples 'autocorrect',
|
292
|
-
'expect(foo).to be_a(Array)',
|
293
|
-
"expect(foo.is_a?(Array)).to #{matcher_true}"
|
294
|
-
include_examples 'autocorrect',
|
295
|
-
'expect(foo).to be_instance_of(Array)',
|
296
|
-
"expect(foo.instance_of?(Array)).to #{matcher_true}"
|
297
|
-
|
298
|
-
include_examples 'autocorrect',
|
299
|
-
'expect(foo).to be_something()',
|
300
|
-
"expect(foo.something?()).to #{matcher_true}"
|
301
|
-
include_examples 'autocorrect',
|
302
|
-
'expect(foo).to be_something(1)',
|
303
|
-
"expect(foo.something?(1)).to #{matcher_true}"
|
304
|
-
include_examples 'autocorrect',
|
305
|
-
'expect(foo).to be_something(1, 2)',
|
306
|
-
"expect(foo.something?(1, 2)).to #{matcher_true}"
|
307
|
-
include_examples 'autocorrect',
|
308
|
-
'expect(foo).to be_something 1, 2',
|
309
|
-
"expect(foo.something? 1, 2).to #{matcher_true}"
|
310
|
-
|
311
|
-
include_examples 'autocorrect',
|
312
|
-
'expect(foo).to be_all { |x| x.present? }',
|
313
|
-
"expect(foo.all? { |x| x.present? }).to #{matcher_true}"
|
314
|
-
include_examples 'autocorrect',
|
315
|
-
'expect(foo).to be_all(n) { |x| x.ok? }',
|
316
|
-
"expect(foo.all?(n) { |x| x.ok? }).to #{matcher_true}"
|
317
|
-
include_examples 'autocorrect',
|
318
|
-
'expect(foo).to be_all { present }',
|
319
|
-
"expect(foo.all? { present }).to #{matcher_true}"
|
320
|
-
include_examples 'autocorrect',
|
321
|
-
'expect(foo).to be_all { }',
|
322
|
-
"expect(foo.all? { }).to #{matcher_true}"
|
323
|
-
include_examples 'autocorrect',
|
324
|
-
<<-BEFORE, <<-AFTER
|
325
|
-
expect(foo).to be_all do |x|
|
326
|
-
x + 1
|
327
|
-
x >= 2
|
328
|
-
end
|
329
|
-
BEFORE
|
330
|
-
expect(foo.all? do |x|
|
331
|
-
x + 1
|
332
|
-
x >= 2
|
333
|
-
end).to #{matcher_true}
|
334
|
-
AFTER
|
335
|
-
include_examples 'autocorrect',
|
336
|
-
'expect(foo).to be_all do; end',
|
337
|
-
"expect(foo.all? do; end).to #{matcher_true}"
|
338
|
-
end
|
339
|
-
|
340
|
-
context 'when strict is true' do
|
341
|
-
let(:strict) { true }
|
342
|
-
|
343
|
-
include_examples 'explicit common'
|
344
|
-
include_examples 'explicit autocorrect', 'be(true)', 'be(false)'
|
345
|
-
end
|
346
|
-
|
347
|
-
context 'when strict is false' do
|
348
|
-
let(:strict) { false }
|
349
|
-
|
350
|
-
include_examples 'explicit common'
|
351
|
-
include_examples 'explicit autocorrect', 'be_truthy', 'be_falsey'
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|