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,171 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::FactoryBot::CreateList, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
let(:cop_config) do
|
7
|
-
{ 'EnforcedStyle' => enforced_style }
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'when EnforcedStyle is :create_list' do
|
11
|
-
let(:enforced_style) { :create_list }
|
12
|
-
|
13
|
-
it 'flags usage of n.times with no arguments' do
|
14
|
-
expect_offense(<<-RUBY)
|
15
|
-
3.times { create :user }
|
16
|
-
^^^^^^^ Prefer create_list.
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'flags usage of n.times when FactoryGirl.create is used' do
|
21
|
-
expect_offense(<<-RUBY)
|
22
|
-
3.times { FactoryGirl.create :user }
|
23
|
-
^^^^^^^ Prefer create_list.
|
24
|
-
RUBY
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'flags usage of n.times when FactoryBot.create is used' do
|
28
|
-
expect_offense(<<-RUBY)
|
29
|
-
3.times { FactoryBot.create :user }
|
30
|
-
^^^^^^^ Prefer create_list.
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'ignores create method of other object' do
|
35
|
-
expect_no_offenses(<<-RUBY)
|
36
|
-
3.times { SomeFactory.create :user }
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores create in other block' do
|
41
|
-
expect_no_offenses(<<-RUBY)
|
42
|
-
allow(User).to receive(:create) { create :user }
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'ignores n.times with argument' do
|
47
|
-
expect_no_offenses(<<-RUBY)
|
48
|
-
3.times { |n| create :user, created_at: n.days.ago }
|
49
|
-
RUBY
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'ignores n.times when there is no create call inside' do
|
53
|
-
expect_no_offenses(<<-RUBY)
|
54
|
-
3.times { do_something }
|
55
|
-
RUBY
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'ignores n.times when there is other calls but create' do
|
59
|
-
expect_no_offenses(<<-RUBY)
|
60
|
-
used_passwords = []
|
61
|
-
3.times do
|
62
|
-
u = create :user
|
63
|
-
expect(used_passwords).not_to include(u.password)
|
64
|
-
used_passwords << u.password
|
65
|
-
end
|
66
|
-
RUBY
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'flags FactoryGirl.create calls with a block' do
|
70
|
-
expect_offense(<<-RUBY)
|
71
|
-
3.times do
|
72
|
-
^^^^^^^ Prefer create_list.
|
73
|
-
create(:user) { |user| create :account, user: user }
|
74
|
-
end
|
75
|
-
RUBY
|
76
|
-
end
|
77
|
-
|
78
|
-
include_examples 'autocorrect',
|
79
|
-
'5.times { create :user }',
|
80
|
-
'create_list :user, 5'
|
81
|
-
|
82
|
-
include_examples 'autocorrect',
|
83
|
-
'5.times { create(:user, :trait) }',
|
84
|
-
'create_list(:user, 5, :trait)'
|
85
|
-
|
86
|
-
include_examples 'autocorrect',
|
87
|
-
'5.times { create :user, :trait, key: val }',
|
88
|
-
'create_list :user, 5, :trait, key: val'
|
89
|
-
|
90
|
-
include_examples 'autocorrect',
|
91
|
-
'5.times { FactoryGirl.create :user }',
|
92
|
-
'FactoryGirl.create_list :user, 5'
|
93
|
-
|
94
|
-
bad_code = <<-RUBY
|
95
|
-
3.times do
|
96
|
-
create(:user, :trait) { |user| create :account, user: user }
|
97
|
-
end
|
98
|
-
RUBY
|
99
|
-
|
100
|
-
good_code = <<-RUBY
|
101
|
-
create_list(:user, 3, :trait) { |user| create :account, user: user }
|
102
|
-
RUBY
|
103
|
-
|
104
|
-
include_examples 'autocorrect', bad_code, good_code
|
105
|
-
|
106
|
-
bad_code = <<-RUBY
|
107
|
-
3.times do
|
108
|
-
create(:user, :trait) do |user|
|
109
|
-
create :account, user: user
|
110
|
-
create :profile, user: user
|
111
|
-
end
|
112
|
-
end
|
113
|
-
RUBY
|
114
|
-
|
115
|
-
good_code = <<-RUBY
|
116
|
-
create_list(:user, 3, :trait) do |user|
|
117
|
-
create :account, user: user
|
118
|
-
create :profile, user: user
|
119
|
-
end
|
120
|
-
RUBY
|
121
|
-
|
122
|
-
include_examples 'autocorrect', bad_code, good_code
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when EnforcedStyle is :n_times' do
|
126
|
-
let(:enforced_style) { :n_times }
|
127
|
-
|
128
|
-
it 'flags usage of create_list' do
|
129
|
-
expect_offense(<<-RUBY)
|
130
|
-
create_list :user, 3
|
131
|
-
^^^^^^^^^^^ Prefer 3.times.
|
132
|
-
RUBY
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'flags usage of FactoryGirl.create_list' do
|
136
|
-
expect_offense(<<-RUBY)
|
137
|
-
FactoryGirl.create_list :user, 3
|
138
|
-
^^^^^^^^^^^ Prefer 3.times.
|
139
|
-
RUBY
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'flags usage of FactoryGirl.create_list with a block' do
|
143
|
-
expect_offense(<<-RUBY)
|
144
|
-
FactoryGirl.create_list(:user, 3) { |user| user.points = rand(1000) }
|
145
|
-
^^^^^^^^^^^ Prefer 3.times.
|
146
|
-
RUBY
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'ignores create method of other object' do
|
150
|
-
expect_no_offenses(<<-RUBY)
|
151
|
-
SomeFactory.create_list :user, 3
|
152
|
-
RUBY
|
153
|
-
end
|
154
|
-
|
155
|
-
include_examples 'autocorrect',
|
156
|
-
'create_list :user, 5',
|
157
|
-
'5.times { create :user }'
|
158
|
-
|
159
|
-
include_examples 'autocorrect',
|
160
|
-
'create_list(:user, 5, :trait)',
|
161
|
-
'5.times { create(:user, :trait) }'
|
162
|
-
|
163
|
-
include_examples 'autocorrect',
|
164
|
-
'create_list :user, 5, :trait, key: val',
|
165
|
-
'5.times { create :user, :trait, key: val }'
|
166
|
-
|
167
|
-
include_examples 'autocorrect',
|
168
|
-
'FactoryGirl.create_list :user, 5',
|
169
|
-
'5.times { FactoryGirl.create :user }'
|
170
|
-
end
|
171
|
-
end
|
@@ -1,200 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::FilePath, :config do
|
4
|
-
subject(:cop) { described_class.new(config) }
|
5
|
-
|
6
|
-
it 'registers an offense for a bad path' do
|
7
|
-
expect_offense(<<-RUBY, 'wrong_path_foo_spec.rb')
|
8
|
-
describe MyClass, 'foo' do; end
|
9
|
-
^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
|
10
|
-
RUBY
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'registers an offense for a wrong class but a correct method' do
|
14
|
-
expect_offense(<<-RUBY, 'wrong_class_foo_spec.rb')
|
15
|
-
describe MyClass, '#foo' do; end
|
16
|
-
^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
|
17
|
-
RUBY
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'registers an offense for a repeated .rb' do
|
21
|
-
expect_offense(<<-RUBY, 'my_class/foo_spec.rb.rb')
|
22
|
-
describe MyClass, '#foo' do; end
|
23
|
-
^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
|
24
|
-
RUBY
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'registers an offense for a file missing a .rb' do
|
28
|
-
expect_offense(<<-RUBY, 'my_class/foo_specorb')
|
29
|
-
describe MyClass, '#foo' do; end
|
30
|
-
^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'registers an offense for a wrong class and highlights metadata' do
|
35
|
-
expect_offense(<<-RUBY, 'wrong_class_foo_spec.rb')
|
36
|
-
describe MyClass, '#foo', blah: :blah do; end
|
37
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
|
38
|
-
RUBY
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'registers an offense for a wrong class name' do
|
42
|
-
expect_offense(<<-RUBY, 'wrong_class_spec.rb')
|
43
|
-
describe MyClass do; end
|
44
|
-
^^^^^^^^^^^^^^^^ Spec path should end with `my_class*_spec.rb`.
|
45
|
-
RUBY
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'registers an offense for a wrong class name with a symbol argument' do
|
49
|
-
expect_offense(<<-RUBY, 'wrong_class_spec.rb')
|
50
|
-
describe MyClass, :foo do; end
|
51
|
-
^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*_spec.rb`.
|
52
|
-
RUBY
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'registers an offense for a file missing _spec' do
|
56
|
-
expect_offense(<<-RUBY, 'user.rb')
|
57
|
-
describe User do; end
|
58
|
-
^^^^^^^^^^^^^ Spec path should end with `user*_spec.rb`.
|
59
|
-
RUBY
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'skips specs that do not describe a class / method' do
|
63
|
-
expect_no_offenses(<<-RUBY, 'some/class/spec.rb')
|
64
|
-
describe 'Test something' do; end
|
65
|
-
RUBY
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'skips specs that do have multiple top level describes' do
|
69
|
-
expect_no_offenses(<<-RUBY, 'some/class/spec.rb')
|
70
|
-
describe MyClass, 'do_this' do; end
|
71
|
-
describe MyClass, 'do_that' do; end
|
72
|
-
RUBY
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'checks class specs' do
|
76
|
-
expect_no_offenses(<<-RUBY, 'some/class_spec.rb')
|
77
|
-
describe Some::Class do; end
|
78
|
-
RUBY
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'allows different parent directories' do
|
82
|
-
expect_no_offenses(<<-RUBY, 'parent_dir/some/class_spec.rb')
|
83
|
-
describe Some::Class do; end
|
84
|
-
RUBY
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'handles CamelCaps class names' do
|
88
|
-
expect_no_offenses(<<-RUBY, 'my_class_spec.rb')
|
89
|
-
describe MyClass do; end
|
90
|
-
RUBY
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'handles ACRONYMClassNames' do
|
94
|
-
expect_no_offenses(<<-RUBY, 'abc_one/two_spec.rb')
|
95
|
-
describe ABCOne::Two do; end
|
96
|
-
RUBY
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'handles ALLCAPS class names' do
|
100
|
-
expect_no_offenses(<<-RUBY, 'allcaps_spec.rb')
|
101
|
-
describe ALLCAPS do; end
|
102
|
-
RUBY
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'handles alphanumeric class names' do
|
106
|
-
expect_no_offenses(<<-RUBY, 'ipv4_and_ipv6_spec.rb')
|
107
|
-
describe IPV4AndIPV6 do; end
|
108
|
-
RUBY
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'checks instance methods' do
|
112
|
-
expect_no_offenses(<<-RUBY, 'some/class/inst_spec.rb')
|
113
|
-
describe Some::Class, '#inst' do; end
|
114
|
-
RUBY
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'checks class methods' do
|
118
|
-
expect_no_offenses(<<-RUBY, 'some/class/inst_spec.rb')
|
119
|
-
describe Some::Class, '.inst' do; end
|
120
|
-
RUBY
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'allows flat hierarchies for instance methods' do
|
124
|
-
expect_no_offenses(<<-RUBY, 'some/class_inst_spec.rb')
|
125
|
-
describe Some::Class, '#inst' do; end
|
126
|
-
RUBY
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'allows flat hierarchies for class methods' do
|
130
|
-
expect_no_offenses(<<-RUBY, 'some/class_inst_spec.rb')
|
131
|
-
describe Some::Class, '.inst' do; end
|
132
|
-
RUBY
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'allows subdirs for instance methods' do
|
136
|
-
filename = 'some/class/instance_methods/inst_spec.rb'
|
137
|
-
expect_no_offenses(<<-RUBY, filename)
|
138
|
-
describe Some::Class, '#inst' do; end
|
139
|
-
RUBY
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'allows subdirs for class methods' do
|
143
|
-
filename = 'some/class/class_methods/inst_spec.rb'
|
144
|
-
expect_no_offenses(<<-RUBY, filename)
|
145
|
-
describe Some::Class, '.inst' do; end
|
146
|
-
RUBY
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'ignores non-alphanumeric characters' do
|
150
|
-
expect_no_offenses(<<-RUBY, 'some/class/pred_spec.rb')
|
151
|
-
describe Some::Class, '#pred?' do; end
|
152
|
-
RUBY
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'allows bang method' do
|
156
|
-
expect_no_offenses(<<-RUBY, 'some/class/bang_spec.rb')
|
157
|
-
describe Some::Class, '#bang!' do; end
|
158
|
-
RUBY
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'allows flexibility with predicates' do
|
162
|
-
filename = 'some/class/thing_predicate_spec.rb'
|
163
|
-
expect_no_offenses(<<-RUBY, filename)
|
164
|
-
describe Some::Class, '#thing?' do; end
|
165
|
-
RUBY
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'allows flexibility with operators' do
|
169
|
-
filename = 'my_little_class/spaceship_operator_spec.rb'
|
170
|
-
expect_no_offenses(<<-RUBY, filename)
|
171
|
-
describe MyLittleClass, '#<=>' do; end
|
172
|
-
RUBY
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when configured with CustomTransform' do
|
176
|
-
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
|
177
|
-
|
178
|
-
it 'respects custom module name transformation' do
|
179
|
-
expect_no_offenses(<<-RUBY, 'foofoo/some/class/bar_spec.rb')
|
180
|
-
describe FooFoo::Some::Class, '#bar' do; end
|
181
|
-
RUBY
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'ignores routing specs' do
|
185
|
-
expect_no_offenses(<<-RUBY, 'foofoo/some/class/bar_spec.rb')
|
186
|
-
describe MyController, "#foo", type: :routing do; end
|
187
|
-
RUBY
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'when configured with IgnoreMethods' do
|
192
|
-
let(:cop_config) { { 'IgnoreMethods' => true } }
|
193
|
-
|
194
|
-
it 'does not care about the described method' do
|
195
|
-
expect_no_offenses(<<-RUBY, 'my_class_spec.rb')
|
196
|
-
describe MyClass, '#look_here_a_method' do; end
|
197
|
-
RUBY
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
@@ -1,139 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::Focus do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
# rubocop:disable RSpec/ExampleLength
|
7
|
-
it 'flags all rspec example blocks with that include `focus: true`' do
|
8
|
-
expect_offense(<<-RUBY)
|
9
|
-
example 'test', meta: true, focus: true do; end
|
10
|
-
^^^^^^^^^^^ Focused spec found.
|
11
|
-
xit 'test', meta: true, focus: true do; end
|
12
|
-
^^^^^^^^^^^ Focused spec found.
|
13
|
-
describe 'test', meta: true, focus: true do; end
|
14
|
-
^^^^^^^^^^^ Focused spec found.
|
15
|
-
RSpec.describe 'test', meta: true, focus: true do; end
|
16
|
-
^^^^^^^^^^^ Focused spec found.
|
17
|
-
it 'test', meta: true, focus: true do; end
|
18
|
-
^^^^^^^^^^^ Focused spec found.
|
19
|
-
xspecify 'test', meta: true, focus: true do; end
|
20
|
-
^^^^^^^^^^^ Focused spec found.
|
21
|
-
specify 'test', meta: true, focus: true do; end
|
22
|
-
^^^^^^^^^^^ Focused spec found.
|
23
|
-
example_group 'test', meta: true, focus: true do; end
|
24
|
-
^^^^^^^^^^^ Focused spec found.
|
25
|
-
scenario 'test', meta: true, focus: true do; end
|
26
|
-
^^^^^^^^^^^ Focused spec found.
|
27
|
-
xexample 'test', meta: true, focus: true do; end
|
28
|
-
^^^^^^^^^^^ Focused spec found.
|
29
|
-
xdescribe 'test', meta: true, focus: true do; end
|
30
|
-
^^^^^^^^^^^ Focused spec found.
|
31
|
-
context 'test', meta: true, focus: true do; end
|
32
|
-
^^^^^^^^^^^ Focused spec found.
|
33
|
-
xcontext 'test', meta: true, focus: true do; end
|
34
|
-
^^^^^^^^^^^ Focused spec found.
|
35
|
-
feature 'test', meta: true, focus: true do; end
|
36
|
-
^^^^^^^^^^^ Focused spec found.
|
37
|
-
xfeature 'test', meta: true, focus: true do; end
|
38
|
-
^^^^^^^^^^^ Focused spec found.
|
39
|
-
xscenario 'test', meta: true, focus: true do; end
|
40
|
-
^^^^^^^^^^^ Focused spec found.
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'flags all rspec example blocks that include `:focus`' do
|
45
|
-
expect_offense(<<-RUBY)
|
46
|
-
example_group 'test', :focus do; end
|
47
|
-
^^^^^^ Focused spec found.
|
48
|
-
feature 'test', :focus do; end
|
49
|
-
^^^^^^ Focused spec found.
|
50
|
-
xexample 'test', :focus do; end
|
51
|
-
^^^^^^ Focused spec found.
|
52
|
-
xdescribe 'test', :focus do; end
|
53
|
-
^^^^^^ Focused spec found.
|
54
|
-
xscenario 'test', :focus do; end
|
55
|
-
^^^^^^ Focused spec found.
|
56
|
-
specify 'test', :focus do; end
|
57
|
-
^^^^^^ Focused spec found.
|
58
|
-
example 'test', :focus do; end
|
59
|
-
^^^^^^ Focused spec found.
|
60
|
-
xfeature 'test', :focus do; end
|
61
|
-
^^^^^^ Focused spec found.
|
62
|
-
xspecify 'test', :focus do; end
|
63
|
-
^^^^^^ Focused spec found.
|
64
|
-
scenario 'test', :focus do; end
|
65
|
-
^^^^^^ Focused spec found.
|
66
|
-
describe 'test', :focus do; end
|
67
|
-
^^^^^^ Focused spec found.
|
68
|
-
RSpec.describe 'test', :focus do; end
|
69
|
-
^^^^^^ Focused spec found.
|
70
|
-
xit 'test', :focus do; end
|
71
|
-
^^^^^^ Focused spec found.
|
72
|
-
context 'test', :focus do; end
|
73
|
-
^^^^^^ Focused spec found.
|
74
|
-
xcontext 'test', :focus do; end
|
75
|
-
^^^^^^ Focused spec found.
|
76
|
-
it 'test', :focus do; end
|
77
|
-
^^^^^^ Focused spec found.
|
78
|
-
RUBY
|
79
|
-
end
|
80
|
-
# rubocop:enable RSpec/ExampleLength
|
81
|
-
|
82
|
-
it 'does not flag unfocused specs' do
|
83
|
-
expect_no_offenses(<<-RUBY)
|
84
|
-
xcontext 'test' do; end
|
85
|
-
xscenario 'test' do; end
|
86
|
-
xspecify 'test' do; end
|
87
|
-
describe 'test' do; end
|
88
|
-
example 'test' do; end
|
89
|
-
xexample 'test' do; end
|
90
|
-
scenario 'test' do; end
|
91
|
-
specify 'test' do; end
|
92
|
-
xit 'test' do; end
|
93
|
-
feature 'test' do; end
|
94
|
-
xfeature 'test' do; end
|
95
|
-
context 'test' do; end
|
96
|
-
it 'test' do; end
|
97
|
-
example_group 'test' do; end
|
98
|
-
xdescribe 'test' do; end
|
99
|
-
RUBY
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'does not flag a method that is focused twice' do
|
103
|
-
expect_offense(<<-RUBY)
|
104
|
-
fit "foo", :focus do
|
105
|
-
^^^^^^^^^^^^^^^^^ Focused spec found.
|
106
|
-
end
|
107
|
-
RUBY
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'ignores non-rspec code with :focus blocks' do
|
111
|
-
expect_no_offenses(<<-RUBY)
|
112
|
-
some_method "foo", focus: true do
|
113
|
-
end
|
114
|
-
RUBY
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'flags focused block types' do
|
118
|
-
expect_offense(<<-RUBY)
|
119
|
-
fdescribe 'test' do; end
|
120
|
-
^^^^^^^^^^^^^^^^ Focused spec found.
|
121
|
-
RSpec.fdescribe 'test' do; end
|
122
|
-
^^^^^^^^^^^^^^^^^^^^^^ Focused spec found.
|
123
|
-
ffeature 'test' do; end
|
124
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
125
|
-
fcontext 'test' do; end
|
126
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
127
|
-
fit 'test' do; end
|
128
|
-
^^^^^^^^^^ Focused spec found.
|
129
|
-
fscenario 'test' do; end
|
130
|
-
^^^^^^^^^^^^^^^^ Focused spec found.
|
131
|
-
fexample 'test' do; end
|
132
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
133
|
-
fspecify 'test' do; end
|
134
|
-
^^^^^^^^^^^^^^^ Focused spec found.
|
135
|
-
focus 'test' do; end
|
136
|
-
^^^^^^^^^^^^ Focused spec found.
|
137
|
-
RUBY
|
138
|
-
end
|
139
|
-
end
|