public
Description: Don't mind this, go to http://github.com/integrity/integrity
Homepage: http://integrityapp.com
Clone URL: git://github.com/foca/integrity.git
integrity / spec / notifier / base_spec.rb
100644 82 lines (63 sloc) 3.013 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require File.dirname(__FILE__) + "/../spec_helper"
 
describe Integrity::Notifier::Base do
  include AppSpecHelper
  include NotifierSpecHelper
 
  it_should_behave_like "A notifier"
  
  def klass
    Integrity::Notifier::Base
  end
 
  it "should raise on #deliver!" do
    notifier = klass.new(mock_build, {})
    lambda { notifier.deliver! }.should raise_error(NoMethodError, /you need to implement this method in your notifier/)
  end
  
  describe "notifying the world of a build" do
    before { klass.stub!(:new).and_return(notifier) }
    
    it "should instantiate a notifier with the given build and config" do
      klass.should_receive(:new).with(mock_build, {}).and_return(notifier)
      klass.notify_of_build(mock_build, notifier_config)
    end
  
    it "should pass the notifier options to the notifier" do
      klass.should_receive(:new).with(anything, notifier_config).and_return(notifier)
      klass.notify_of_build(mock_build, notifier_config)
    end
    
    it "should deliver the notification" do
      notifier.should_receive(:deliver!)
      klass.notify_of_build(mock_build, notifier_config)
    end
  end
  
  describe "generating the config form" do
    it "should raise on #to_haml unless redefined on the inherited class" do
      lambda { klass.to_haml }.should raise_error(NoMethodError, /you need to implement this method in your notifier/)
    end
  end
  
  describe "getting the build message" do
    before { @notifier = klass.new(mock_build, {}) }
    
    it "should have a nice short_message when the build was successful" do
      mock_build.stub!(:successful?).and_return(true)
      @notifier.short_message.should == "Build e7e02b was successful"
    end
    
    it "should have a nice short_message when the build wasn't successful" do
      mock_build.stub!(:successful?).and_return(false)
      @notifier.short_message.should == "Build e7e02b failed"
    end
    
    it "should show the build status on the full_message" do
      mock_build.stub!(:successful?).and_return(true)
      @notifier.full_message.should =~ /Build e7e02bc669d07064cdbc7e7508a21a41e040e70d was successful/
    end
    
    it "should show the commit message on the full_message" do
      @notifier.full_message.should =~ /Commit Message: the commit message/
    end
    
    it "should show the commit date on the full_message" do
      @notifier.full_message.should =~ /Commit Date: Fri Jul 25 18:44:00 [+|-]{1}\d{4} 2008/
    end
 
    it "should show the commit author on the full_message" do
      @notifier.full_message.should =~ /Commit Author: Nicolás Sanguinetti/
    end
    
    it "should show a link back to the integrity build page on the full_message" do
      @notifier.full_message.should =~ %r(Link: http://localhost:4567/integrity/builds/e7e02bc669d07064cdbc7e7508a21a41e040e70d)
    end
    
    it "should show the stripped build output on the full_message" do
      @notifier.full_message.should =~ /Build Output:\n\nthe output with color coding/
    end
  end
end