Sha256: 3c96a6ed3a02a2e9c595abc831b25504123b62110a765b943b9ed64b7dd5d432

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

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


require_relative 'helpers'


class TestBlockUtil < Test::Unit::TestCase

  include Xot::BlockUtil::ClassMethods

  class Temp

    attr_accessor :value

  end# Temp

  def temp (*args)
    Temp.new
  end

  def test_instance_eval_or_block_call ()
    t = temp
    t.value = 1

    assert_equal 2, instance_eval_or_block_call(t) {|x| x.value = 2}
    assert_equal 2, t.value

    assert_equal 3, instance_eval_or_block_call(t) {|x| t.value = 3}
    assert_equal 3, t.value

    assert_equal 4, instance_eval_or_block_call(t) {self.value = 4}
    assert_equal 4, t.value

    assert_equal 5, instance_eval_or_block_call(t) {t.value = 5}
    assert_equal 5, t.value

    assert_raise NoMethodError do
      instance_eval_or_block_call(t) {|x| self.value = 9}
    end
  end

end# TestBlockUtil

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xot-0.1.4 test/test_blockutil.rb