This repository has been archived by the owner on May 10, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from travis-ci/fix-campfire-notifications
Fix problem with Campfire hook notifying on start.
- Loading branch information
Showing
6 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'spec_helper' | ||
require 'active_support/core_ext/class' | ||
|
||
describe Travis::Notifications::Subscription do | ||
class Travis::Notifications::Handler::SubscriptionTestHandler | ||
class_attribute :events | ||
self.events = [] | ||
|
||
EVENTS = /build:finished/ | ||
|
||
def notify(*args) | ||
self.class.notify(*args) | ||
end | ||
|
||
def self.notify(*args) | ||
events << args | ||
end | ||
end | ||
|
||
let(:subscription) {Travis::Notifications::Subscription.new(:subscription_test_handler)} | ||
|
||
describe "triggering a notification" do | ||
before do | ||
subscription.subscriber.events.clear | ||
end | ||
|
||
it "should notify when the event matches" do | ||
subscription.notify('build:finished') | ||
subscription.subscriber.events.should have(1).item | ||
end | ||
|
||
it "should increment a counter when the event is triggered" do | ||
expect { | ||
subscription.notify('build:finished') | ||
}.to change {Metriks.counter('travis.notifications.subscription_test_handler.build.finished').count} | ||
end | ||
|
||
it "shouldn't notify when the event doesn't match" do | ||
subscription.notify('build:started') | ||
subscription.subscriber.events.should have(0).items | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
require 'support/active_record' | ||
|
||
# A more high-level test for notifications as a whole | ||
describe Travis::Notifications do | ||
include Travis::Notifications | ||
include Support::ActiveRecord | ||
|
||
let(:build) { Factory(:build, :config => { 'notifications' => { 'campfire' => 'evome:apitoken@42' } }) } | ||
describe "notifying of an event" do | ||
describe "campfire" do | ||
before do | ||
Travis.config.notifications = [:campfire] | ||
end | ||
|
||
it "should not publish start events to campfire" do | ||
Travis::Notifications::Handler::Campfire.any_instance.expects(:notify).never | ||
notify("build:started", build) | ||
end | ||
|
||
it "should publish finish events to campfire" do | ||
Travis::Notifications::Handler::Campfire.any_instance.expects(:notify) | ||
notify("build:finished", build) | ||
end | ||
end | ||
|
||
describe "webhooks" do | ||
before do | ||
Travis.config.notifications = [:webhook] | ||
end | ||
|
||
it "should publish start events to webhooks" do | ||
targets = ['http://evome.fr/notifications', 'http://example.com/'] | ||
build.config[:notifications][:webhooks] = {:urls => targets} | ||
Travis::Notifications::Handler::Webhook.any_instance.expects(:notify) | ||
notify("build:started") | ||
end | ||
|
||
it "should publish finish events to webhooks" do | ||
targets = ['http://evome.fr/notifications', 'http://example.com/'] | ||
build.config[:notifications][:webhooks] = {:urls => targets} | ||
Travis::Notifications::Handler::Webhook.any_instance.expects(:notify) | ||
notify("build:finish") | ||
end | ||
end | ||
end | ||
end |