Sha256: 73c521328a93fe3ca0d1f4442ead00c6114a4fcf7dd38b9ced56278e1e9d9e9e

Contents?: true

Size: 1.03 KB

Versions: 39

Compression:

Stored size: 1.03 KB

Contents

require 'awestruct/handler_chain'
require 'hashery'

describe Awestruct::HandlerChain do

  class BaseMockHandler 
    attr_reader :site, :arg
    def initialize(site, arg)
      @site, @arg = site, arg
    end
  end

  class HandlerOne   < BaseMockHandler; end
  class HandlerTwo   < BaseMockHandler; end
  class HandlerThree < BaseMockHandler; end


  before :all do
    @site = Hashery::OpenCascade[ { :encoding => false } ]
  end

  it "should use a regexp to match" do
    chain = Awestruct::HandlerChain.new( /foo/ )
    chain.should be_matches( "foot" )
    chain.should_not be_matches( "hand" )
  end

  it "should nest handlers in order, first being deepest" do
    chain = Awestruct::HandlerChain.new( /foo/ )
    chain.handler_classes << HandlerOne
    chain.handler_classes << HandlerTwo
    chain.handler_classes << HandlerThree

    result = chain.create( @site, "foot" )

    result.should be_a HandlerThree
    result.arg.should be_a HandlerTwo
    result.arg.arg.should be_a HandlerOne
    result.arg.arg.arg.should == "foot"
  end

end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
awestruct-0.5.6.beta5 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta4 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta3 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta2 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta spec/awestruct/handler_chain_spec.rb
awestruct-0.5.5 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.4.2 spec/handler_chain_spec.rb
awestruct-0.5.4.1 spec/handler_chain_spec.rb
awestruct-0.5.4 spec/handler_chain_spec.rb
awestruct-0.5.4.rc3 spec/handler_chain_spec.rb
awestruct-0.5.4.rc2 spec/handler_chain_spec.rb
awestruct-0.5.4.rc spec/handler_chain_spec.rb
awestruct-0.5.4.beta1 spec/handler_chain_spec.rb
awestruct-0.5.3 spec/handler_chain_spec.rb
awestruct-0.5.2.1 spec/handler_chain_spec.rb
awestruct-0.5.2 spec/handler_chain_spec.rb
awestruct-0.5.1 spec/handler_chain_spec.rb
awestruct-0.5.1a spec/handler_chain_spec.rb
awestruct-0.5.0 spec/handler_chain_spec.rb