Sha256: 565a9de9fdca65bd4176e4bdda09893f19aa13fbfede8e2a241c0ce6c7252cf2

Contents?: true

Size: 1.6 KB

Versions: 56

Compression:

Stored size: 1.6 KB

Contents

require 'helper'

class FilterWithDispatcherMixin
  include Temple::Mixins::Dispatcher

  def on_test(arg)
    [:on_test, arg]
  end

  def on_test_check(arg)
    [:on_check, arg]
  end

  def on_second_test(arg)
    [:on_second_test, arg]
  end

  def on_a_b(*arg)
    [:on_ab, *arg]
  end

  def on_a_b_test(arg)
    [:on_ab_test, arg]
  end

  def on_a_b_c_d_test(arg)
    [:on_abcd_test, arg]
  end
end

class FilterWithDispatcherMixinAndOn < FilterWithDispatcherMixin
  def on(*args)
    [:on_zero, *args]
  end
end

describe Temple::Mixins::Dispatcher do
  before do
    @filter = FilterWithDispatcherMixin.new
  end

  it 'should return unhandled expressions' do
    @filter.call([:unhandled]).should.equal [:unhandled]
  end

  it 'should dispatch first level' do
    @filter.call([:test, 42]).should.equal [:on_test, 42]
  end

  it 'should dispatch second level' do
    @filter.call([:second, :test, 42]).should.equal [:on_second_test, 42]
  end

  it 'should dispatch second level if prefixed' do
    @filter.call([:test, :check, 42]).should.equal [:on_check, 42]
  end

  it 'should dispatch parent level' do
    @filter.call([:a, 42]).should == [:a, 42]
    @filter.call([:a, :b, 42]).should == [:on_ab, 42]
    @filter.call([:a, :b, :test, 42]).should == [:on_ab_test, 42]
    @filter.call([:a, :b, :c, 42]).should == [:on_ab, :c, 42]
    @filter.call([:a, :b, :c, :d, 42]).should == [:on_ab, :c, :d, 42]
    @filter.call([:a, :b, :c, :d, :test, 42]).should == [:on_abcd_test, 42]
  end

  it 'should dispatch zero level' do
    FilterWithDispatcherMixinAndOn.new.call([:foo,42]).should == [:on_zero, :foo, 42]
  end
end

Version data entries

56 entries across 56 versions & 6 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/mixins/test_dispatcher.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/mixins/test_dispatcher.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/mixins/test_dispatcher.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/temple-0.8.2/test/mixins/test_dispatcher.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/temple-0.8.2/test/mixins/test_dispatcher.rb
temple-0.9.0 test/mixins/test_dispatcher.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/temple-0.8.0/test/mixins/test_dispatcher.rb
temple-0.8.2 test/mixins/test_dispatcher.rb
temple-0.8.1 test/mixins/test_dispatcher.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/mixins/test_dispatcher.rb