| 31 | | end |
| 32 | | |
| 33 | | after do |
| 34 | | @dplug.clear |
| 35 | | end |
| 36 | | |
| 37 | | it "should rescue plugins' exception" do |
| 38 | | @core.instance_variable_set(:@plugins, Plugins.new("/dev/null")) |
| | 29 | |
| | 30 | @temp = Pathname.tempname |
| | 31 | @temp.mkpath |
| | 32 | |
| | 33 | @pdir = @temp + "plugins" |
| | 34 | @pdir.mkpath |
| | 35 | |
| | 36 | @ddir = @temp + "data" |
| | 37 | @ddir.mkpath |
| | 38 | |
| | 39 | @conf = @temp + "config.yaml" |
| | 40 | @conf.open("w") do |f| |
| | 41 | f << <<-EOS.gsub(/^\t+/, "") |
| | 42 | --- |
| | 43 | general: |
| | 44 | host: charlotte |
| | 45 | port: 6669 |
| | 46 | user: chokan |
| | 47 | nick: chokan |
| | 48 | real: chokan bot via Tiarra |
| | 49 | error: "#chokan" |
| | 50 | plugin_dir: #{@pdir} |
| | 51 | data_dir: #{@ddir} |
| | 52 | charset: |
| | 53 | default: utf-8 |
| | 54 | |
| | 55 | plugins: |
| | 56 | System: |
| | 57 | operator: "foo!bar@localhost" |
| | 58 | |
| | 59 | Foo: |
| | 60 | disabled: |
| | 61 | - "#disabled" |
| | 62 | |
| | 63 | Bar: |
| | 64 | enabled: |
| | 65 | - "#enabled" |
| | 66 | |
| | 67 | Test: |
| | 68 | EOS |
| | 69 | end |
| | 70 | |
| | 71 | (@pdir + "system.rb").open("w") do |f| |
| | 72 | f.puts File.read("plugins/system.rb") |
| | 73 | end |
| | 74 | |
| | 75 | %w(Foo Bar).each do |name| |
| | 76 | (@pdir + "#{name.downcase}.rb").open("w") do |f| |
| | 77 | f << <<-EOS.gsub(/^\t+/, "") |
| | 78 | require "thread" |
| | 79 | class #{name} |
| | 80 | include Net::IRC |
| | 81 | include Constants |
| | 82 | |
| | 83 | attr_reader :config |
| | 84 | |
| | 85 | def initialize(core, config) |
| | 86 | @core, @config = core, config[self.class.name.sub(/.+::/, "")] || {} |
| | 87 | @messages = {} |
| | 88 | end |
| | 89 | |
| | 90 | def method_missing(method, *args) |
| | 91 | @messages[method] = args |
| | 92 | end |
| | 93 | |
| | 94 | def m |
| | 95 | @messages |
| | 96 | end |
| | 97 | end |
| | 98 | EOS |
| | 99 | end |
| | 100 | end |
| | 101 | |
| | 102 | (@pdir + "test.rb").open("w") do |f| |
| | 103 | f << <<-EOS.gsub(/^\t+/, "") |
| | 104 | require "thread" |
| | 105 | class Test < Citrus::Plugin |
| | 106 | |
| | 107 | attr_reader :config |
| | 108 | |
| | 109 | def on_notice(prefix, channel, message) |
| | 110 | eval(message) if channel == "#eval" |
| | 111 | end |
| | 112 | |
| | 113 | def on_message(m) |
| | 114 | @messages ||= SizedQueue.new(1) |
| | 115 | @messages << m |
| | 116 | end |
| | 117 | end |
| | 118 | EOS |
| | 119 | end |
| | 120 | |
| | 121 | @sock = StringIO.new |
| | 122 | |
| | 123 | @core = Core.new(@conf) |
| | 124 | @core.instance_variable_set(:@socket, @sock) |
| | 125 | |
| 139 | | @core.config.plugins["Foo"]["disabled"].should == ["#foo"] |
| 140 | | @core.config.plugins["Foo"]["enabled"].should == nil |
| 141 | | |
| 142 | | @core.plugins["Foo"].results.clear |
| 143 | | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| 144 | | @core.plugins["Foo"].results[:on_privmsg].should_not == ["foo!bar@localhost", "#foo", "message"] |
| 145 | | |
| 146 | | @core.plugins["Foo"].results.clear |
| | 234 | @core.config.plugins["Foo"]["disabled"] = ["#foo"] |
| | 235 | @core.config.plugins["Foo"]["enabled"] = nil |
| | 236 | |
| | 237 | @core.plugins.loaded_plugins["Foo"].m.clear |
| | 238 | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| | 239 | @core.plugins.loaded_plugins["Foo"].m[:on_privmsg].should_not == ["foo!bar@localhost", "#foo", "message"] |
| | 240 | |
| | 241 | @core.plugins.loaded_plugins["Foo"].m.clear |
| 151 | | @core.config.plugins["Bar"]["disabled"].should == nil |
| 152 | | @core.config.plugins["Bar"]["enabled"].should == ["#foo"] |
| 153 | | |
| 154 | | @core.plugins["Bar"].results.clear |
| 155 | | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| 156 | | @core.plugins["Bar"].results[:on_privmsg].should == ["foo!bar@localhost", "#foo", "message"] |
| 157 | | |
| 158 | | @core.plugins["Bar"].results.clear |
| | 246 | @core.config.plugins["Bar"]["disabled"] = nil |
| | 247 | @core.config.plugins["Bar"]["enabled"] = ["#foo"] |
| | 248 | |
| | 249 | @core.plugins.loaded_plugins["Bar"].m.clear |
| | 250 | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| | 251 | @core.plugins.loaded_plugins["Bar"].m[:on_privmsg].should == ["foo!bar@localhost", "#foo", "message"] |
| | 252 | |
| | 253 | @core.plugins.loaded_plugins["Bar"].m.clear |
| 170 | | @core.plugins["Foo"].results[:on_privmsg].should be_nil |
| 171 | | |
| 172 | | @core.plugins["Foo"].results.clear |
| 173 | | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| 174 | | @core.plugins["Foo"].results[:on_privmsg].should == ["foo!bar@localhost", "#foo", "message"] |
| 175 | | |
| 176 | | @core.plugins["Bar"].results.clear |
| | 265 | @core.plugins.loaded_plugins["Foo"].m[:on_privmsg].should be_nil |
| | 266 | |
| | 267 | @core.plugins.loaded_plugins["Foo"].m.clear |
| | 268 | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| | 269 | @core.plugins.loaded_plugins["Foo"].m[:on_privmsg].should == ["foo!bar@localhost", "#foo", "message"] |
| | 270 | |
| | 271 | @core.plugins.loaded_plugins["Bar"].m.clear |
| 178 | | @core.plugins["Bar"].results[:on_privmsg].should == ["foo!bar@localhost", "#foo-ja", "message"] |
| 179 | | |
| 180 | | @core.plugins["Bar"].results.clear |
| 181 | | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| 182 | | @core.plugins["Bar"].results[:on_privmsg].should be_nil |
| | 273 | @core.plugins.loaded_plugins["Bar"].m[:on_privmsg].should == ["foo!bar@localhost", "#foo-ja", "message"] |
| | 274 | |
| | 275 | @core.plugins.loaded_plugins["Bar"].m.clear |
| | 276 | @core.on_privmsg(Message.new(@prefix, PRIVMSG, ["#foo", "message"])) |
| | 277 | @core.plugins.loaded_plugins["Bar"].m[:on_privmsg].should be_nil |