Sha256: 69568aded60a555fe4c99999edc929949af6f0f48c805151d82a5b641c7ec76b

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"
require "baton"
require "baton/consumer"
require "baton/server"
require 'ostruct'

describe Baton::Consumer do

  before :each do
    Baton::Server.any_instance.stub(:facts).and_return({
      "fqdn" => "camac.dsci.it",
      "chef_environment" => "production"
    })
    @server = Baton::Server.new
  end

  let(:payload) do
    JSON({"type" => "message type" })
  end

  subject {
    Baton::Consumer.new("deploy-consumer", @server)
  }

  describe "#routing_key" do
    context "given an instance of Baton::Consumer" do
      it "should return a routing key" do
        subject.routing_key.should eq("deploy-consumer.production")
      end
    end
  end

  describe "#exception_notifier" do
    context "given a block that doesn't raise an error" do
      it "should not raise an error" do
        expect{
          subject.exception_notifier do
            a = 1
          end
        }.to_not raise_error
      end
    end

    context "given a block that raises an error" do
      it "should catch the error notify" do
        subject.should_receive(:notify_error)
        subject.exception_notifier do
          raise
        end
      end
    end
  end

  describe "#handle_message" do
    context "given a payload" do
      it "should call process_message" do
        subject.should_receive(:process_message).with(JSON.parse(payload))
        subject.handle_message(payload)
      end
    end
  end

  describe "#attributes" do
    context "given an instance of a consumer" do
      it "should have empty attributes" do
        subject.attributes.should eq({})
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
baton-0.5.4 spec/baton/consumer_spec.rb
baton-0.5.2 spec/baton/consumer_spec.rb
baton-0.4.10 spec/baton/consumer_spec.rb
baton-0.4.9 spec/baton/consumer_spec.rb
baton-0.4.8 spec/baton/consumer_spec.rb