Sha256: 20098b130d0124dc537d6aed9e79e4efc2239b26a805780065211312c145f55b

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env rspec -cfd

require_relative '../spec_helper'

require 'arborist/event'


describe Arborist::Event do

	it "derives its type name from its class" do
		payload = { 'status' => ['up', 'down'] }
		expect( TestEvent.new(payload).type ).to eq( 'test.event' )
	end


	it "copies the payload it's constructed with" do
		payload = { 'status' => ['up', 'down'] }

		ev = TestEvent.create( TestEvent, payload )
		payload.clear

		expect( ev.payload ).to include( 'status' )
	end


	describe "subscription support" do

		it "matches a subscription with only an event type if the type is the same" do
			sub = Arborist::Subscription.new( 'test.event' ) {}
			event = described_class.create( TestEvent, [] )

			expect( event ).to match( sub )
		end


		it "always matches a subscription with a nil event type" do
			sub = Arborist::Subscription.new {}
			event = described_class.create( TestEvent, [] )

			expect( event ).to match( sub )
		end

	end


	describe "serialization support" do

		it "can represent itself as a Hash" do
			payload = { 'status' => ['up', 'down'] }
			ev = TestEvent.create( TestEvent, payload )

			result = ev.to_h

			expect( result ).to include( :type, :data )

			expect( result[:type] ).to eq( 'test.event' )
			expect( result[:data] ).to eq( payload )
		end


	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arborist-0.3.0 spec/arborist/event_spec.rb
arborist-0.2.0 spec/arborist/event_spec.rb