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.6.7 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.6 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.5 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.4 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.3 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.2 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.1 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.0 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.0.RC1 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.0.alpha4 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.0.alpha3 spec/awestruct/handler_chain_spec.rb
awestruct-0.6.0.alpha1 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.7 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.7.RC2 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.7.RC1 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta9 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta8 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta7 spec/awestruct/handler_chain_spec.rb
awestruct-0.5.6.beta6 spec/awestruct/handler_chain_spec.rb