# The MIT License # Copyright © 2009 Magnus Bergmark # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require File.dirname(__FILE__) + '/../../spec_helper' # Pre-define Meow for systems without it installed class ::Meow; end describe "Meow notifier plugin" do it "should be available when the gem is installed and loadable" do GitRemoteMonitor::Notifiers::Meow.should_receive(:require).with('meow').and_return(true) GitRemoteMonitor::Notifiers::Meow.available?.should be_true end it "should be available when the gem is installed and loadable" do GitRemoteMonitor::Notifiers::Meow.should_receive(:require).with('meow').and_raise(LoadError) GitRemoteMonitor::Notifiers::Meow.available?.should be_false end describe "instance" do before(:each) do meow_instance = mock("Meow gem") Meow.should_receive(:new).with("git-remote-monitor").and_return(meow_instance) @instance = GitRemoteMonitor::Notifiers::Meow.new @instance.instance_eval { @meow = meow_instance } @meow = meow_instance end it "should send notifications correctly when a message is generated" do status = mock("Status object") @instance.should_receive(:get_message).with(status).and_return("A message") @instance.should_receive(:notification_title).with(status).and_return("Title") @instance.should_receive(:notification_icon).with(status).and_return("icon") @instance.should_receive(:notification_type).with(status).and_return("type") @meow.should_receive(:notify).with("Title", "A message", :icon => "icon", :note_type => "type") @instance.send_notification!(status) end it "should not send notifications when a message isn't generated" do status = mock("Status object") @instance.should_receive(:get_message).with(status).and_return(nil) @meow.should_not_receive(:notify) @instance.send_notification!(status) end it "should use a correct message type" do status = mock("Status object", :type => :foobar) @instance.send(:notification_type, status).should == "Foobar" end it "should format message title" do status = mock("Status object", :name => 'repo', :branch_name => 'master') @instance.send(:notification_title, status).should == "repo (master)" end it "should use correct image path" do status = mock("Status object") GitRemoteMonitor.stub!(:root => '/root') @instance.send(:notification_icon, status).should == "/root/images/git-logo.png" end describe "generating message body" do before(:each) do @status = mock("Status object", :remote_commits => 12, :local_commits => 1) end it "should raise error when the status type is unknown" do @status.stub!(:type => :unknown) lambda { @instance.send(:get_message, @status) }.should raise_error end it "should work with diverged status" do @status.stub!(:type => :diverged) @instance.send(:get_message, @status).should == "Diverged! Remote has 12 new commit(s), and you have 1 commit(s) to push." end it "should work with remote changes" do @status.stub!(:type => :remote) @instance.send(:get_message, @status).should == "Remote got updated! Now 12 commit(s) in front of you." end it "should not return anything if the changes are local" do @status.stub!(:type => :local) @instance.send(:get_message, @status).should be_nil end end end end