Permalink
Browse files

Adding in work method.

  • Loading branch information...
1 parent 5409c41 commit 62f41fee76f2afa5ebc46b6c22940862a57ac40f @steveklabnik committed Nov 28, 2010
Showing with 29 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +10 −0 lib/pomodoro.rb
  4. +16 −0 spec/pomodoro_spec.rb
View
@@ -7,4 +7,5 @@ group :test do
gem "rspec", "~>2.1.0"
gem "autotest"
gem "timecop"
+ gem "chronic"
end
View
@@ -10,6 +10,7 @@ GEM
remote: http://rubygems.org/
specs:
autotest (4.4.5)
+ chronic (0.3.0)
daemons (1.1.0)
diff-lcs (1.1.2)
eventmachine (0.12.10)
@@ -38,6 +39,7 @@ PLATFORMS
DEPENDENCIES
autotest
+ chronic
noprocrast
pomodoro!
rspec (~> 2.1.0)
View
@@ -12,6 +12,16 @@ def start!
def stop!
Noprocrast.deactivate!
end
+
+ def work interval=5
+ loop do
+ if Time.now - @start_time >= 1500 # 25 minutes * 60 seconds
+ stop!
+ end
+ break if interval == 0
+ sleep interval * 60
+ end
+ end
end
end
View
@@ -2,6 +2,7 @@
require 'noprocrast'
require './lib/pomodoro'
require 'timecop'
+require 'chronic'
describe Pomodoro do
@@ -39,6 +40,21 @@ def Noprocrast.deactivate!
describe "#work" do
+ it "doesn't call #stop for the first 24 minutes" do
+ Pomodoro.start!
+ Pomodoro.should_not_receive(:stop!)
+ Timecop.travel(Chronic.parse('24 minutes from now'))
+ Pomodoro.work(0)
+ Timecop.return
+ end
+
+ it "calls #stop! after 25 minutes" do
+ Pomodoro.start!
+ Pomodoro.should_receive(:stop!)
+ Timecop.travel(Chronic.parse('26 minutes from now'))
+ Pomodoro.work(0)
+ Timecop.return
+ end
end
end

0 comments on commit 62f41fe

Please sign in to comment.