Sha256: 061fce032067b3577d3d1c28472160540a5448e0f1a292062e4487a09d5e558e

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

require_relative 'helper'


class TestHookable < Test::Unit::TestCase

  class Temp

    include Xot::Hookable

    attr_reader :log

    def initialize()
      @log = []
    end

    def test(val1, val2)
      @log << val1 << val2
    end

    def zero()
      @log << 0
    end

  end# Temp

  def temp(*args)
    Temp.new
  end

  def test_hook()
    o = temp
    o.hook(:test) do |*args|
      super(-1, 0)
      o.log << args
      super(*args)
      super 8, 9
    end
    o.test 1, 2
    assert_equal [-1, 0, [1, 2], 1, 2, 8, 9], o.log
  end

  def test_before()
    o = temp
    o.before(:zero) {o.log << 1}
    o.zero
    assert_equal [1, 0], o.log
  end

  def test_after()
    o = temp
    o.after(:zero) {o.log << 1}
    o.zero
    assert_equal [0, 1], o.log
  end

  def test_on()
    o = temp
    o.on(:zero) {o.log << 1}
    o.zero
    assert_equal [1], o.log
  end

  def test_hook_self()
    o, id = temp, nil
    o.hook(:zero) {id = __id__}
    o.zero
    assert_equal o.__id__, id
  end

end# TestHookable

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xot-0.3 test/test_hookable.rb
xot-0.2.1 test/test_hookable.rb
xot-0.2 test/test_hookable.rb
xot-0.1.42 test/test_hookable.rb
xot-0.1.41 test/test_hookable.rb
xot-0.1.40 test/test_hookable.rb
xot-0.1.39 test/test_hookable.rb
xot-0.1.38 test/test_hookable.rb
xot-0.1.37 test/test_hookable.rb
xot-0.1.36 test/test_hookable.rb
xot-0.1.35 test/test_hookable.rb