require 'spec/spec_helper' class ErrorPlugin < Scout::Plugin def build_report raise 'FOO' end end class FooPlugin < Scout::Plugin OPTIONS=<<-EOS username: name: Username notes: The MySQL username to use default: other EOS end class OptionsPlugin < Scout::Plugin OPTIONS=<<-EOS host: name: Host notes: The slave host to monitor default: 127.0.0.1 username: name: Username notes: The MySQL username to use default: root EOS end describe Deputy do it "has a VERSION" do Deputy::VERSION.should =~ /^\d+\.\d+\.\d+$/ end def klass(name, options={}) "class TEMP_#{options[:rand]||rand(11111)};def self.interval;60;end;class #{name} < Scout::Plugin; def build_report; #{options[:code]}; end; end; end" end describe Scout do describe :plugins do it "finds plugins" do Scout.plugins(klass('A', :rand => 1111)).inspect.should == '[[60, TEMP_1111::A]]' end it "reprots non-plugins" do Deputy.should_receive(:send_report) Scout.plugins("class Foo;def self.interval;11;end;end").inspect.should == '[]' end end describe :option do it "get default" do OptionsPlugin.new.option(:username).should == 'root' end it "get nil when no default is there" do OptionsPlugin.new.option(:foo).should == nil end it "get nil when no OPTIONS are there" do ErrorPlugin.new.option(:foo).should == nil end it "does not overwrite others" do FooPlugin.new.option(:username).should == 'other' end end end describe :run_plugins do it "executes all plugins" do $notify = 0 Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff' FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb", :body => klass('C', :code => '$notify=1')) Deputy.run_plugins $notify.should == 1 end end describe :send_report do it "sends a report" do Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff' FakeWeb.register_uri(:get, "http://sheri.ff/report/Xxx.yyy?value=123", :body => 'OK') Deputy.send_report('Xxx.yyy', '123').should == 'OK' end end end