#!/usr/bin/env ruby require 'test/unit' require 'pathname' require File.join( File.dirname(__FILE__), '../../lib/masterview/mtime_tracking_hash' ) class TestMTimeTrackingHash < Test::Unit::TestCase def setup @h = MasterView::MTimeTrackingHash.new @h[1] = 'one' @h[2] = :two @h[:foo] = :bar @h['cat'] = :dog end def test_hash assert_equal 'one', @h[1] assert_equal :two, @h[2] assert_equal :bar, @h[:foo] assert_equal :dog, @h['cat'] assert_nil @h.mtime(:not_found) assert_kind_of Time, @h.mtime(1) end def test_hash_changed m1 = @h.mtime(1) m2 = @h.mtime(2) assert_equal m1, @h.mtime(1) sleep 1 # make sure noticeable time passes @h[2] = 'two updated' assert_not_equal m2, @h.mtime(2) assert_equal m1, @h.mtime(1) assert_kind_of Time, @h.mtime(2) assert(@h.mtime(2) > m2) end end