-
Notifications
You must be signed in to change notification settings - Fork 2
/
terminal_spec.rb
84 lines (64 loc) · 1.88 KB
/
terminal_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
require 'spec_helper'
require 'circuits/terminal'
describe Circuits::Terminal do
describe '#get' do
let(:state) { double('state') }
context 'when given no state' do
subject { Circuits::Terminal.new }
it 'is false' do
expect(subject.get).to eq(false)
end
end
context 'when given a state' do
subject { Circuits::Terminal.new(state: state) }
it 'has that state' do
expect(subject.get).to eq(state)
end
end
context 'when given terminal' do
let(:terminal) { Circuits::Terminal.new(state: state) }
subject { Circuits::Terminal.new(terminal: terminal) }
it 'is false' do
expect(subject.get).to eq(false)
end
end
end
describe '#set' do
let(:state_1) { double('state_1') }
let(:state_2) { double('state_2') }
context 'when given a state' do
subject { Circuits::Terminal.new(state: state_1) }
it 'gets set immediately' do
subject.set state_2
expect(subject.get).to eq(state_2)
end
end
context 'when given a terminal' do
let(:terminal) { Circuits::Terminal.new(state: state_2) }
subject { Circuits::Terminal.new(state: state_1) }
it 'gets does not get set immediately' do
subject.set terminal
expect(subject.get).to eq(state_1)
end
end
end
describe '#tock' do
let(:state) { double('state') }
context 'when passed a state' do
subject { Circuits::Terminal.new }
it 'moves next set to get' do
subject.set state
subject.tock
expect(subject.get).to eq(state)
end
end
context 'when given terminal' do
let(:terminal) { Circuits::Terminal.new(state: state) }
subject { Circuits::Terminal.new(terminal: terminal) }
it 'is has that state' do
subject.tock
expect(subject.get).to eq(state)
end
end
end
end