Sha256: 9fc73481dc4d50abcf472101d0653b1cd2b4e4ad760d63daaddc2458e5f7824a

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Firehose::Producer do
  let(:channel)       { "/channel-awesome" }
  let(:url)           { "#{Firehose::Default::URI}#{channel}"}
  let(:publish_stub)  { stub_request(:put, url) }
  let(:message)       { "hey dude" }

  before(:all) do
    Firehose::Producer.adapter = :net_http
  end

  after(:all) do
    Firehose::Producer.adapter = nil
  end

  it "should publish message to channel" do
    publish_stub.to_return(:body => "", :status => 202)

    Firehose::Producer.new.publish(message).to(channel)
    WebMock.should have_requested(:put, url).with { |req| req.body == message }
  end

  it "should publish message to channel with expiry headers" do
    publish_stub.to_return(:body => "", :status => 202)
    ttl = 20

    Firehose::Producer.new.publish(message).to(channel, :ttl => ttl)
    WebMock.should have_requested(:put, url).with { |req| req.body == message and req.headers['Cache-Control'] == "max-age=#{ttl}" }
  end

  describe "connection error handling" do
    it "should raise PublishError if not 201" do
      publish_stub.to_return(:body => "", :status => 500)

      lambda{
        Firehose::Producer.new.publish(message).to(channel)
      }.should raise_exception(Firehose::Producer::PublishError)
    end

    it "should use .error_handler if not 201" do
      publish_stub.to_return(:body => "", :status => 500)

      producer = Firehose::Producer.new
      producer.on_error do |e|
        e.message.should =~ /could not publish.+to/i
      end
      producer.publish(message).to(channel)
    end

    it "should raise TimeoutError if timed out" do
      publish_stub.to_timeout

      lambda{
        Firehose::Producer.new.publish(message).to(channel)
      }.should raise_exception(Firehose::Producer::TimeoutError)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
firehose-1.1.0 spec/lib/producer_spec.rb
firehose-1.0.0 spec/lib/producer_spec.rb
firehose-0.2.alpha.10 spec/lib/producer_spec.rb
firehose-0.2.alpha.9 spec/lib/producer_spec.rb
firehose-0.2.alpha.8 spec/lib/producer_spec.rb
firehose-0.2.alpha.7 spec/lib/producer_spec.rb
firehose-0.2.alpha.6 spec/lib/producer_spec.rb
firehose-0.2.alpha.5 spec/lib/producer_spec.rb