# 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__) + '/../../lib/git_remote_monitor' describe GitRemoteMonitor::GitWrapper do before(:all) do # Shortcut :-D @wrapper = GitRemoteMonitor::GitWrapper end describe "fetch" do it "should know if a fetch didn't occur" do @wrapper.should_receive(:call_fetch).and_return "\n" @wrapper.fetch!.should == false end it "should know if a fetch occured" do @wrapper.should_receive(:call_fetch).and_return( "remote: Generating pack...\n" + "remote: Done counting 119 objects.\n" + "remote: Result has 90 objects.\n" + "remote: Deltifying 90 objects.\n" + "remote: 100% (90/90) done\n" + "remote: Total 90, written 90 (delta 55), reused 0 (delta 0)\n" + "Unpacking objects: 100% (90/90), done.\n" + "From git@foobar:baz\n" + " e871819..110f4bc master -> origin/master\n" ) @wrapper.fetch!.should == true end end describe "branch discovery" do before(:each) do @wrapper.stub!(:call_get_remote).and_return "" @wrapper.stub!(:call_get_local_branch).and_return " * master" @wrapper.stub!(:call_get_remote).with("master").and_return "upstream\n" end it "should find the current local branch" do @wrapper.local_branch.should == "master" end it "should find the current local branch, even if there are many branches" do @wrapper.stub!(:call_get_local_branch).and_return(" master\n* test\n other") @wrapper.local_branch.should == "test" end it "should find the remote branch" do @wrapper.remote_branch.should == "upstream/master" end it "should return nil when no remote branch exists" do @wrapper.stub!(:call_get_local_branch).and_return "local" @wrapper.remote_branch.should be_nil end end describe "getting tracking information" do before(:each) do @wrapper.stub!(:call_get_tracking_info).and_return " 1 " end it "should be able to get the correct number of commits when nothing has changed" do @wrapper.get_tracking_info("me", "you").should == [0, 0] end it "should be able to get the correct number of commits when diverged" do @wrapper.should_receive(:call_get_tracking_info).and_return(" 1 <\n 7 >") @wrapper.get_tracking_info("me", "you").should == [1, 7] end it "should be able to get the correct number of commits when remote is ahead" do @wrapper.should_receive(:call_get_tracking_info).and_return(" 7 >") @wrapper.get_tracking_info("me", "you").should == [0, 7] end it "should be able to get the correct number of commits when remote is behind" do @wrapper.should_receive(:call_get_tracking_info).and_return(" 1 <") @wrapper.get_tracking_info("me", "you").should == [1, 0] end end end