Sha256: 783bbda0d530ec1aa125248c4957237fb859716c1772edbb211a404423a642a8

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

require File.join(File.dirname(__FILE__), *%w[example_helper])

describe Chatterbox do

  before do
    Chatterbox.logger = Logger.new(nil)
    Chatterbox::Publishers.clear!
  end
  
  after do
    Chatterbox.logger = nil
  end
  
  describe "handle_notice" do
    include Chatterbox
    
    it "should create Notification and return the notice" do
      notification = mock(:notice => {:hash => 'of awesomeness'})
      Chatterbox::Notification.expects(:new).returns(notification)
      handle_notice("message")
    end
    
    it "should publish the notice" do
      notification = stub(:notice => {:hash => 'of awesomeness'})
      Chatterbox::Notification.stubs(:new).returns(notification)
      expects(:publish_notice).with({:hash => 'of awesomeness'})
      handle_notice("message")
    end
    
  end
  
  describe "logger" do
    
    it "uses STDOUT logger if Rails not available" do
      Chatterbox.logger = nil
      
      Logger.expects(:new).with(STDOUT).returns("logger")
      Chatterbox.stubs(:rails_default_logger).returns(nil)
      Chatterbox.logger.should == "logger"
    end
  end
  
  describe "publish" do
    
    include Chatterbox
    
    it "should call each publisher with the notice" do
      notice = stub
      publisher = Chatterbox::Publishers.register { "i'm in your block" }
      publisher.expects(:call).with(notice)
      
      publish_notice(notice)
    end
    
  end

  describe "publishers" do
    
    it "should allow clearing all publishers" do
      Chatterbox::Publishers.register { "sending your messages" }
      Chatterbox::Publishers.publishers.size.should == 1
      Chatterbox::Publishers.clear!
      Chatterbox::Publishers.publishers.size.should == 0
    end
    
    it "should allow registering with a block" do
      pub1 = Chatterbox::Publishers.register { "sending your messages" }
      pub2 = Chatterbox::Publishers.register { "announcing your news" }
      Chatterbox::Publishers.publishers.should == [pub1, pub2]
    end
  end
  
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
relevance-chatterbox-0.1.0 examples/chatterbox_example.rb
relevance-chatterbox-0.2.0 examples/chatterbox_example.rb
relevance-chatterbox-0.2.1 examples/chatterbox_example.rb
relevance-chatterbox-0.2.2 examples/chatterbox_example.rb
relevance-chatterbox-0.3.0 examples/chatterbox_example.rb
relevance-chatterbox-0.3.1 examples/chatterbox_example.rb
relevance-chatterbox-0.3.2 examples/chatterbox_example.rb
relevance-chatterbox-0.3.3 examples/chatterbox_example.rb
chatterbox-0.3.3 examples/chatterbox_example.rb