Sha256: 9f8b2a668941e534a9427cf0f2e1fecbcb994362520837406910642148baf754

Contents?: true

Size: 835 Bytes

Versions: 6

Compression:

Stored size: 835 Bytes

Contents

require "spec_helper"

RSpec.describe Plumbing::Filter do
  it "raises a TypeError if it is connected to a non-Pipe" do
    @invalid_source = Object.new

    expect { described_class.start source: @invalid_source }.to raise_error(TypeError)
  end

  it "accepts event types" do
    @pipe = Plumbing::Pipe.start

    @filter = described_class.start source: @pipe do |event|
      %w[first_type third_type].include? event.type.to_s
    end

    @results = []
    @filter.add_observer do |event|
      @results << event
    end

    @pipe << Plumbing::Event.new(type: "first_type", data: nil)
    expect(@results.count).to eq 1

    @pipe << Plumbing::Event.new(type: "second_type", data: nil)
    expect(@results.count).to eq 1

    # Use the alternative syntax
    @pipe.notify "third_type"
    expect(@results.count).to eq 2
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.3 spec/plumbing/filter_spec.rb
standard-procedure-plumbing-0.4.2 spec/plumbing/filter_spec.rb
standard-procedure-plumbing-0.4.1 spec/plumbing/filter_spec.rb
standard-procedure-plumbing-0.4.0 spec/plumbing/filter_spec.rb
standard-procedure-plumbing-0.3.3 spec/plumbing/filter_spec.rb
standard-procedure-plumbing-0.3.2 spec/plumbing/filter_spec.rb