Sha256: a14fcb3deb11375361b89f49e25b5152846b4b0629595709ecc7e3d1525c4c98

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'
require 'support/active_record'

describe Travis::Notifications::Webhook do
  include Support::ActiveRecord

  before do
    Travis.config.notifications = [:webhook]
    stub_http
  end

  let(:dispatch) { lambda { |event, object| Travis::Notifications.dispatch(event, object) } }

  it 'sends webhook notifications to the urls given as an array' do
    targets = ['http://evome.fr/notifications', 'http://example.com/']
    build = Factory(:build, :config => { 'notifications' => { 'webhooks' => targets } })
    dispatch.should post_webhooks_on('build:finished', build, :to => targets)
  end

  it 'sends webhook notifications to a url given as a string' do
    target = 'http://evome.fr/notifications'
    build = Factory(:build, :config => { 'notifications' => { 'webhooks' => target } })
    dispatch.should post_webhooks_on('build:finished', build, :to => ['http://evome.fr/notifications'])
  end

  it 'sends no webhook if the given url is blank' do
    build = Factory(:build, :config => { 'notifications' => { 'webhooks' => '' } })
    # No need to assert anything here as Faraday would complain about a request not being stubbed <3
    dispatch.call('build:finished', build)
  end

  def stub_http
    $http_stub ||= Faraday::Adapter::Test::Stubs.new
    Travis::Notifications::Webhook.http_client = Faraday.new do |f|
      f.request :url_encoded
      f.adapter :test, $http_stub
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 spec/travis/notifications/webhook_spec.rb