Sha256: 39e26f504a3887784531077c92829a4bca6f74382f72d0449ee77c9344d92114

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"

describe "Baton::Observer module" do

  let(:my_observer) {
    class MyObserver
      include Baton::Observer

      def attributes
        {name: "my_observer_name"}
      end
    end
    MyObserver.new
  }

  describe "#notify_error" do
    context "given an error message" do
      it "should notify the observers about it" do
        my_observer.should_receive(:notify_observers).with(
          {:name=>"my_observer_name", :type=>"error", :error_class=>Exception, :error_message=>"an error"})
        my_observer.notify_error(Exception, "an error")
      end
    end
  end

  describe "#notify_info" do
    context "given an info message" do
      it "should notify the observers about it" do
        my_observer.should_receive(:notify_observers).with(
          {:name=>"my_observer_name", :type=>"info", :message=>"a message"})
        my_observer.notify_info("a message")
      end
    end
  end

  describe "#notify_success" do
    context "given a success message" do
      it "should notify the observers about it" do
        my_observer.should_receive(:notify_observers).with(
          {:name=>"my_observer_name", :type=>"success", :message=>"a success message"})
        my_observer.notify_success("a success message")
      end
    end
  end

  describe "#notify_log" do
    context "given a set or attributes" do
      it "should notify the observers with those attributes" do
        my_observer.should_receive(:notify_observers).with(
         {:name=>"my_observer_name", :attr_1=>1, :attr_2=>2})
        my_observer.notify_log({attr_1: 1, attr_2: 2})
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
baton-0.7.0 spec/baton/observer_spec.rb
baton-0.6.0 spec/baton/observer_spec.rb
baton-0.5.6 spec/baton/observer_spec.rb
baton-0.5.5 spec/baton/observer_spec.rb