Sha256: b132e800f8a087cfe7333b1d34bc43ff1a4692f79eda68febf21477dacb816f3

Contents?: true

Size: 1.03 KB

Versions: 15

Compression:

Stored size: 1.03 KB

Contents

# -*- coding: utf-8 -*-


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

15 entries across 15 versions & 1 rubygems

Version Path
xot-0.1.21 test/test_hookable.rb
xot-0.1.20 test/test_hookable.rb
xot-0.1.19 test/test_hookable.rb
xot-0.1.16 test/test_hookable.rb
xot-0.1.15 test/test_hookable.rb
xot-0.1.14 test/test_hookable.rb
xot-0.1.13 test/test_hookable.rb
xot-0.1.12 test/test_hookable.rb
xot-0.1.11 test/test_hookable.rb
xot-0.1.10 test/test_hookable.rb
xot-0.1.9 test/test_hookable.rb
xot-0.1.8 test/test_hookable.rb
xot-0.1.7 test/test_hookable.rb
xot-0.1.6 test/test_hookable.rb
xot-0.1.5 test/test_hookable.rb