-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontext_spec.rb
More file actions
68 lines (59 loc) · 1.97 KB
/
context_spec.rb
File metadata and controls
68 lines (59 loc) · 1.97 KB
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
require 'spec_helper'
describe Pipes::Context do
describe '#add' do
it 'allows adding new fields' do
subject.add(key: 'val')
expect(subject.key).to eq('val')
end
it 'does not allow rewriting existing fields' do
subject.add(key: 'val')
expect { subject.add(key: 'other_val') }
.to raise_error(Pipes::Context::Override)
end
it 'does not allow modifying existing fields' do
subject.add(key: 'val')
expect { subject.key << 'ue' }.to raise_error(FrozenError)
end
it 'allows rewriting existing mutable fields' do
subject.add({}, key: 'val')
expect { subject.add(key: 'other_val') }
.to change { subject.key }.from('val').to 'other_val'
end
it 'allows modifying existing mutable fields' do
subject.add({}, key: 'val')
expect { subject.key << 'ue' }
.to change { subject.key }.from('val').to 'value'
end
end # describe '#add'
describe '#inspect' do
it 'lists all fields' do
subject.add(bacon: 'yum', raisins: 'bleh')
expect(subject.inspect)
.to match(/bacon=\"yum\", raisins=\"bleh\", @errors=nil/)
end
it 'lists nested contexts' do
subject.add(nested: Pipes::Context.new(foo: 'bar'))
expect(subject.inspect)
.to match(/nested=#<Pipes::Context:0x\w+ foo="bar", @errors=nil>,/)
end
end # describe '#inspect'
describe '#add_errors' do
it 'adds error to error_collector' do
subject.add_errors(base: 'Error message')
subject.add_errors(
base: ['Another error message'],
user: 'User error message'
)
expect(subject.errors).to eq(
base: ['Error message', 'Another error message'],
user: ['User error message']
)
end
end # describe '#add_errors'
describe '#halt' do
it 'adds error to error collector :base' do
subject.halt('Some error')
expect(subject.error).to eq('Some error')
end
end # describe '#halt'
end # describe Pipes::Context