/
controller_spec.rb
97 lines (83 loc) · 2.92 KB
/
controller_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
# frozen_string_literal: true
require 'listen/silencer/controller'
RSpec.describe Listen::Silencer::Controller do
let(:silencer) { instance_double(Listen::Silencer) }
describe 'append_ignores' do
context 'with no previous :ignore rules' do
subject do
described_class.new(silencer, {})
end
before do
allow(silencer).to receive(:configure).with({})
end
context 'when providing a nil' do
it 'sets the given :ignore rules as empty array' do
subject
allow(silencer).to receive(:configure).with(ignore: [])
subject.append_ignores(nil)
end
end
context 'when providing a single regexp as argument' do
it 'sets the given :ignore rules as array' do
subject
allow(silencer).to receive(:configure).with(ignore: [/foo/])
subject.append_ignores(/foo/)
end
end
context 'when providing multiple arguments' do
it 'sets the given :ignore rules as a flat array' do
subject
allow(silencer).to receive(:configure).with(ignore: [/foo/, /bar/])
subject.append_ignores(/foo/, /bar/)
end
end
context 'when providing as array' do
it 'sets the given :ignore rules' do
subject
allow(silencer).to receive(:configure).with(ignore: [/foo/, /bar/])
subject.append_ignores([/foo/, /bar/])
end
end
end
context 'with previous :ignore rules' do
subject do
described_class.new(silencer, ignore: [/foo/, /bar/])
end
before do
allow(silencer).to receive(:configure).with(ignore: [/foo/, /bar/])
end
context 'when providing a nil' do
# TODO: should this invocation maybe reset the rules?
it 'reconfigures with existing :ignore rules' do
subject
allow(silencer).to receive(:configure).with(ignore: [/foo/, /bar/])
subject.append_ignores(nil)
end
end
context 'when providing a single regexp as argument' do
it 'appends the given :ignore rules as array' do
subject
expected = { ignore: [/foo/, /bar/, /baz/] }
allow(silencer).to receive(:configure).with(expected)
subject.append_ignores(/baz/)
end
end
context 'when providing multiple arguments' do
it 'appends the given :ignore rules as a flat array' do
subject
expected = { ignore: [/foo/, /bar/, /baz/, /bak/] }
allow(silencer).to receive(:configure).with(expected)
subject.append_ignores(/baz/, /bak/)
end
end
context 'when providing as array' do
it 'appends the given :ignore rules' do
subject
expected = { ignore: [/foo/, /bar/, /baz/, /bak/] }
allow(silencer).to receive(:configure).with(expected)
subject.append_ignores([/baz/, /bak/])
end
end
end
end
end