-
Notifications
You must be signed in to change notification settings - Fork 0
/
rubyholdem_spec.rb
137 lines (113 loc) · 4.04 KB
/
rubyholdem_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
=begin
Copyright 2009 Time
This file is part of RubyHoldem.
RubyHoldem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RubyHoldem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RubyHoldem. If not, see <http://www.gnu.org/licenses/>.
=end
require 'rubyholdem'
describe OpenHoldem do
before do
@o = OpenHoldem
@pwd = "/foo/bar"
Dir.stub!(:pwd).and_return { @pwd }
@loads = 0
Kernel.stub!(:load).with("#@pwd/pokerbot.rb").and_return { @loads += 1; true }
File.stub!(:mtime).with("#@pwd/pokerbot.rb").and_return { @mtime }
@mtime = Time.now
end
it "should load pokerbot.rb on load_pokerbot" do
@o.load_pokerbot
@loads.should == 1
end
it "should call load_pokerbot on event load and return 0.0" do
@o.should_receive(:load_pokerbot).with().once
@o.process_event("load").should == 0.0
end
it "should not load pokerbot.rb on event other than load and return 0.0" do
@o.should_not_receive(:load_pokerbot)
@o.process_event("foo").should == 0.0
end
it "should call get_symbol on []" do
symbol = mock("symbol")
symbol_to_s = mock("symbol#to_s")
result = mock("result")
chair = mock("chair")
symbol.should_receive(:to_s).and_return(symbol_to_s)
@o.should_receive(:get_symbol).once.with(0, "userchair").and_return(chair)
@o.should_receive(:get_symbol).once.with(chair, symbol_to_s).and_return(result)
@o[symbol].should == result
end
it "should reload_pokerbot and propagate queries to the bot when it process_query" do
bot = mock("bot")
query = mock("query")
result = mock("result")
@o.bot = bot
pokerbot_reloaded = false
@o.should_receive(:reload_pokerbot).with().once.and_return do
pokerbot_reloaded = true
end
bot.should_receive(:process_query).with(query).and_return do
pokerbot_reloaded.should == true
result
end
@o.process_query(query).should == result
end
%w( process_state process_query ).each do |process_method|
it "should reload_pokerbot and propagate to the bot when it #{process_method}" do
bot = mock("bot")
param = mock("param")
result = mock("result")
@o.bot = bot
pokerbot_reloaded = false
@o.should_receive(:reload_pokerbot).with().once.and_return do
pokerbot_reloaded = true
end
bot.should_receive(process_method).with(param).and_return do
pokerbot_reloaded.should == true
result
end
@o.send(process_method, param).should == result
end
end
it "should store mtime on load_pokerbot" do
@o.pokerbot_mtime = "wrong mtime"
@o.load_pokerbot
@o.pokerbot_mtime.should == @mtime
end
# because when load fails we don't want to load it until it has changed again
it "should store mtime before load on load_pokerbot" do
@o.pokerbot_mtime = "wrong mtime"
Kernel.should_receive(:load).and_return do
@o.pokerbot_mtime.should == @mtime
end
@o.load_pokerbot
end
it "should load_pokerbot when mtime has changed on reload_pokerbot" do
@o.load_pokerbot
@mtime += 1
@o.should_receive(:load_pokerbot).with().once
@o.reload_pokerbot
end
it "should not load_pokerbot when mtime has not changed on reload_pokerbot" do
@o.load_pokerbot
@o.should_not_receive(:load_pokerbot)
@o.reload_pokerbot
end
it "should refuse to get symbol from dll (because of thread issues)" do
@o.should_not_receive(:get_symbol)
lambda {
@o["dll$foo"]
}.should raise_error(
RuntimeError,
"dll$ symbols blocked due to threading issues (requested \"dll$foo\")"
)
end
end