Sha256: 377f3530b462295e834719f40b82fcb803efc0f28422d0463f99a88c9d692dfa

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

require 'wisper'
require_relative '../../../../lib/wisper/rspec/matchers'

describe Wisper::RSpec::BroadcastMatcher::Matcher do
  let(:event_name) { 'it_happened' }
  let(:matcher)    { described_class.new(event_name) }

  let(:broadcaster) do
    Class.new do
      include Wisper.publisher

      public :broadcast
    end.new
  end

  context 'matching event broadcast' do
    let(:block) do
      Proc.new do
        broadcaster.broadcast(event_name)
      end
    end

    describe '#matches?' do
      it 'returns true' do
        expect(matcher.matches?(block)).to be_truthy
      end
    end
  end

  context 'no events broadcast' do
    let(:block) { Proc.new {} }

    describe '#matches?' do
      it 'returns false' do
        expect(matcher.matches?(block)).to be_falsey
      end
    end

    describe '#failure_message' do
      before { matcher.matches?(block) }

      it 'has descriptive failure message' do
        expect(matcher.failure_message).to eq "expected publisher to broadcast #{event_name} event (no events broadcast)"
      end
    end
  end

  context 'non-matching event broadcast' do
    let(:block) do
      Proc.new do
        broadcaster.broadcast('event1')
        broadcaster.send(:broadcast, 'event2', 12345, :foo)
      end
    end

    describe '#matches?' do
      it 'returns false' do
        expect(matcher.matches?(block)).to be_falsey
      end
    end

    describe '#failure_message' do
      before { matcher.matches?(block) }

      it 'has descriptive failure message' do
        message = "expected publisher to broadcast it_happened event "\
          "(actual events broadcast: event1, event2(12345, foo))"
        expect(matcher.failure_message).to eq(message)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wisper-rspec-1.1.0 spec/wisper/rspec/unit/broadcast_matcher_spec.rb
wisper-rspec-1.0.1 spec/wisper/rspec/unit/broadcast_matcher_spec.rb
wisper-rspec-1.0.0 spec/wisper/rspec/unit/broadcast_matcher_spec.rb
wisper-rspec-0.0.3 spec/wisper/rspec/unit/broadcast_matcher_spec.rb