Sha256: 4a7d737240c428456e6271eca52fd5ce57a31a1ad03ae55b6d20a3f29a28d53c

Contents?: true

Size: 799 Bytes

Versions: 3

Compression:

Stored size: 799 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.new(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.0 spec/plumbing/custom_filter_spec.rb
standard-procedure-plumbing-0.3.3 spec/plumbing/custom_filter_spec.rb
standard-procedure-plumbing-0.3.2 spec/plumbing/custom_filter_spec.rb