-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
message_spies_spec.rb
149 lines (125 loc) · 5.07 KB
/
message_spies_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::MessageSpies, :config do
context 'when EnforcedStyle is have_received' do
let(:cop_config) do
{ 'EnforcedStyle' => 'have_received' }
end
it 'flags expect(send).to receive' do
expect_offense(<<-RUBY)
expect(foo).to receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(lvar).to receive' do
expect_offense(<<-RUBY)
foo = baz
expect(foo).to receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(ivar).to receive' do
expect_offense(<<-RUBY)
expect(@foo).to receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `@foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(const).to receive' do
expect_offense(<<-RUBY)
expect(Foo).to receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `Foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(...).not_to receive' do
expect_offense(<<-RUBY)
expect(foo).not_to receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(...).to_not receive' do
expect_offense(<<-RUBY)
expect(foo).to_not receive(:bar)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(...).to receive with' do
expect_offense(<<-RUBY)
expect(foo).to receive(:bar).with(:baz)
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'flags expect(...).to receive at_most' do
expect_offense(<<-RUBY)
expect(foo).to receive(:bar).at_most(42).times
^^^^^^^ Prefer `have_received` for setting message expectations. Setup `foo` as a spy using `allow` or `instance_spy`.
RUBY
end
it 'approves of expect(...).to have_received' do
expect_no_offenses('expect(foo).to have_received(:bar)')
end
include_examples 'detects style', 'expect(foo).to receive(:bar)', 'receive'
include_examples 'detects style',
'expect(foo).to have_received(:bar)',
'have_received'
end
context 'when EnforcedStyle is receive' do
let(:cop_config) do
{ 'EnforcedStyle' => 'receive' }
end
it 'flags expect(send).to have_received' do
expect_offense(<<-RUBY)
expect(foo).to have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(lvar).to have_received' do
expect_offense(<<-RUBY)
foo = baz
expect(foo).to have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(ivar).to have_received' do
expect_offense(<<-RUBY)
expect(@foo).to have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(const).to have_received' do
expect_offense(<<-RUBY)
expect(Foo).to have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(...).not_to have_received' do
expect_offense(<<-RUBY)
expect(foo).not_to have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(...).to_not have_received' do
expect_offense(<<-RUBY)
expect(foo).to_not have_received(:bar)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(...).to have_received with' do
expect_offense(<<-RUBY)
expect(foo).to have_received(:bar).with(:baz)
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'flags expect(...).to have_received at_most' do
expect_offense(<<-RUBY)
expect(foo).to have_received(:bar).at_most(42).times
^^^^^^^^^^^^^ Prefer `receive` for setting message expectations.
RUBY
end
it 'approves of expect(...).to receive' do
expect_no_offenses('expect(foo).to receive(:bar)')
end
include_examples 'detects style', 'expect(foo).to receive(:bar)', 'receive'
include_examples 'detects style',
'expect(foo).to have_received(:bar)',
'have_received'
end
end