-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
verified_doubles_spec.rb
84 lines (73 loc) · 2.05 KB
/
verified_doubles_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
it 'finds a `double` instead of an `instance_double`' do
expect_offense(<<-RUBY)
it do
foo = double("Widget")
^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
context 'when configuration does not specify IgnoreSymbolicNames' do
let(:cop_config) { {} }
it 'find doubles whose name is a symbol' do
expect_offense(<<-RUBY)
it do
foo = double(:widget)
^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
it 'finds a `spy` instead of an `instance_spy`' do
expect_offense(<<-RUBY)
it do
foo = spy("Widget")
^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
end
context 'when configured to ignore symbolic names' do
let(:cop_config) { { 'IgnoreSymbolicNames' => true } }
it 'ignores doubles whose name is a symbol' do
expect_no_offenses(<<-RUBY)
it do
foo = double(:widget)
end
RUBY
end
it 'still flags doubles whose name is a string' do
expect_offense(<<-RUBY)
it do
foo = double("widget")
^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
end
context 'when configured not to ignore nameless doubles' do
let(:cop_config) { { 'IgnoreNameless' => false } }
it 'flags doubles that have no name specified' do
expect_offense(<<-RUBY)
it do
foo = double
^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
end
it 'ignores doubles that have no name specified' do
expect_no_offenses(<<-RUBY)
it do
foo = double
end
RUBY
end
it 'ignores instance_doubles' do
expect_no_offenses(<<-RUBY)
it do
foo = instance_double("Foo")
end
RUBY
end
end