domodoro 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module Domodoro
9
9
  visual: true
10
10
  sound: false
11
11
  """
12
- Domodoro::Config.load
12
+ Domodoro::Config.load_client_configuration
13
13
 
14
14
  assert_equal true, Domodoro::Config.visual
15
15
  assert_equal false, Domodoro::Config.sound
@@ -20,7 +20,7 @@ module Domodoro
20
20
  it 'sets both options to true' do
21
21
  File.stubs(:exist?).returns false
22
22
 
23
- Domodoro::Config.load
23
+ Domodoro::Config.load_client_configuration
24
24
 
25
25
  assert_equal true, Domodoro::Config.visual
26
26
  assert_equal true, Domodoro::Config.sound
@@ -0,0 +1,108 @@
1
+ require 'test_helper'
2
+ require 'ostruct'
3
+ require 'pp'
4
+
5
+ module Domodoro
6
+ describe Schedule do
7
+ before do
8
+ File.stubs(:exist?).returns false
9
+ @schedule = Schedule.new
10
+ @schedule.generate!
11
+ @times = @schedule.to_hash
12
+ end
13
+
14
+ describe "before lunch" do
15
+ it 'generates start times correctly' do
16
+ %w(08:30 09:00 09:30 10:00 10:35 11:05 11:35 12:05 12:35).each do |time|
17
+ assert_equal :start, @times[time]
18
+ end
19
+ end
20
+
21
+ it 'generates stop times correctly' do
22
+ %w(08:55 09:25 09:55 10:25 11:00 11:30 12:00 12:30).each do |time|
23
+ assert_equal :stop, @times[time]
24
+ end
25
+ assert_equal :lunch, @times["13:00"]
26
+ end
27
+ end
28
+
29
+ describe 'after lunch' do
30
+ it 'generates start times correctly' do
31
+ %w(13:30 14:00 14:30 15:00 15:35 16:05).each do |time|
32
+ assert_equal :start, @times[time]
33
+ end
34
+ end
35
+
36
+ it 'generates stop times correctly' do
37
+ %w(13:55 14:25 14:55 15:25 16:00).each do |time|
38
+ assert_equal :stop, @times[time]
39
+ end
40
+ assert_equal :go_home, @times["16:30"]
41
+ end
42
+ end
43
+
44
+ describe 'uneven, weird schedules' do
45
+ before do
46
+ config = OpenStruct.new
47
+ config.pomodoro_duration = 25
48
+ config.pomodoro_break = 5
49
+ config.long_break_after = 4
50
+ config.day_start = Timepoint.new('9:13')
51
+ config.lunch_time = Timepoint.new('12:49')
52
+ config.lunch_duration = 120
53
+ config.day_end = Timepoint.new('15:00')
54
+
55
+ Config.expects(:get_server_configuration).returns config
56
+
57
+ @schedule = Schedule.new
58
+ @schedule.generate!
59
+ @times = @schedule.to_hash
60
+ end
61
+
62
+ it 'respect lunch' do
63
+ assert_equal :lunch, @times["12:49"]
64
+ assert_equal :start, @times["14:49"]
65
+ end
66
+
67
+ it 'respect home' do
68
+ assert_equal :go_home, @times["15:00"]
69
+ end
70
+ end
71
+
72
+ describe '#action_after' do
73
+ it 'returns the next action after a given timestamp' do
74
+ times = {
75
+ "08:30" => :start,
76
+ "09:15" => :stop,
77
+ "10:15" => :start,
78
+ }
79
+
80
+ @schedule = Schedule.new
81
+ @schedule.instance_variable_set(:@times, times)
82
+
83
+ @schedule.action_after("08:30").must_equal ['09:15', :stop]
84
+ @schedule.action_after("08:45").must_equal ['09:15', :stop]
85
+ @schedule.action_after("09:31").must_equal ['10:15', :start]
86
+ end
87
+ end
88
+
89
+ describe '#current_action' do
90
+ it 'returns the current or past action on a given timestamp' do
91
+ times = {
92
+ "08:30" => :start,
93
+ "09:15" => :stop,
94
+ "10:15" => :start,
95
+ }
96
+
97
+ @schedule = Schedule.new
98
+ @schedule.instance_variable_set(:@times, times)
99
+
100
+ @schedule.current_action("08:30").must_equal ['08:30', :start]
101
+ @schedule.current_action("08:31").must_equal ['08:30', :start]
102
+ @schedule.current_action("09:18").must_equal ['09:15', :stop]
103
+ @schedule.current_action("12:18").must_equal ['10:15', :start]
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -5,19 +5,16 @@ module Domodoro
5
5
  include EM::MiniTest::Spec
6
6
 
7
7
  before do
8
+ File.stubs(:exist?).returns(false)
8
9
  @channel = Channel.new
9
- end
10
-
11
- it 'initializes with a channel' do
12
- server = Domodoro::Server.new(nil, @channel)
13
- assert_equal @channel, server.channel
10
+ @schedule = Schedule.new
11
+ @schedule.generate!
14
12
  end
15
13
 
16
14
  it 'repeats every message broadcasted to the channel' do
17
- server = Server.new(nil, @channel)
18
- EM.start_server('127.0.0.1', 8888, Server, :app => server)
15
+ EM.start_server('127.0.0.1', 8888, Server, @channel, @schedule)
19
16
 
20
- server.expects(:send_data).with(":start\n")
17
+ Server.any_instance.expects(:send_data).with(":start\n")
21
18
 
22
19
  @channel << :start
23
20
  end
@@ -25,7 +22,8 @@ module Domodoro
25
22
  describe '.start' do
26
23
  it 'opens a server with a new channel' do
27
24
  Channel.expects(:new).returns @channel
28
- EM.expects(:start_server).with('0.0.0.0', '8888', Server, @channel)
25
+ Schedule.expects(:new).returns @schedule
26
+ EM.expects(:start_server).with('0.0.0.0', '8888', Server, @channel, @schedule)
29
27
 
30
28
  Server.start('0.0.0.0', '8888')
31
29
  end
@@ -61,5 +59,37 @@ module Domodoro
61
59
  end
62
60
  end
63
61
 
62
+ describe 'on connection' do
63
+ it 'sends the current and next actions to the client', :timeout => 0.3 do
64
+ Server.stubs(:timestamp).returns "13:15"
65
+
66
+ EM.start_server('127.0.0.1', 8888, Server, @channel, @schedule)
67
+
68
+ FakeSocketClient = Class.new(EM::Connection) do
69
+ include EM::P::ObjectProtocol
70
+ @object = nil
71
+ def self.object=(obj)
72
+ @object = obj
73
+ end
74
+ def receive_object(object)
75
+ self.class.object = object
76
+ end
77
+ end
78
+
79
+ EM.connect('127.0.0.1', 8888, FakeSocketClient)
80
+
81
+ EM.add_timer(0.25) do
82
+ object = FakeSocketClient.class_eval "@object"
83
+
84
+ assert_equal ["13:00", :lunch], object[:current_action]
85
+ assert_equal ["13:30", :start], object[:next_action]
86
+
87
+ done!
88
+ end
89
+
90
+ wait!
91
+ end
92
+ end
93
+
64
94
  end
65
95
  end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ module Domodoro
4
+ describe Timepoint do
5
+ before do
6
+ @timepoint = Timepoint.new("08:30")
7
+ end
8
+
9
+ it 'initializes with an hour/minute timestamp' do
10
+ assert_equal 8, @timepoint.hour
11
+ assert_equal 30, @timepoint.min
12
+ end
13
+
14
+ it 'initializes with hours and minutes as fixnums' do
15
+ timepoint = Timepoint.new(8, 30)
16
+ assert_equal 8, timepoint.hour
17
+ assert_equal 30, timepoint.min
18
+ end
19
+
20
+ describe '#to_s' do
21
+ it 'returns the original timestamp' do
22
+ assert_equal "08:30", @timepoint.to_s
23
+ end
24
+ end
25
+
26
+ describe '+' do
27
+ describe 'when the added minutes belong to the next hour' do
28
+ it 'adds time appropriately returning a new timepoint' do
29
+ new_timepoint = @timepoint + 45
30
+
31
+ assert_equal 9, new_timepoint.hour
32
+ assert_equal 15, new_timepoint.min
33
+ end
34
+ end
35
+
36
+ describe 'within the same hour' do
37
+ it 'works the same way' do
38
+ new_timepoint = @timepoint + 15
39
+
40
+ assert_equal 8, new_timepoint.hour
41
+ assert_equal 45, new_timepoint.min
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#after?' do
47
+ before do
48
+ @timepoint = Timepoint.new(8, 30)
49
+ end
50
+ it 'tells if the timepoint is after another timepoint' do
51
+ Timepoint.new(8, 45).after?(@timepoint).must_equal true
52
+ Timepoint.new(9, 15).after?(@timepoint).must_equal true
53
+ Timepoint.new(8, 25).after?(@timepoint).must_equal false
54
+ Timepoint.new(7, 10).after?(@timepoint).must_equal false
55
+ end
56
+ end
57
+
58
+ describe '#before?' do
59
+ before do
60
+ @timepoint = Timepoint.new(17, 30)
61
+ end
62
+ it 'tells if the timepoint is before another timepoint' do
63
+ Timepoint.new(17, 15).before?(@timepoint).must_equal true
64
+ Timepoint.new(13, 00).before?(@timepoint).must_equal true
65
+ Timepoint.new(17, 40).before?(@timepoint).must_equal false
66
+ Timepoint.new(19, 10).before?(@timepoint).must_equal false
67
+ end
68
+ end
69
+
70
+ describe '#==' do
71
+ before do
72
+ @timepoint = Timepoint.new(8, 30)
73
+ end
74
+ it 'tells if the timepoint equals another timepoint' do
75
+ Timepoint.new(8, 30).must_equal @timepoint
76
+ Timepoint.new(8, 45).wont_equal @timepoint
77
+ Timepoint.new(8, 15).wont_equal @timepoint
78
+ end
79
+
80
+ it 'tells if the timepoint equals another string' do
81
+ "08:30".must_equal @timepoint
82
+ "08:45".wont_equal @timepoint
83
+ "08:15".wont_equal @timepoint
84
+ end
85
+ end
86
+
87
+ describe '#left_until' do
88
+ it 'returns the time left until another timestamp' do
89
+ Time.stubs(:now).returns stub(:sec => 55)
90
+ @a = Timepoint.new(8, 30)
91
+ @b = Timepoint.new(9, 45)
92
+ @c = Timepoint.new(11, 10)
93
+ @d = Timepoint.new(8, 32)
94
+ @e = Timepoint.new(15, 01)
95
+ @f = Timepoint.new(8, 31)
96
+
97
+ assert_equal "01:14:04", @a.left_until(@b)
98
+ assert_equal "01:24:04", @b.left_until(@c)
99
+ assert_equal "00:01:04", @a.left_until(@d)
100
+ assert_equal "06:30:04", @a.left_until(@e)
101
+ assert_equal "00:00:04", @a.left_until(@f)
102
+ end
103
+ end
104
+ end
105
+ end
metadata CHANGED
@@ -1,139 +1,173 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: domodoro
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1322991910812937300
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Josep M. Bach
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-08-29 00:00:00.000000000 +02:00
17
+
18
+ date: 2011-08-30 00:00:00 +02:00
13
19
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: eventmachine
17
- requirement: &2155991320 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 2002549777813010636
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :runtime
24
- prerelease: false
25
- version_requirements: *2155991320
26
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
27
36
  name: notify
28
- requirement: &2155990500 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 2002549777813010636
44
+ segments:
45
+ - 0
46
+ version: "0"
34
47
  type: :runtime
35
- prerelease: false
36
- version_requirements: *2155990500
37
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
38
50
  name: minitest
39
- requirement: &2155989420 !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
40
53
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 2002549777813010636
58
+ segments:
59
+ - 0
60
+ version: "0"
45
61
  type: :development
46
- prerelease: false
47
- version_requirements: *2155989420
48
- - !ruby/object:Gem::Dependency
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
49
64
  name: mocha
50
- requirement: &2155928300 !ruby/object:Gem::Requirement
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
51
67
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 2002549777813010636
72
+ segments:
73
+ - 0
74
+ version: "0"
56
75
  type: :development
57
- prerelease: false
58
- version_requirements: *2155928300
59
- - !ruby/object:Gem::Dependency
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
60
78
  name: purdytest
61
- requirement: &2155927240 !ruby/object:Gem::Requirement
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
62
81
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 2002549777813010636
86
+ segments:
87
+ - 0
88
+ version: "0"
67
89
  type: :development
68
- prerelease: false
69
- version_requirements: *2155927240
90
+ version_requirements: *id005
70
91
  description: Distributed Pomodoro for the masses
71
- email:
92
+ email:
72
93
  - josep.m.bach@gmail.com
73
- executables:
94
+ executables:
74
95
  - domodoro
75
96
  extensions: []
97
+
76
98
  extra_rdoc_files: []
77
- files:
99
+
100
+ files:
78
101
  - .gitignore
79
102
  - .travis.yml
80
103
  - Gemfile
81
104
  - Guardfile
82
105
  - Rakefile
83
106
  - Readme.md
84
- - assets/start.wav
85
- - assets/stop.wav
107
+ - assets/break.wav
108
+ - assets/home.wav
109
+ - assets/lunch.wav
110
+ - assets/work.wav
86
111
  - bin/domodoro
87
112
  - domodoro.gemspec
88
113
  - lib/domodoro.rb
89
114
  - lib/domodoro/channel.rb
90
115
  - lib/domodoro/client.rb
91
116
  - lib/domodoro/config.rb
117
+ - lib/domodoro/schedule.rb
92
118
  - lib/domodoro/server.rb
119
+ - lib/domodoro/timepoint.rb
93
120
  - lib/domodoro/version.rb
94
121
  - test/domodoro/channel_test.rb
95
122
  - test/domodoro/client_test.rb
96
123
  - test/domodoro/config_test.rb
124
+ - test/domodoro/schedule_test.rb
97
125
  - test/domodoro/server_test.rb
126
+ - test/domodoro/timepoint_test.rb
98
127
  - test/domodoro_test.rb
99
128
  - test/support/em-minitest.rb
100
129
  - test/test_helper.rb
101
130
  has_rdoc: true
102
131
  homepage: http://github.com/txus/domodoro
103
132
  licenses: []
133
+
104
134
  post_install_message:
105
135
  rdoc_options: []
106
- require_paths:
136
+
137
+ require_paths:
107
138
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
139
+ required_ruby_version: !ruby/object:Gem::Requirement
109
140
  none: false
110
- requirements:
111
- - - ! '>='
112
- - !ruby/object:Gem::Version
113
- version: '0'
114
- segments:
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 2002549777813010636
145
+ segments:
115
146
  - 0
116
- hash: -4547981421582945209
117
- required_rubygems_version: !ruby/object:Gem::Requirement
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
149
  none: false
119
- requirements:
120
- - - ! '>='
121
- - !ruby/object:Gem::Version
122
- version: '0'
123
- segments:
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 2002549777813010636
154
+ segments:
124
155
  - 0
125
- hash: -4547981421582945209
156
+ version: "0"
126
157
  requirements: []
158
+
127
159
  rubyforge_project: domodoro
128
- rubygems_version: 1.6.2
160
+ rubygems_version: 1.5.2
129
161
  signing_key:
130
162
  specification_version: 3
131
163
  summary: Distributed Pomodoro for the masses
132
- test_files:
164
+ test_files:
133
165
  - test/domodoro/channel_test.rb
134
166
  - test/domodoro/client_test.rb
135
167
  - test/domodoro/config_test.rb
168
+ - test/domodoro/schedule_test.rb
136
169
  - test/domodoro/server_test.rb
170
+ - test/domodoro/timepoint_test.rb
137
171
  - test/domodoro_test.rb
138
172
  - test/support/em-minitest.rb
139
173
  - test/test_helper.rb