rubocop-rspec 1.32.0 → 1.33.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 +11 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/config/default.yml +6 -0
- data/lib/rubocop-rspec.rb +3 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
- data/lib/rubocop/cop/rspec/around_block.rb +4 -2
- data/lib/rubocop/cop/rspec/be.rb +4 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
- data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class.rb +3 -3
- data/lib/rubocop/cop/rspec/dialect.rb +76 -0
- data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/example_length.rb +1 -1
- data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
- data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
- data/lib/rubocop/cop/rspec/file_path.rb +2 -2
- data/lib/rubocop/cop/rspec/focus.rb +3 -3
- data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
- data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
- data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
- data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
- data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +3 -3
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
- data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
- data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
- data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
- data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
- data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
- data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
- data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
- data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/yield.rb +2 -4
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec.rb +2 -0
- data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
- data/lib/rubocop/rspec/config_formatter.rb +3 -1
- data/lib/rubocop/rspec/description_extractor.rb +3 -1
- data/lib/rubocop/rspec/factory_bot.rb +58 -0
- data/lib/rubocop/rspec/final_end_location.rb +2 -0
- data/lib/rubocop/rspec/inject.rb +2 -0
- data/lib/rubocop/rspec/language.rb +9 -2
- data/lib/rubocop/rspec/top_level_describe.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +3 -1
- data/spec/project/changelog_spec.rb +2 -0
- data/spec/project/default_config_spec.rb +2 -0
- data/spec/project/project_requires_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
- data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
- data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
- data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
- data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
- data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
- data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
- data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
- data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
- data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
- data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
- data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
- data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
- data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
- data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
- data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
- data/spec/rubocop/rspec/util/one_spec.rb +2 -0
- data/spec/rubocop/rspec/wording_spec.rb +2 -0
- data/spec/shared/autocorrect_behavior.rb +2 -0
- data/spec/shared/detects_style_behavior.rb +2 -0
- data/spec/shared/smoke_test_examples.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/expect_offense.rb +3 -1
- metadata +8 -4
@@ -11,6 +11,14 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterHook do
|
|
11
11
|
it { does_something }
|
12
12
|
end
|
13
13
|
RUBY
|
14
|
+
|
15
|
+
expect_correction(<<-RUBY)
|
16
|
+
RSpec.describe User do
|
17
|
+
before { do_something }
|
18
|
+
|
19
|
+
it { does_something }
|
20
|
+
end
|
21
|
+
RUBY
|
14
22
|
end
|
15
23
|
|
16
24
|
it 'checks for empty line after `after` hook' do
|
@@ -21,6 +29,14 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterHook do
|
|
21
29
|
it { does_something }
|
22
30
|
end
|
23
31
|
RUBY
|
32
|
+
|
33
|
+
expect_correction(<<-RUBY)
|
34
|
+
RSpec.describe User do
|
35
|
+
after { do_something }
|
36
|
+
|
37
|
+
it { does_something }
|
38
|
+
end
|
39
|
+
RUBY
|
24
40
|
end
|
25
41
|
|
26
42
|
it 'checks for empty line after `around` hook' do
|
@@ -31,6 +47,14 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterHook do
|
|
31
47
|
it { does_something }
|
32
48
|
end
|
33
49
|
RUBY
|
50
|
+
|
51
|
+
expect_correction(<<-RUBY)
|
52
|
+
RSpec.describe User do
|
53
|
+
around { |test| test.run }
|
54
|
+
|
55
|
+
it { does_something }
|
56
|
+
end
|
57
|
+
RUBY
|
34
58
|
end
|
35
59
|
|
36
60
|
it 'approves empty line after `before` hook' do
|
@@ -106,23 +130,4 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterHook do
|
|
106
130
|
end
|
107
131
|
RUBY
|
108
132
|
end
|
109
|
-
|
110
|
-
bad_example = <<-RUBY
|
111
|
-
RSpec.describe User do
|
112
|
-
before { do_something }
|
113
|
-
it { does_something }
|
114
|
-
end
|
115
|
-
RUBY
|
116
|
-
|
117
|
-
good_example = <<-RUBY
|
118
|
-
RSpec.describe User do
|
119
|
-
before { do_something }
|
120
|
-
|
121
|
-
it { does_something }
|
122
|
-
end
|
123
|
-
RUBY
|
124
|
-
|
125
|
-
include_examples 'autocorrect',
|
126
|
-
bad_example,
|
127
|
-
good_example
|
128
133
|
end
|
@@ -11,6 +11,14 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
|
|
11
11
|
let(:params) { foo }
|
12
12
|
end
|
13
13
|
RUBY
|
14
|
+
|
15
|
+
expect_correction(<<-RUBY)
|
16
|
+
RSpec.describe User do
|
17
|
+
subject { described_class.new }
|
18
|
+
|
19
|
+
let(:params) { foo }
|
20
|
+
end
|
21
|
+
RUBY
|
14
22
|
end
|
15
23
|
|
16
24
|
it 'checks for empty line after subject!' do
|
@@ -21,6 +29,14 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
|
|
21
29
|
let(:params) { foo }
|
22
30
|
end
|
23
31
|
RUBY
|
32
|
+
|
33
|
+
expect_correction(<<-RUBY)
|
34
|
+
RSpec.describe User do
|
35
|
+
subject! { described_class.new }
|
36
|
+
|
37
|
+
let(:params) { foo }
|
38
|
+
end
|
39
|
+
RUBY
|
24
40
|
end
|
25
41
|
|
26
42
|
it 'approves empty line after subject' do
|
@@ -75,23 +91,4 @@ RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterSubject do
|
|
75
91
|
end
|
76
92
|
RUBY
|
77
93
|
end
|
78
|
-
|
79
|
-
bad_example = <<-RUBY
|
80
|
-
RSpec.describe User do
|
81
|
-
subject { described_class.new }
|
82
|
-
let(:params) { foo }
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
|
86
|
-
good_example = <<-RUBY
|
87
|
-
RSpec.describe User do
|
88
|
-
subject { described_class.new }
|
89
|
-
|
90
|
-
let(:params) { foo }
|
91
|
-
end
|
92
|
-
RUBY
|
93
|
-
|
94
|
-
include_examples 'autocorrect',
|
95
|
-
bad_example,
|
96
|
-
good_example
|
97
94
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
2
4
|
subject(:cop) { described_class.new(config) }
|
3
5
|
|
@@ -19,6 +21,11 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
19
21
|
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
20
22
|
end
|
21
23
|
RUBY
|
24
|
+
|
25
|
+
expect_correction(<<-RUBY)
|
26
|
+
it 'does something' do
|
27
|
+
end
|
28
|
+
RUBY
|
22
29
|
end
|
23
30
|
|
24
31
|
it 'finds description with `Should` at the beginning' do
|
@@ -27,6 +34,11 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
27
34
|
^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
28
35
|
end
|
29
36
|
RUBY
|
37
|
+
|
38
|
+
expect_correction(<<-RUBY)
|
39
|
+
it 'does something' do
|
40
|
+
end
|
41
|
+
RUBY
|
30
42
|
end
|
31
43
|
|
32
44
|
it 'finds description with `shouldn\'t` at the beginning' do
|
@@ -35,6 +47,24 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
35
47
|
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
36
48
|
end
|
37
49
|
RUBY
|
50
|
+
|
51
|
+
expect_correction(<<-RUBY)
|
52
|
+
it "does not do something" do
|
53
|
+
end
|
54
|
+
RUBY
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'finds description with `SHOULDN\'T` at the beginning' do
|
58
|
+
expect_offense(<<-RUBY)
|
59
|
+
it "SHOULDN'T do something" do
|
60
|
+
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
|
64
|
+
expect_correction(<<-RUBY)
|
65
|
+
it "DOES NOT do something" do
|
66
|
+
end
|
67
|
+
RUBY
|
38
68
|
end
|
39
69
|
|
40
70
|
it 'flags a lone should' do
|
@@ -43,6 +73,11 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
43
73
|
^^^^^^ Do not use should when describing your tests.
|
44
74
|
end
|
45
75
|
RUBY
|
76
|
+
|
77
|
+
expect_correction(<<-RUBY)
|
78
|
+
it '' do
|
79
|
+
end
|
80
|
+
RUBY
|
46
81
|
end
|
47
82
|
|
48
83
|
it 'flags a lone should not' do
|
@@ -51,6 +86,11 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
51
86
|
^^^^^^^^^^ Do not use should when describing your tests.
|
52
87
|
end
|
53
88
|
RUBY
|
89
|
+
|
90
|
+
expect_correction(<<-RUBY)
|
91
|
+
it 'does not' do
|
92
|
+
end
|
93
|
+
RUBY
|
54
94
|
end
|
55
95
|
|
56
96
|
it 'finds leading its' do
|
@@ -59,6 +99,11 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
59
99
|
^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
|
60
100
|
end
|
61
101
|
RUBY
|
102
|
+
|
103
|
+
expect_correction(<<-RUBY)
|
104
|
+
it "does something" do
|
105
|
+
end
|
106
|
+
RUBY
|
62
107
|
end
|
63
108
|
|
64
109
|
it "skips words beginning with 'it'" do
|
@@ -81,30 +126,6 @@ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
81
126
|
end
|
82
127
|
RUBY
|
83
128
|
end
|
84
|
-
|
85
|
-
include_examples 'autocorrect',
|
86
|
-
'it "should only have trait" do end',
|
87
|
-
'it "only has trait" do end'
|
88
|
-
|
89
|
-
include_examples 'autocorrect',
|
90
|
-
'it "SHOULDN\'T only have trait" do end',
|
91
|
-
'it "DOES NOT only have trait" do end'
|
92
|
-
|
93
|
-
include_examples 'autocorrect',
|
94
|
-
'it "it does something" do end',
|
95
|
-
'it "does something" do end'
|
96
|
-
|
97
|
-
include_examples 'autocorrect',
|
98
|
-
'it "It does something" do end',
|
99
|
-
'it "does something" do end'
|
100
|
-
|
101
|
-
include_examples 'autocorrect',
|
102
|
-
'it "should" do end',
|
103
|
-
'it "" do end'
|
104
|
-
|
105
|
-
include_examples 'autocorrect',
|
106
|
-
'it "should not" do end',
|
107
|
-
'it "does not" do end'
|
108
129
|
end
|
109
130
|
|
110
131
|
context 'when configuration is empty' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
2
4
|
subject(:cop) { described_class.new(config) }
|
3
5
|
|
@@ -11,10 +13,16 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
|
11
13
|
it 'finds blocks that contain simple message sending' do
|
12
14
|
expect_offense(<<-RUBY)
|
13
15
|
it do
|
14
|
-
expect(run).to change { User.count }
|
16
|
+
expect(run).to change { User.count }.by(1)
|
15
17
|
^^^^^^^^^^^^^^^^^^^^^ Prefer `change(User, :count)`.
|
16
18
|
end
|
17
19
|
RUBY
|
20
|
+
|
21
|
+
expect_correction(<<-RUBY)
|
22
|
+
it do
|
23
|
+
expect(run).to change(User, :count).by(1)
|
24
|
+
end
|
25
|
+
RUBY
|
18
26
|
end
|
19
27
|
|
20
28
|
it 'ignores blocks that cannot be converted to obj/attribute pair' do
|
@@ -32,12 +40,6 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
|
32
40
|
end
|
33
41
|
RUBY
|
34
42
|
end
|
35
|
-
|
36
|
-
include_examples(
|
37
|
-
'autocorrect',
|
38
|
-
'expect(run).to change { User.count }.by(1)',
|
39
|
-
'expect(run).to change(User, :count).by(1)'
|
40
|
-
)
|
41
43
|
end
|
42
44
|
|
43
45
|
context 'with EnforcedStyle `block`' do
|
@@ -46,10 +48,16 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
|
46
48
|
it 'finds change matcher without block' do
|
47
49
|
expect_offense(<<-RUBY)
|
48
50
|
it do
|
49
|
-
expect(run).to change(User, :count)
|
51
|
+
expect(run).to change(User, :count).by(1)
|
50
52
|
^^^^^^^^^^^^^^^^^^^^ Prefer `change { User.count }`.
|
51
53
|
end
|
52
54
|
RUBY
|
55
|
+
|
56
|
+
expect_correction(<<-RUBY)
|
57
|
+
it do
|
58
|
+
expect(run).to change { User.count }.by(1)
|
59
|
+
end
|
60
|
+
RUBY
|
53
61
|
end
|
54
62
|
|
55
63
|
it 'finds change matcher when receiver is a variable' do
|
@@ -59,6 +67,12 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
|
59
67
|
^^^^^^^^^^^^^^^^^^^^ Prefer `change { user.count }`.
|
60
68
|
end
|
61
69
|
RUBY
|
70
|
+
|
71
|
+
expect_correction(<<-RUBY)
|
72
|
+
it do
|
73
|
+
expect(run).to change { user.count }
|
74
|
+
end
|
75
|
+
RUBY
|
62
76
|
end
|
63
77
|
|
64
78
|
it 'ignores methods called change' do
|
@@ -68,11 +82,5 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
|
|
68
82
|
end
|
69
83
|
RUBY
|
70
84
|
end
|
71
|
-
|
72
|
-
include_examples(
|
73
|
-
'autocorrect',
|
74
|
-
'expect(run).to change(User, :count).by(1)',
|
75
|
-
'expect(run).to change { User.count }.by(1)'
|
76
|
-
)
|
77
85
|
end
|
78
86
|
end
|
@@ -66,6 +66,21 @@ RSpec.describe RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically do #
|
|
66
66
|
RUBY
|
67
67
|
end
|
68
68
|
|
69
|
+
it 'registers an offense for attributes defined on explicit receiver' do
|
70
|
+
expect_offense(<<-RUBY)
|
71
|
+
FactoryBot.define do
|
72
|
+
factory :post do |post_definition|
|
73
|
+
post_definition.end Date.tomorrow
|
74
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to declare attribute values.
|
75
|
+
post_definition.trait :published do |published_definition|
|
76
|
+
published_definition.published_at 1.day.from_now
|
77
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to declare attribute values.
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
RUBY
|
82
|
+
end
|
83
|
+
|
69
84
|
it 'accepts valid factory definitions' do
|
70
85
|
expect_no_offenses(<<-RUBY)
|
71
86
|
FactoryBot.define do
|
@@ -98,6 +113,27 @@ RSpec.describe RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically do #
|
|
98
113
|
RUBY
|
99
114
|
end
|
100
115
|
|
116
|
+
it 'does not add offense if method called on another object' do
|
117
|
+
expect_no_offenses(<<-RUBY)
|
118
|
+
FactoryBot.define do
|
119
|
+
factory :post do |post_definition|
|
120
|
+
Registrar.register :post_factory
|
121
|
+
end
|
122
|
+
end
|
123
|
+
RUBY
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'does not add offense if method called on a local variable' do
|
127
|
+
expect_no_offenses(<<-RUBY)
|
128
|
+
FactoryBot.define do
|
129
|
+
factory :post do |post_definition|
|
130
|
+
local = Registrar
|
131
|
+
local.register :post_factory
|
132
|
+
end
|
133
|
+
end
|
134
|
+
RUBY
|
135
|
+
end
|
136
|
+
|
101
137
|
it 'accepts valid association definitions' do
|
102
138
|
expect_no_offenses(<<-RUBY)
|
103
139
|
FactoryBot.define do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RuboCop::Cop::RSpec::Focus do
|
2
4
|
subject(:cop) { described_class.new }
|
3
5
|
|
@@ -112,7 +114,6 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
112
114
|
RUBY
|
113
115
|
end
|
114
116
|
|
115
|
-
# rubocop:disable RSpec/ExampleLength
|
116
117
|
it 'flags focused block types' do
|
117
118
|
expect_offense(<<-RUBY)
|
118
119
|
fdescribe 'test' do; end
|
@@ -135,5 +136,4 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
135
136
|
^^^^^^^^^^^^ Focused spec found.
|
136
137
|
RUBY
|
137
138
|
end
|
138
|
-
# rubocop:enable RSpec/ExampleLength
|
139
139
|
end
|
@@ -1,58 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RuboCop::Cop::RSpec::HooksBeforeExamples do
|
2
4
|
subject(:cop) { described_class.new }
|
3
5
|
|
4
6
|
it 'flags `before` after `it`' do
|
5
7
|
expect_offense(<<-RUBY)
|
6
8
|
RSpec.describe User do
|
7
|
-
it { is_expected.to
|
9
|
+
it { is_expected.to be_after_before_hook }
|
8
10
|
before { setup }
|
9
11
|
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
10
12
|
end
|
11
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
|
12
21
|
end
|
13
22
|
|
14
23
|
it 'flags `before` after `context`' do
|
15
24
|
expect_offense(<<-RUBY)
|
16
25
|
RSpec.describe User do
|
17
26
|
context 'a context' do
|
18
|
-
it { is_expected.to
|
27
|
+
it { is_expected.to be_after_before_hook }
|
19
28
|
end
|
20
29
|
|
21
30
|
before { setup }
|
22
31
|
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
23
32
|
end
|
24
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
|
25
44
|
end
|
26
45
|
|
27
46
|
it 'flags `before` after `include_examples`' do
|
28
47
|
expect_offense(<<-RUBY)
|
29
48
|
RSpec.describe User do
|
30
|
-
include_examples('should be after
|
49
|
+
include_examples('should be after before-hook')
|
31
50
|
|
32
51
|
before { setup }
|
33
52
|
^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
34
53
|
end
|
35
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
|
36
63
|
end
|
37
64
|
|
38
65
|
it 'flags `after` after an example' do
|
39
66
|
expect_offense(<<-RUBY)
|
40
67
|
RSpec.describe User do
|
41
|
-
it { is_expected.to
|
68
|
+
it { is_expected.to be_after_after_hook }
|
42
69
|
after { cleanup }
|
43
70
|
^^^^^^^^^^^^^^^^^ Move `after` above the examples in the group.
|
44
71
|
end
|
45
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
|
46
80
|
end
|
47
81
|
|
48
82
|
it 'flags scoped hook after an example' do
|
49
83
|
expect_offense(<<-RUBY)
|
50
84
|
RSpec.describe User do
|
51
|
-
it { is_expected.to
|
85
|
+
it { is_expected.to be_after_before_hook }
|
52
86
|
before(:each) { cleanup }
|
53
87
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Move `before` above the examples in the group.
|
54
88
|
end
|
55
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
|
56
97
|
end
|
57
98
|
|
58
99
|
it 'does not flag hooks before the examples' do
|
@@ -61,7 +102,7 @@ RSpec.describe RuboCop::Cop::RSpec::HooksBeforeExamples do
|
|
61
102
|
before(:each) { setup }
|
62
103
|
after(:each) { cleanup }
|
63
104
|
|
64
|
-
it { is_expected.to
|
105
|
+
it { is_expected.to be_after_hooks }
|
65
106
|
|
66
107
|
context 'a context' do
|
67
108
|
it { is_expected.to work }
|
@@ -106,30 +147,4 @@ RSpec.describe RuboCop::Cop::RSpec::HooksBeforeExamples do
|
|
106
147
|
end
|
107
148
|
RUBY
|
108
149
|
end
|
109
|
-
|
110
|
-
bad_code = <<-RUBY
|
111
|
-
RSpec.describe User do
|
112
|
-
include_examples('should be after hook')
|
113
|
-
context 'another one' do
|
114
|
-
before { another_setup }
|
115
|
-
include_examples('should be ok')
|
116
|
-
end
|
117
|
-
|
118
|
-
after { cleanup }
|
119
|
-
end
|
120
|
-
RUBY
|
121
|
-
|
122
|
-
good_code = <<-RUBY
|
123
|
-
RSpec.describe User do
|
124
|
-
after { cleanup }
|
125
|
-
include_examples('should be after hook')
|
126
|
-
context 'another one' do
|
127
|
-
before { another_setup }
|
128
|
-
include_examples('should be ok')
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
RUBY
|
133
|
-
|
134
|
-
include_examples 'autocorrect', bad_code, good_code
|
135
150
|
end
|