Permalink
Browse files

add test-case

  • Loading branch information...
1 parent 2e1a2b5 commit 961cac770f68ec49e9ea740f0607b1517fbf67ba @kachick committed Apr 5, 2012
Showing with 47 additions and 0 deletions.
  1. +2 −0 Manifest.txt
  2. +2 −0 test/test_helper.rb
  3. +43 −0 test/test_instancevalue.rb
View
@@ -4,4 +4,6 @@ History.rdoc
Manifest.txt
Rakefile
lib/instancevalue.rb
+test/test_helper.rb
+test/test_instancevalue.rb
example/example.rb
View
@@ -0,0 +1,2 @@
+require 'test/unit'
+require_relative '../lib/instancevalue'
@@ -0,0 +1,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

0 comments on commit 961cac7

Please sign in to comment.