Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 961cac770f
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 44 lines (33 sloc) 1.124 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
$VERBOSE = true
require_relative 'test_helper'

class TestBasicCase < Test::Unit::TestCase
  class Person
    include InstanceValue
    
    value_reader :birthday

    def initialize(birthday)
      val :birthday, birthday
    end

    def age
      (Time.now - val(:birthday)) / (60 * 60 * 24 * 365)
    end
  end
  
  def test_normaly
    person = Person.new Time.at 8888
    assert_equal Time.at(8888), person.birthday
    assert_kind_of Float, person.age
    assert_equal [:birthday], person.instance_values

    assert_raises RuntimeError do
      person.instance_eval{val :birthday, Time.now}
    end
    
    assert_equal 'Ken', person.instance_eval{val :name, 'Ken'}
    assert_equal [:birthday, :name], person.instance_values
    
    assert_equal 'Ken', person.instance_eval{val :name}
    assert_equal 'Ken', person.instance_eval{remove_instance_value :name}
    assert_equal [:birthday], person.instance_values
    
    assert_equal nil, person.instance_eval{val :name}
    assert_equal 'John', person.instance_eval{val :name, 'John'}
    
    assert_raises NoMethodError do
      person.name
    end
  end
end
Something went wrong with that request. Please try again.