forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
implicit_expect_spec.rb
100 lines (80 loc) · 2.55 KB
/
implicit_expect_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
context 'when EnforcedStyle is is_expected' do
let(:cop_config) do
{ 'EnforcedStyle' => 'is_expected' }
end
it 'flags it { should }' do
expect_offense(<<-RUBY)
it { should be_truthy }
^^^^^^ Prefer `is_expected.to` over `should`.
RUBY
expect_correction(<<-RUBY)
it { is_expected.to be_truthy }
RUBY
end
it 'flags it { should_not }' do
expect_offense(<<-RUBY)
it { should_not be_truthy }
^^^^^^^^^^ Prefer `is_expected.to_not` over `should_not`.
RUBY
expect_correction(<<-RUBY)
it { is_expected.to_not be_truthy }
RUBY
end
it 'approves of is_expected.to' do
expect_no_offenses('it { is_expected.to be_truthy }')
end
it 'approves of is_expected.to_not' do
expect_no_offenses('it { is_expected.to_not be_truthy }')
end
it 'approves of is_expected.not_to' do
expect_no_offenses('it { is_expected.not_to be_truthy }')
end
include_examples 'detects style', 'it { should be_truthy }', 'should'
end
context 'when EnforcedStyle is should' do
let(:cop_config) do
{ 'EnforcedStyle' => 'should' }
end
it 'flags it { is_expected.to }' do
expect_offense(<<-RUBY)
it { is_expected.to be_truthy }
^^^^^^^^^^^^^^ Prefer `should` over `is_expected.to`.
RUBY
expect_correction(<<-RUBY)
it { should be_truthy }
RUBY
end
it 'flags it { is_expected.to_not }' do
expect_offense(<<-RUBY)
it { is_expected.to_not be_truthy }
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.to_not`.
RUBY
expect_correction(<<-RUBY)
it { should_not be_truthy }
RUBY
end
it 'flags it { is_expected.not_to }' do
expect_offense(<<-RUBY)
it { is_expected.not_to be_truthy }
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.not_to`.
RUBY
expect_correction(<<-RUBY)
it { should_not be_truthy }
RUBY
end
it 'approves of should' do
expect_no_offenses('it { should be_truthy }')
end
it 'approves of should_not' do
expect_no_offenses('it { should_not be_truthy }')
end
include_examples 'detects style',
'it { is_expected.to be_truthy }',
'is_expected'
include_examples 'detects style',
'it { should be_truthy }',
'should'
end
end