Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding in work method.

  • Loading branch information...
commit 62f41fee76f2afa5ebc46b6c22940862a57ac40f 1 parent 5409c41
@steveklabnik authored
View
1  Gemfile
@@ -7,4 +7,5 @@ group :test do
gem "rspec", "~>2.1.0"
gem "autotest"
gem "timecop"
+ gem "chronic"
end
View
2  Gemfile.lock
@@ -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
10 lib/pomodoro.rb
@@ -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
16 spec/pomodoro_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.