Sha256: 28a748cbf47a656ba0e4fc0426735ffcfbee480618c828d5e2e56c806bf0886e

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 Bytes

Contents

require "spec_helper"

RSpec.describe Plumbing::CustomFilter 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 "defines a custom filter" do
    # standard:disable Lint/ConstantDefinitionInBlock
    class ReversingFilter < Plumbing::CustomFilter
      def received(event) = notify event.type.reverse, event.data
    end
    # standard:enable Lint/ConstantDefinitionInBlock

    @pipe = Plumbing::Pipe.start
    @filter = ReversingFilter.start(source: @pipe)
    @result = []
    @filter.add_observer do |event|
      @result << event.type
    end

    @pipe.notify "hello"
    @pipe.notify "world"

    expect(@result).to eq ["olleh", "dlrow"]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.3 spec/plumbing/custom_filter_spec.rb
standard-procedure-plumbing-0.4.2 spec/plumbing/custom_filter_spec.rb
standard-procedure-plumbing-0.4.1 spec/plumbing/custom_filter_spec.rb