Browse files

Rubinius doesn't know Thread.kill, use #kill instead. [bug]

  • Loading branch information...
1 parent fc61923 commit f833f455412a2efe1bfb95c48f1d380cf7c78cef @trans trans committed Dec 27, 2011
Showing with 27 additions and 12 deletions.
  1. +2 −0 .gitignore
  2. +3 −2 lib/standard/facets/timer.rb
  3. +22 −10 test/standard/test_timer.rb
View
2 .gitignore
@@ -1,3 +1,4 @@
+.rbx
.rdoc
.reap/digest
.yardoc
@@ -8,3 +9,4 @@ tmp
web
work/sandbox
work/trash
+Gemfile.lock
View
5 lib/standard/facets/timer.rb
@@ -116,7 +116,8 @@ def limit( time_limit=nil )
# Kill time limit thread, if any.
def defuse
if @timer_thread
- Thread.kill @timer_thread
+ #Thread.kill @timer_thread
+ @timer_thread.kill
@timer_thread = nil
end
end
@@ -204,4 +205,4 @@ def stop
end #class Timer
-# Copyright (c) 2004 Thomas Sawyer (Ruby License)
+# Copyright (c) 2004 Rubyworks
View
32 test/standard/test_timer.rb
@@ -3,20 +3,32 @@
test_case Timer do
class_method :time do
- test do
- Timer.time { |timer|
+ test "can keep time of a block" do
+ Timer.time do |timer|
timer.total_time.round.assert == 0
sleep 1
timer.total_time.round.assert == 1
+ end
+ end
+
+ test "can be stopped" do
+ Timer.time do |timer|
+ sleep 0.4
timer.stop
- timer.total_time.round.assert == 1
- sleep 1
- timer.total_time.round.assert == 1
+ sleep 0.6
+ timer.total_time.round.assert == 0
+ end
+ end
+
+ test "timer can be started again" do
+ Timer.time do |timer|
+ timer.stop
+ sleep 0.5
+ timer.total_time.round.assert == 0
timer.start
- timer.total_time.round.assert == 1
sleep 1
- timer.total_time.round.assert == 2
- }
+ timer.total_time.round.assert == 1
+ end
end
end
@@ -31,7 +43,7 @@
end
test "in time" do
- t = Timer.new(1)
+ t = Timer.new(2)
t.start
sleep 0.5
t.stop
@@ -40,7 +52,7 @@
method :stop do
test "in time" do
- t = Timer.new(1)
+ t = Timer.new(2)
t.start
sleep 0.5
t.stop

0 comments on commit f833f45

Please sign in to comment.