rubocop-rspec 1.15.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/Gemfile +0 -1
- data/config/default.yml +105 -0
- data/lib/rubocop-rspec.rb +27 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +51 -0
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +51 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
- data/lib/rubocop/cop/rspec/cop.rb +4 -2
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +61 -0
- data/lib/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically.rb +84 -0
- data/lib/rubocop/cop/rspec/hook_argument.rb +11 -5
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +42 -0
- data/lib/rubocop/cop/rspec/let_before_examples.rb +66 -0
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -5
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +80 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +5 -6
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +337 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +83 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +52 -0
- data/lib/rubocop/rspec/align_let_brace.rb +64 -0
- data/lib/rubocop/rspec/config_formatter.rb +7 -4
- data/lib/rubocop/rspec/description_extractor.rb +2 -2
- data/lib/rubocop/rspec/example_group.rb +25 -2
- data/lib/rubocop/rspec/factory_girl.rb +7 -0
- data/lib/rubocop/rspec/language.rb +6 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +1 -4
- data/spec/project/default_config_spec.rb +8 -4
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +62 -0
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +62 -0
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/around_block_spec.rb +11 -11
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/cop_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/described_class_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +9 -9
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/example_length_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +79 -0
- data/spec/rubocop/cop/rspec/expect_output_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically_spec.rb +87 -0
- data/spec/rubocop/cop/rspec/file_path_spec.rb +29 -29
- data/spec/rubocop/cop/rspec/focus_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +35 -23
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +37 -0
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +8 -8
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +83 -0
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/message_spies_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +45 -9
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +96 -0
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +335 -0
- data/spec/rubocop/cop/rspec/repeated_description_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/repeated_example_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +85 -0
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +8 -8
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +9 -9
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +47 -0
- data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/expect_offense.rb +17 -0
- metadata +39 -51
- data/spec/expect_violation/expectation_spec.rb +0 -85
- data/spec/support/expect_violation.rb +0 -170
@@ -3,7 +3,7 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
3
3
|
|
4
4
|
# rubocop:disable RSpec/ExampleLength
|
5
5
|
it 'flags all rspec example blocks with that include `focus: true`' do
|
6
|
-
|
6
|
+
expect_offense(<<-RUBY)
|
7
7
|
example 'test', meta: true, focus: true do; end
|
8
8
|
^^^^^^^^^^^ Focused spec found.
|
9
9
|
xit 'test', meta: true, focus: true do; end
|
@@ -38,7 +38,7 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'flags all rspec example blocks that include `:focus`' do
|
41
|
-
|
41
|
+
expect_offense(<<-RUBY)
|
42
42
|
example_group 'test', :focus do; end
|
43
43
|
^^^^^^ Focused spec found.
|
44
44
|
feature 'test', :focus do; end
|
@@ -73,7 +73,7 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'does not flag unfocused specs' do
|
76
|
-
|
76
|
+
expect_no_offenses(<<-RUBY)
|
77
77
|
xcontext 'test' do; end
|
78
78
|
xscenario 'test' do; end
|
79
79
|
xspecify 'test' do; end
|
@@ -93,7 +93,7 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'does not flag a method that is focused twice' do
|
96
|
-
|
96
|
+
expect_offense(<<-RUBY)
|
97
97
|
fit "foo", :focus do
|
98
98
|
^^^^^^^^^^^^^^^^^ Focused spec found.
|
99
99
|
end
|
@@ -101,14 +101,14 @@ RSpec.describe RuboCop::Cop::RSpec::Focus do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'ignores non-rspec code with :focus blocks' do
|
104
|
-
|
104
|
+
expect_no_offenses(<<-RUBY)
|
105
105
|
some_method "foo", focus: true do
|
106
106
|
end
|
107
107
|
RUBY
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'flags focused block types' do
|
111
|
-
|
111
|
+
expect_offense(<<-RUBY)
|
112
112
|
fdescribe 'test' do; end
|
113
113
|
^^^^^^^^^^^^^^^^ Focused spec found.
|
114
114
|
ffeature 'test' do; end
|
@@ -9,7 +9,7 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
9
9
|
|
10
10
|
shared_examples 'ignored hooks' do
|
11
11
|
it 'ignores :context and :suite' do
|
12
|
-
|
12
|
+
expect_no_offenses(<<-RUBY)
|
13
13
|
before(:suite) { true }
|
14
14
|
after(:suite) { true }
|
15
15
|
before(:context) { true }
|
@@ -18,13 +18,13 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'ignores hooks with more than one argument' do
|
21
|
-
|
21
|
+
expect_no_offenses(<<-RUBY)
|
22
22
|
before(:each, :something_custom) { true }
|
23
23
|
RUBY
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'ignores non-rspec hooks' do
|
27
|
-
|
27
|
+
expect_no_offenses(<<-RUBY)
|
28
28
|
setup(:each) { true }
|
29
29
|
RUBY
|
30
30
|
end
|
@@ -34,6 +34,13 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
34
34
|
include_examples 'autocorrect', 'before(:each) { }', output
|
35
35
|
include_examples 'autocorrect', 'before(:example) { }', output
|
36
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
|
37
44
|
end
|
38
45
|
|
39
46
|
shared_examples 'an example hook' do
|
@@ -47,33 +54,36 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
47
54
|
let(:enforced_style) { :implicit }
|
48
55
|
|
49
56
|
it 'detects :each for hooks' do
|
50
|
-
|
57
|
+
expect_offense(<<-RUBY)
|
51
58
|
before(:each) { true }
|
52
59
|
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
53
60
|
after(:each) { true }
|
54
61
|
^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
55
62
|
around(:each) { true }
|
56
63
|
^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
64
|
+
config.after(:each) { true }
|
65
|
+
^^^^^^^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
|
57
66
|
RUBY
|
58
67
|
end
|
59
68
|
|
60
69
|
it 'detects :example for hooks' do
|
61
|
-
|
70
|
+
expect_offense(<<-RUBY)
|
62
71
|
before(:example) { true }
|
63
72
|
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
64
73
|
after(:example) { true }
|
65
74
|
^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
66
75
|
around(:example) { true }
|
67
76
|
^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
77
|
+
config.before(:example) { true }
|
78
|
+
^^^^^^^^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
|
68
79
|
RUBY
|
69
80
|
end
|
70
81
|
|
71
82
|
it 'does not flag hooks without default scopes' do
|
72
|
-
|
73
|
-
before { true }
|
74
|
-
after { true }
|
83
|
+
expect_no_offenses(<<-RUBY)
|
75
84
|
before { true }
|
76
85
|
after { true }
|
86
|
+
config.before { true }
|
77
87
|
RUBY
|
78
88
|
end
|
79
89
|
|
@@ -85,34 +95,35 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
85
95
|
let(:enforced_style) { :each }
|
86
96
|
|
87
97
|
it 'detects :each for hooks' do
|
88
|
-
|
98
|
+
expect_no_offenses(<<-RUBY)
|
89
99
|
before(:each) { true }
|
90
100
|
after(:each) { true }
|
91
101
|
around(:each) { true }
|
102
|
+
config.before(:each) { true }
|
92
103
|
RUBY
|
93
104
|
end
|
94
105
|
|
95
106
|
it 'detects :example for hooks' do
|
96
|
-
|
107
|
+
expect_offense(<<-RUBY)
|
97
108
|
before(:example) { true }
|
98
109
|
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
99
110
|
after(:example) { true }
|
100
111
|
^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
101
112
|
around(:example) { true }
|
102
113
|
^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
114
|
+
config.before(:example) { true }
|
115
|
+
^^^^^^^^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
|
103
116
|
RUBY
|
104
117
|
end
|
105
118
|
|
106
|
-
it '
|
107
|
-
|
108
|
-
before { true }
|
109
|
-
^^^^^^ Use `:each` for RSpec hooks.
|
110
|
-
after { true }
|
111
|
-
^^^^^ Use `:each` for RSpec hooks.
|
119
|
+
it 'detects hooks without default scopes' do
|
120
|
+
expect_offense(<<-RUBY)
|
112
121
|
before { true }
|
113
122
|
^^^^^^ Use `:each` for RSpec hooks.
|
114
123
|
after { true }
|
115
124
|
^^^^^ Use `:each` for RSpec hooks.
|
125
|
+
config.before { true }
|
126
|
+
^^^^^^ Use `:each` for RSpec hooks.
|
116
127
|
RUBY
|
117
128
|
end
|
118
129
|
|
@@ -124,34 +135,35 @@ RSpec.describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
124
135
|
let(:enforced_style) { :example }
|
125
136
|
|
126
137
|
it 'detects :example for hooks' do
|
127
|
-
|
138
|
+
expect_no_offenses(<<-RUBY)
|
128
139
|
before(:example) { true }
|
129
140
|
after(:example) { true }
|
130
141
|
around(:example) { true }
|
142
|
+
config.before(:example) { true }
|
131
143
|
RUBY
|
132
144
|
end
|
133
145
|
|
134
146
|
it 'detects :each for hooks' do
|
135
|
-
|
147
|
+
expect_offense(<<-RUBY)
|
136
148
|
before(:each) { true }
|
137
149
|
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
138
150
|
after(:each) { true }
|
139
151
|
^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
140
152
|
around(:each) { true }
|
141
153
|
^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
154
|
+
config.before(:each) { true }
|
155
|
+
^^^^^^^^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
|
142
156
|
RUBY
|
143
157
|
end
|
144
158
|
|
145
159
|
it 'does not flag hooks without default scopes' do
|
146
|
-
|
147
|
-
before { true }
|
148
|
-
^^^^^^ Use `:example` for RSpec hooks.
|
149
|
-
after { true }
|
150
|
-
^^^^^ Use `:example` for RSpec hooks.
|
160
|
+
expect_offense(<<-RUBY)
|
151
161
|
before { true }
|
152
162
|
^^^^^^ Use `:example` for RSpec hooks.
|
153
163
|
after { true }
|
154
164
|
^^^^^ Use `:example` for RSpec hooks.
|
165
|
+
config.before { true }
|
166
|
+
^^^^^^ Use `:example` for RSpec hooks.
|
155
167
|
RUBY
|
156
168
|
end
|
157
169
|
|
@@ -9,29 +9,29 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'flags it { should }' do
|
12
|
-
|
12
|
+
expect_offense(<<-RUBY)
|
13
13
|
it { should be_truthy }
|
14
14
|
^^^^^^ Prefer `is_expected.to` over `should`.
|
15
15
|
RUBY
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'flags it { should_not }' do
|
19
|
-
|
19
|
+
expect_offense(<<-RUBY)
|
20
20
|
it { should_not be_truthy }
|
21
21
|
^^^^^^^^^^ Prefer `is_expected.to_not` over `should_not`.
|
22
22
|
RUBY
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'approves of is_expected.to' do
|
26
|
-
|
26
|
+
expect_no_offenses('it { is_expected.to be_truthy }')
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'approves of is_expected.to_not' do
|
30
|
-
|
30
|
+
expect_no_offenses('it { is_expected.to_not be_truthy }')
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'approves of is_expected.not_to' do
|
34
|
-
|
34
|
+
expect_no_offenses('it { is_expected.not_to be_truthy }')
|
35
35
|
end
|
36
36
|
|
37
37
|
include_examples 'detects style', 'it { should be_truthy }', 'should'
|
@@ -50,32 +50,32 @@ RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'flags it { is_expected.to }' do
|
53
|
-
|
53
|
+
expect_offense(<<-RUBY)
|
54
54
|
it { is_expected.to be_truthy }
|
55
55
|
^^^^^^^^^^^^^^ Prefer `should` over `is_expected.to`.
|
56
56
|
RUBY
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'flags it { is_expected.to_not }' do
|
60
|
-
|
60
|
+
expect_offense(<<-RUBY)
|
61
61
|
it { is_expected.to_not be_truthy }
|
62
62
|
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.to_not`.
|
63
63
|
RUBY
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'flags it { is_expected.not_to }' do
|
67
|
-
|
67
|
+
expect_offense(<<-RUBY)
|
68
68
|
it { is_expected.not_to be_truthy }
|
69
69
|
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.not_to`.
|
70
70
|
RUBY
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'approves of should' do
|
74
|
-
|
74
|
+
expect_no_offenses('it { should be_truthy }')
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'approves of should_not' do
|
78
|
-
|
78
|
+
expect_no_offenses('it { should_not be_truthy }')
|
79
79
|
end
|
80
80
|
|
81
81
|
include_examples 'detects style',
|
@@ -3,7 +3,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
|
|
3
3
|
|
4
4
|
context 'when used with `have_received`' do
|
5
5
|
it 'adds an offense for an instance_double with single argument' do
|
6
|
-
|
6
|
+
expect_offense(<<-RUBY)
|
7
7
|
it do
|
8
8
|
foo = instance_double(Foo).as_null_object
|
9
9
|
^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`.
|
@@ -13,7 +13,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'adds an offense for an instance_double with multiple arguments' do
|
16
|
-
|
16
|
+
expect_offense(<<-RUBY)
|
17
17
|
it do
|
18
18
|
foo = instance_double(Foo, :name).as_null_object
|
19
19
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `instance_spy` when you check your double with `have_received`.
|
@@ -23,7 +23,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'ignores instance_double when it is not used with as_null_object' do
|
26
|
-
|
26
|
+
expect_no_offenses(<<-RUBY)
|
27
27
|
it do
|
28
28
|
foo = instance_double(Foo)
|
29
29
|
expect(bar).to have_received(:bar)
|
@@ -34,7 +34,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceSpy do
|
|
34
34
|
|
35
35
|
context 'when not used with `have_received`' do
|
36
36
|
it 'does not add an offence' do
|
37
|
-
|
37
|
+
expect_no_offenses(<<-RUBY)
|
38
38
|
it do
|
39
39
|
foo = instance_double(Foo).as_null_object
|
40
40
|
expect(bar).to have_received(:bar)
|
@@ -2,7 +2,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
2
2
|
subject(:cop) { described_class.new }
|
3
3
|
|
4
4
|
it 'finds an instance variable inside a describe' do
|
5
|
-
|
5
|
+
expect_offense(<<-RUBY)
|
6
6
|
describe MyClass do
|
7
7
|
before { @foo = [] }
|
8
8
|
it { expect(@foo).to be_empty }
|
@@ -12,7 +12,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'ignores non-spec blocks' do
|
15
|
-
|
15
|
+
expect_no_offenses(<<-RUBY)
|
16
16
|
not_rspec do
|
17
17
|
before { @foo = [] }
|
18
18
|
it { expect(@foo).to be_empty }
|
@@ -21,7 +21,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'finds an instance variable inside a shared example' do
|
24
|
-
|
24
|
+
expect_offense(<<-RUBY)
|
25
25
|
shared_examples 'shared example' do
|
26
26
|
it { expect(@foo).to be_empty }
|
27
27
|
^^^^ Use `let` instead of an instance variable.
|
@@ -30,7 +30,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'ignores an instance variable without describe' do
|
33
|
-
|
33
|
+
expect_no_offenses(<<-RUBY)
|
34
34
|
@foo = []
|
35
35
|
@foo.empty?
|
36
36
|
RUBY
|
@@ -38,7 +38,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
38
38
|
|
39
39
|
# Regression test for nevir/rubocop-rspec#115
|
40
40
|
it 'ignores instance variables outside of specs' do
|
41
|
-
|
41
|
+
expect_no_offenses(<<-RUBY, 'lib/source_code.rb')
|
42
42
|
feature do
|
43
43
|
@foo = bar
|
44
44
|
|
@@ -55,7 +55,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'flags an instance variable when it is also assigned' do
|
58
|
-
|
58
|
+
expect_offense(<<-RUBY)
|
59
59
|
describe MyClass do
|
60
60
|
before { @foo = [] }
|
61
61
|
it { expect(@foo).to be_empty }
|
@@ -65,7 +65,7 @@ RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'ignores an instance variable when it is not assigned' do
|
68
|
-
|
68
|
+
expect_no_offenses(<<-RUBY)
|
69
69
|
describe MyClass do
|
70
70
|
it { expect(@foo).to be_empty }
|
71
71
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
RSpec.describe RuboCop::Cop::RSpec::InvalidPredicateMatcher do
|
2
|
+
subject(:cop) { described_class.new }
|
3
|
+
|
4
|
+
it 'registers an offense for double question' do
|
5
|
+
expect_offense(<<-RUBY)
|
6
|
+
expect(foo).to be_something?
|
7
|
+
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'registers an offense for double question with `not_to`' do
|
12
|
+
expect_offense(<<-RUBY)
|
13
|
+
expect(foo).not_to be_something?
|
14
|
+
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'registers an offense for double question with `to_not`' do
|
19
|
+
expect_offense(<<-RUBY)
|
20
|
+
expect(foo).to_not be_something?
|
21
|
+
^^^^^^^^^^^^^ Omit `?` from `be_something?`.
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'registers an offense for double question with `have_something?`' do
|
26
|
+
expect_offense(<<-RUBY)
|
27
|
+
expect(foo).to have_something?
|
28
|
+
^^^^^^^^^^^^^^^ Omit `?` from `have_something?`.
|
29
|
+
RUBY
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts valid predicate matcher' do
|
33
|
+
expect_no_offenses(<<-RUBY)
|
34
|
+
expect(foo).to be_something
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
end
|
@@ -11,14 +11,14 @@ RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do
|
|
11
11
|
let(:enforced_style) { :it_behaves_like }
|
12
12
|
|
13
13
|
it 'flags a violation for it_should_behave_like' do
|
14
|
-
|
14
|
+
expect_offense(<<-RUBY)
|
15
15
|
it_should_behave_like 'a foo'
|
16
16
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_behaves_like` over `it_should_behave_like` when including examples in a nested context.
|
17
17
|
RUBY
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'does not flag a violation for it_behaves_like' do
|
21
|
-
|
21
|
+
expect_no_offenses("it_behaves_like 'a foo'")
|
22
22
|
end
|
23
23
|
|
24
24
|
include_examples(
|
@@ -32,14 +32,14 @@ RSpec.describe RuboCop::Cop::RSpec::ItBehavesLike, :config do
|
|
32
32
|
let(:enforced_style) { :it_should_behave_like }
|
33
33
|
|
34
34
|
it 'flags a violation for it_behaves_like' do
|
35
|
-
|
35
|
+
expect_offense(<<-RUBY)
|
36
36
|
it_behaves_like 'a foo'
|
37
37
|
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_should_behave_like` over `it_behaves_like` when including examples in a nested context.
|
38
38
|
RUBY
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'does not flag a violation for it_behaves_like' do
|
42
|
-
|
42
|
+
expect_no_offenses("it_should_behave_like 'a foo'")
|
43
43
|
end
|
44
44
|
|
45
45
|
include_examples(
|