/
test_dialogue_spec.rb
67 lines (57 loc) · 1.53 KB
/
test_dialogue_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
# encoding: utf-8
#
require File.expand_path '../../../lib/james', __FILE__
describe 'TestDialogue' do
context 'unit' do
let(:dialogue) do
Class.new do
include James::Dialog
hear ['test1', 'test2'] => :first
state :first do
hear 'go' => :second, 'stay' => :first
end
state :second do
hear 'go' => :third, 'back' => :first
end
end.new
end
let(:visitor) do
James::Visitor.new dialogue.state_for(:first)
end
describe "integration" do
it 'works correctly' do
visitor.current.name.should == :first
visitor.hear('go') {}
visitor.current.name.should == :second
visitor.hear('back') {}
visitor.current.name.should == :first
visitor.hear('stay') {}
visitor.current.name.should == :first
end
end
end
# context 'integration' do
# let(:dialogue) do
# dialogue = Class.new do
# include James::Dialog
#
# hear ['test1', 'test2'] => :first
# state :first do
# hear 'go' => :second, 'stay' => :first
# end
# state :second do
# hear 'go' => :third, 'back' => :first
# end
# end.new
# end
# it 'works correctly' do
# dialogue.state.name.should == :awake
# dialogue.hear 'sleep'
# dialogue.state.name.should == :sleeping
# end
# it 'delegates correctly' do
# dialogue.state.name.should == :awake
# dialogue.hear 'test1'
# end
# end
end