Sha256: 1b0db4107d2f2b12c7aaef2ba9f3ac1292dfefa5746d188f4e70a35e3ccea709

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

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

RSpec::configure do |config|
  config.include(Wisper::RSpec::BroadcastMatcher)
end

describe 'broadcast matcher' do
  let(:publisher_class) { Class.new { include Wisper::Publisher } }
  let(:publisher)       { publisher_class.new }

  it 'passes when publisher broadcasts inside block' do
    expect { publisher.send(:broadcast, :foobar) }.to broadcast(:foobar)
  end

  context 'with arguments' do
    it 'passes when publisher broadcasts inside block' do
      expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to broadcast(:fizzbuzz, 12345)
    end

    it 'passes without arguments when publisher broadcasts inside block' do
      expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to broadcast(:fizzbuzz)
    end

    it 'passes with rspect arguments matchers' do
      expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to broadcast(:fizzbuzz, kind_of(Numeric))
    end

    it 'fails with rspec arguments matchers' do
      expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to_not broadcast(:fizzbuzz, kind_of(Hash))
    end

    it 'fails with incorrect arguments when publisher broadcasts inside block' do
      expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.not_to broadcast(:fizzbuzz, 98765)
    end
  end

  context 'with compound assertions' do
    it 'passes when both values are expected' do
      expect {
        publisher.send(:broadcast, :fizzbuzz, 12345)
        publisher.send(:broadcast, :fizzbuzz, 54321)
      }.to broadcast(:fizzbuzz, 12345).and broadcast(:fizzbuzz, 54321)
    end

    it 'passes when either value is expected' do
      expect {
        publisher.send(:broadcast, :fizzbuzz, 54321)
      }.to broadcast(:fizzbuzz, 12345).or broadcast(:fizzbuzz, 54321)
    end
  end

  it 'passes with not_to when publisher does not broadcast inside block' do
    expect { publisher }.not_to broadcast(:foobar)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wisper-rspec-1.0.1 spec/wisper/rspec/matchers_spec.rb
wisper-rspec-1.0.0 spec/wisper/rspec/matchers_spec.rb
wisper-rspec-0.0.3 spec/wisper/rspec/matchers_spec.rb