root/lang/ruby/citrus/trunk/plugins/simple_reply.rb

Revision 6594, 1.1 kB (checked in by cho45, 7 months ago)

lang/ruby/chokan/branches/citrus/plugins:

テスト時の @socket には Queue をつかうように。

  • スレッドを扱うテストをスマートかつ確実に書けるように

Line 
1
2class SimpleReply < Citrus::Plugin
3        def on_privmsg(prefix, channel, message)
4                @config["replies"].each do |r|
5                        if r["words"].include?(message) &&
6                           (!r["channels"] || r["channels"].include?(channel))
7
8                                notice channel, r["reply"]
9                        end
10                end
11        end
12end
13
14tests do
15
16        describe SimpleReply do
17                before :all do
18                        @core   = DummyCore.new({})
19                        @socket = @core.socket
20                        @prefix = Net::IRC::Prefix.new("foo!foo@localhsot")
21
22                        @plugin = SimpleReply.new(@core, { "SimpleReply" => {
23                                "replies" => [
24                                        {
25                                                "words"    => ["foo", "bar"],
26                                                "channels" => "#test",
27                                                "reply"    => "Nice boat.",
28                                        }
29                                ]
30                        } })
31                end
32
33                it "should reply correctly" do
34                        @socket.clear
35                        @plugin.on_privmsg(@prefix, "#test", "foo")
36                        @socket.pop.to_s.should == "NOTICE #test :Nice boat.\r\n"
37
38                        @socket.clear
39                        @plugin.on_privmsg(@prefix, "#test", "bar")
40                        @socket.pop.to_s.should == "NOTICE #test :Nice boat.\r\n"
41
42                        @socket.clear
43                        @plugin.on_privmsg(@prefix, "#test", "baz")
44                        @socket.should be_empty
45
46                        @socket.clear
47                        @plugin.on_privmsg(@prefix, "#test2", "foo")
48                        @socket.should be_empty
49                end
50        end
51
52end
Note: See TracBrowser for help on using the browser.