Sha256: 5c5fe5399c51fc78c850d5d2c7e3a87eb69971e22bb44fa4ac24f511924ba076

Contents?: true

Size: 1.38 KB

Versions: 42

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

require "spec_helper"
require "amq/client/entity"

describe AMQ::Client::Entity do
  let(:klazz) do
    Class.new do
      include AMQ::Client::Entity
    end
  end


  subject do
    klazz.new(Object.new)
  end

  it "should maintain an associative array of callbacks" do
    subject.callbacks.should be_kind_of(Hash)
  end

  describe "#has_callback?" do
    it "should return true if entity has at least one callback with given name" do
      subject.define_callback(:init, proc {})
      subject.has_callback?(:init).should be_true
    end

    it "should return false if entity doesn't have callbacks with given name" do
      subject.has_callback?(:init).should be_false
    end
  end

  describe "#exec_callback" do
    it "executes callback for given event" do
      proc = Proc.new { |*args, &block|
        @called = true
      }

      expect {
        subject.define_callback(:init, proc)
        subject.define_callback :init do
          @called2 = true
        end
      }.to change(subject.callbacks, :size).from(0).to(1)

      subject.callbacks[:init].size.should == 2

      subject.exec_callback(:init)

      @called.should be_true
      @called2.should be_true
    end


    it "should pass arguments to the callback" do
      f = Proc.new { |*args| args.first }
      subject.define_callback :init, f

      subject.exec_callback(:init, 1).should eql([f])
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
amq-client-1.0.4 spec/unit/client/entity_spec.rb
amq-client-1.0.3 spec/unit/client/entity_spec.rb
amq-client-1.1.0.pre1 spec/unit/client/entity_spec.rb
amq-client-1.0.2 spec/unit/client/entity_spec.rb
amq-client-1.0.1 spec/unit/client/entity_spec.rb
amq-client-1.0.0 spec/unit/client/entity_spec.rb
amq-client-0.9.12 spec/unit/client/entity_spec.rb
amq-client-0.9.11 spec/unit/client/entity_spec.rb
amq-client-0.9.10 spec/unit/client/entity_spec.rb
amq-client-0.9.9 spec/unit/client/entity_spec.rb
amq-client-0.9.8 spec/unit/client/entity_spec.rb
amq-client-0.9.7 spec/unit/client/entity_spec.rb
amq-client-0.9.6 spec/unit/client/entity_spec.rb
amq-client-0.9.5 spec/unit/client/entity_spec.rb
amq-client-0.9.4 spec/unit/client/entity_spec.rb
amq-client-1.0.0.pre2 spec/unit/client/entity_spec.rb
amq-client-0.9.3 spec/unit/client/entity_spec.rb
amq-client-1.0.0.pre1 spec/unit/client/entity_spec.rb
amq-client-0.9.2 spec/unit/client/entity_spec.rb
amq-client-0.9.1 spec/unit/client/entity_spec.rb