Sha256: 6b2e40b05f5d0ab5b8fe00e6ad8552033800616ab0924664d5b1db8ad609ec82

Contents?: true

Size: 773 Bytes

Versions: 11

Compression:

Stored size: 773 Bytes

Contents

require_relative 'helper'


class TestBlockUtil < Test::Unit::TestCase

  include Xot::BlockUtil

  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

11 entries across 11 versions & 1 rubygems

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