paradeiser 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Guardfile +16 -11
  4. data/README.md +1 -1
  5. data/Rakefile +1 -1
  6. data/TODO.md +12 -1
  7. data/bin/par +5 -2
  8. data/lib/paradeiser.rb +22 -2
  9. data/lib/paradeiser/controllers/controller.rb +1 -0
  10. data/lib/paradeiser/controllers/paradeiser_controller.rb +0 -1
  11. data/lib/paradeiser/models/hook.rb +4 -0
  12. data/lib/paradeiser/models/repository.rb +1 -1
  13. data/lib/paradeiser/models/scheduled.rb +4 -0
  14. data/lib/paradeiser/version.rb +1 -1
  15. data/paradeiser.gemspec +1 -6
  16. data/templates/linux/hooks/after-finish-break +2 -0
  17. data/templates/linux/hooks/after-finish-pomodoro +2 -0
  18. data/templates/linux/hooks/after-start-break +2 -0
  19. data/templates/linux/hooks/after-start-pomodoro +2 -0
  20. data/templates/mac/hooks/after-finish-break +2 -0
  21. data/templates/mac/hooks/after-finish-pomodoro +2 -0
  22. data/templates/mac/hooks/after-start-break +2 -0
  23. data/templates/mac/hooks/after-start-pomodoro +2 -0
  24. data/test/helper.rb +14 -36
  25. data/test/integration/test_annotate.rb +15 -13
  26. data/test/integration/test_finish.rb +7 -5
  27. data/test/integration/test_interrupt.rb +7 -5
  28. data/test/integration/test_log.rb +9 -7
  29. data/test/integration/test_no_args.rb +5 -3
  30. data/test/integration/test_start.rb +5 -3
  31. data/test/integration/test_status.rb +8 -6
  32. data/test/integration/test_unknown.rb +5 -3
  33. data/test/lib/controller_test.rb +4 -2
  34. data/test/lib/integration_test.rb +8 -2
  35. data/test/lib/paradeiser_controller_test.rb +7 -1
  36. data/test/lib/token_file_registry.rb +19 -0
  37. data/test/lib/unit_test.rb +47 -0
  38. data/test/lib/view_test.rb +13 -8
  39. data/test/scripts/create-failing-hooks +17 -0
  40. data/test/scripts/fail +5 -0
  41. data/test/unit/test_break.rb +43 -40
  42. data/test/unit/test_break_view.rb +17 -14
  43. data/test/unit/test_breaks_controller.rb +55 -52
  44. data/test/unit/test_interrupt.rb +27 -24
  45. data/test/unit/test_paradeiser_controller_export.rb +103 -100
  46. data/test/unit/test_paradeiser_controller_init.rb +2 -2
  47. data/test/unit/test_paradeiser_controller_report.rb +72 -69
  48. data/test/unit/test_paradeiser_controller_status.rb +78 -75
  49. data/test/unit/test_paradeiser_view_init.rb +5 -3
  50. data/test/unit/test_paradeiser_view_report.rb +116 -114
  51. data/test/unit/test_paradeiser_view_status.rb +14 -11
  52. data/test/unit/test_pomodori_controller.rb +319 -316
  53. data/test/unit/test_pomodori_view.rb +40 -37
  54. data/test/unit/test_pomodoro.rb +116 -113
  55. data/test/unit/test_pomodoro_hooks.rb +172 -170
  56. data/test/unit/test_repository.rb +98 -95
  57. data/test/unit/test_scheduler.rb +39 -30
  58. data/test/unit/test_token_file_registry.rb +40 -0
  59. metadata +59 -49
@@ -1,36 +1,39 @@
1
1
  require 'helper'
2
2
 
3
- class TestInterrupt < MiniTest::Test
4
- def setup
5
- @now = srand
6
- end
3
+ module ParadeiserTest
4
+ class TestInterrupt < UnitTest
5
+ def setup
6
+ super
7
+ @now = srand
8
+ end
7
9
 
8
- def test_created_at
9
- int = new_interrupt
10
- assert_equal(@now, int.created_at.to_i)
11
- end
10
+ def test_created_at
11
+ int = new_interrupt
12
+ assert_equal(@now, int.created_at.to_i)
13
+ end
12
14
 
13
- def test_defaults_to_internal
14
- int = new_interrupt
15
- assert_equal(:internal, int.type)
16
- end
15
+ def test_defaults_to_internal
16
+ int = new_interrupt
17
+ assert_equal(:internal, int.type)
18
+ end
17
19
 
18
- def test_external
19
- int = new_interrupt(:external)
20
- assert_equal(:external, int.type)
21
- end
20
+ def test_external
21
+ int = new_interrupt(:external)
22
+ assert_equal(:external, int.type)
23
+ end
22
24
 
23
- def test_unknown
24
- assert_raises InvalidTypeError do
25
- new_interrupt(:unknown)
25
+ def test_unknown
26
+ assert_raises InvalidTypeError do
27
+ new_interrupt(:unknown)
28
+ end
26
29
  end
27
- end
28
30
 
29
- private
31
+ private
30
32
 
31
- def new_interrupt(type = nil)
32
- Time.stub :now, Time.at(@now) do
33
- Paradeiser::Interrupt.new(type)
33
+ def new_interrupt(type = nil)
34
+ Time.stub :now, Time.at(@now) do
35
+ Paradeiser::Interrupt.new(type)
36
+ end
34
37
  end
35
38
  end
36
39
  end
@@ -3,105 +3,108 @@ require 'helper'
3
3
  #
4
4
  # There is no view for export, so we need to test the entire results here
5
5
  #
6
- class TestParadeiserControllerExport < ParadeiserControllerTest
7
- def setup
8
- @backend = PStoreMock.new
9
- end
10
-
11
- def test_empty
12
- attrs = invoke(:export)
13
- assert_empty(attrs[:stderr])
14
-
15
- result = JSON.parse(attrs[:stdout])
16
- assert(result)
17
- assert_empty(result)
18
- end
19
-
20
- def test_pomodoro
21
- pom = produce(Pomodoro)
22
- started_at = Time.new(8)
23
- pom.started_at = started_at
24
- pom.finish!
25
- finished_at = Time.new(16)
26
- pom.finished_at = finished_at
27
- @backend[:bar] = pom
28
-
29
- attrs = invoke(:export)
30
- assert_empty(attrs[:stderr])
31
- result = JSON.parse(attrs[:stdout])
32
-
33
- assert(result)
34
- refute_empty(result)
35
- assert_equal(1, result.size)
36
- p = result.first
37
- assert(p)
38
-
39
- assert_equal('Pomodoro', p['type'])
40
- assert_equal(1500, p['length'])
41
- assert_equal('finished', p['status'])
42
- assert_equal(started_at.as_json, p['started_at'])
43
- assert_equal(finished_at.as_json, p['finished_at'])
44
-
45
- interrupts = p['interrupts']
46
- assert(interrupts)
47
- assert_empty(interrupts)
48
-
49
- annotations = p['annotations']
50
- assert(annotations)
51
- assert_empty(annotations)
52
- end
53
-
54
- def test_break
55
- br3ak = produce(Break)
56
- started_at = Time.new(8)
57
- br3ak.started_at = started_at
58
- br3ak.finish!
59
- finished_at = Time.new(16)
60
- br3ak.finished_at = finished_at
61
- @backend[:bar] = br3ak
62
-
63
- attrs = invoke(:export)
64
- assert_empty(attrs[:stderr])
65
- result = JSON.parse(attrs[:stdout])
66
-
67
- assert(result)
68
- refute_empty(result)
69
- assert_equal(1, result.size)
70
- p = result.first
71
- assert(p)
72
-
73
- assert_equal('Break', p['type'])
74
- assert_equal(300, p['length'])
75
- assert_equal('finished', p['status'])
76
- assert_equal(started_at.as_json, p['started_at'])
77
- assert_equal(finished_at.as_json, p['finished_at'])
78
-
79
- refute(p['interrupts'])
80
- refute(p['annotations'])
81
- end
82
-
83
- def test_multiple
84
- br3ak = produce(Break)
85
- br3ak.started_at = Time.new(8)
86
- br3ak.finish!
87
- br3ak.finished_at = Time.new(16)
88
- @backend[:bar] = br3ak
89
-
90
- pom = produce(Pomodoro)
91
- pom.started_at = Time.new(8)
92
- pom.finish!
93
- pom.finished_at = Time.new(16)
94
- @backend[:foo] = pom
95
-
96
- attrs = invoke(:export)
97
- assert_empty(attrs[:stderr])
98
- result = JSON.parse(attrs[:stdout])
99
-
100
- assert(result)
101
- refute_empty(result)
102
- assert_equal(2, result.size)
103
-
104
- assert_equal('Break', result.first['type'])
105
- assert_equal('Pomodoro', result.last['type'])
6
+ module ParadeiserTest
7
+ class TestParadeiserControllerExport < ParadeiserControllerTest
8
+ def setup
9
+ super
10
+ @backend = PStoreMock.new
11
+ end
12
+
13
+ def test_empty
14
+ attrs = invoke(:export)
15
+ assert_empty(attrs[:stderr])
16
+
17
+ result = JSON.parse(attrs[:stdout])
18
+ assert(result)
19
+ assert_empty(result)
20
+ end
21
+
22
+ def test_pomodoro
23
+ pom = produce(Pomodoro)
24
+ started_at = Time.new(8)
25
+ pom.started_at = started_at
26
+ pom.finish!
27
+ finished_at = Time.new(16)
28
+ pom.finished_at = finished_at
29
+ @backend[:bar] = pom
30
+
31
+ attrs = invoke(:export)
32
+ assert_empty(attrs[:stderr])
33
+ result = JSON.parse(attrs[:stdout])
34
+
35
+ assert(result)
36
+ refute_empty(result)
37
+ assert_equal(1, result.size)
38
+ p = result.first
39
+ assert(p)
40
+
41
+ assert_equal('Pomodoro', p['type'])
42
+ assert_equal(1500, p['length'])
43
+ assert_equal('finished', p['status'])
44
+ assert_equal(started_at.as_json, p['started_at'])
45
+ assert_equal(finished_at.as_json, p['finished_at'])
46
+
47
+ interrupts = p['interrupts']
48
+ assert(interrupts)
49
+ assert_empty(interrupts)
50
+
51
+ annotations = p['annotations']
52
+ assert(annotations)
53
+ assert_empty(annotations)
54
+ end
55
+
56
+ def test_break
57
+ br3ak = produce(Break)
58
+ started_at = Time.new(8)
59
+ br3ak.started_at = started_at
60
+ br3ak.finish!
61
+ finished_at = Time.new(16)
62
+ br3ak.finished_at = finished_at
63
+ @backend[:bar] = br3ak
64
+
65
+ attrs = invoke(:export)
66
+ assert_empty(attrs[:stderr])
67
+ result = JSON.parse(attrs[:stdout])
68
+
69
+ assert(result)
70
+ refute_empty(result)
71
+ assert_equal(1, result.size)
72
+ p = result.first
73
+ assert(p)
74
+
75
+ assert_equal('Break', p['type'])
76
+ assert_equal(300, p['length'])
77
+ assert_equal('finished', p['status'])
78
+ assert_equal(started_at.as_json, p['started_at'])
79
+ assert_equal(finished_at.as_json, p['finished_at'])
80
+
81
+ refute(p['interrupts'])
82
+ refute(p['annotations'])
83
+ end
84
+
85
+ def test_multiple
86
+ br3ak = produce(Break)
87
+ br3ak.started_at = Time.new(8)
88
+ br3ak.finish!
89
+ br3ak.finished_at = Time.new(16)
90
+ @backend[:bar] = br3ak
91
+
92
+ pom = produce(Pomodoro)
93
+ pom.started_at = Time.new(8)
94
+ pom.finish!
95
+ pom.finished_at = Time.new(16)
96
+ @backend[:foo] = pom
97
+
98
+ attrs = invoke(:export)
99
+ assert_empty(attrs[:stderr])
100
+ result = JSON.parse(attrs[:stdout])
101
+
102
+ assert(result)
103
+ refute_empty(result)
104
+ assert_equal(2, result.size)
105
+
106
+ assert_equal('Break', result.first['type'])
107
+ assert_equal('Pomodoro', result.last['type'])
108
+ end
106
109
  end
107
110
  end
@@ -26,7 +26,7 @@ class TestParadeiserControllerInit < MiniTest::Test
26
26
  end
27
27
 
28
28
  def test_init_existing
29
- FileUtils.mkdir_p(Paradeiser.par_dir, 0700)
29
+ FileUtils.mkdir_p(Paradeiser.par_dir, mode: 0700)
30
30
  assert(Dir.exists?(Paradeiser.par_dir))
31
31
 
32
32
  invoke(:init)
@@ -50,7 +50,7 @@ class TestParadeiserControllerInit < MiniTest::Test
50
50
  def test_init_existing_with_env_override
51
51
  ENV.delete('PAR_DIR')
52
52
 
53
- Dir.mktmpdir do |dir|
53
+ Dir.mktmpdir(name) do |dir|
54
54
  refute_equal(dir, Paradeiser.par_dir)
55
55
  ENV['PAR_DIR'] = dir
56
56
  assert_equal(dir, Paradeiser.par_dir)
@@ -1,91 +1,94 @@
1
1
  require 'helper'
2
2
 
3
- class TestParadeiserControllerReport < ParadeiserControllerTest
4
- ATTR_NAMES = %w{has_output @finished @canceled @external_interrupts @internal_interrupts @breaks @break_minutes}
3
+ module ParadeiserTest
4
+ class TestParadeiserControllerReportTest < ParadeiserControllerTest
5
+ ATTR_NAMES = %w{has_output @finished @canceled @external_interrupts @internal_interrupts @breaks @break_minutes}
5
6
 
6
- def setup
7
- @backend = PStoreMock.new
8
- end
7
+ def setup
8
+ super
9
+ @backend = PStoreMock.new
10
+ end
9
11
 
10
- def test_idle
11
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
12
- assert_equal(0, attrs[:finished])
13
- end
12
+ def test_idle
13
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
14
+ assert_equal(0, attrs[:finished])
15
+ end
14
16
 
15
- def test_has_output
16
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
17
- assert_equal(true, attrs[:has_output])
18
- end
17
+ def test_has_output
18
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
19
+ assert_equal(true, attrs[:has_output])
20
+ end
19
21
 
20
- def test_finished
21
- pom = produce(Pomodoro) # can't use mocks as long as the controller uses kind_of?
22
- pom.started_at = Time.new(8)
23
- pom.finished_at = Time.new(16)
24
- pom.finish!
25
- @backend[:bar] = pom
22
+ def test_finished
23
+ pom = produce(Pomodoro) # can't use mocks as long as the controller uses kind_of?
24
+ pom.started_at = Time.new(8)
25
+ pom.finished_at = Time.new(16)
26
+ pom.finish!
27
+ @backend[:bar] = pom
26
28
 
27
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
28
- assert_equal(1, attrs[:finished])
29
- end
29
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
30
+ assert_equal(1, attrs[:finished])
31
+ end
30
32
 
31
- def test_canceled
32
- pom = produce(Pomodoro)
33
- pom.started_at = Time.new(16)
34
- pom.canceled_at = Time.new(24)
35
- pom.cancel!
36
- @backend[:bar] = pom
33
+ def test_canceled
34
+ pom = produce(Pomodoro)
35
+ pom.started_at = Time.new(16)
36
+ pom.canceled_at = Time.new(24)
37
+ pom.cancel!
38
+ @backend[:bar] = pom
37
39
 
38
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
39
- assert_equal(1, attrs[:canceled])
40
- end
40
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
41
+ assert_equal(1, attrs[:canceled])
42
+ end
41
43
 
42
- def test_external_interrupts
43
- pom = produce(Pomodoro)
44
- pom.started_at = Time.new(24)
45
- pom.canceled_at = Time.new(32)
46
- pom.interrupt!(:external)
47
- @backend[:bar] = pom
44
+ def test_external_interrupts
45
+ pom = produce(Pomodoro)
46
+ pom.started_at = Time.new(24)
47
+ pom.canceled_at = Time.new(32)
48
+ pom.interrupt!(:external)
49
+ @backend[:bar] = pom
48
50
 
49
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
50
- assert_equal(1, attrs[:external_interrupts])
51
- end
51
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
52
+ assert_equal(1, attrs[:external_interrupts])
53
+ end
52
54
 
53
- def test_internal_interrupts
54
- pom = produce(Pomodoro)
55
- pom.started_at = Time.new(32)
56
- pom.canceled_at = Time.new(64)
57
- pom.interrupt!(:internal)
58
- @backend[:bar] = pom
55
+ def test_internal_interrupts
56
+ pom = produce(Pomodoro)
57
+ pom.started_at = Time.new(32)
58
+ pom.canceled_at = Time.new(64)
59
+ pom.interrupt!(:internal)
60
+ @backend[:bar] = pom
59
61
 
60
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
61
- assert_equal(1, attrs[:internal_interrupts])
62
- end
62
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
63
+ assert_equal(1, attrs[:internal_interrupts])
64
+ end
63
65
 
64
- def test_breaks
65
- br3ak = produce(Break)
66
- br3ak.started_at = Time.new(164)
67
- br3ak.finished_at = Time.new(128)
68
- @backend[:foo] = br3ak
66
+ def test_breaks
67
+ br3ak = produce(Break)
68
+ br3ak.started_at = Time.new(164)
69
+ br3ak.finished_at = Time.new(128)
70
+ @backend[:foo] = br3ak
69
71
 
70
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
71
- assert_equal(1, attrs[:breaks])
72
- end
72
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
73
+ assert_equal(1, attrs[:breaks])
74
+ end
73
75
 
74
- def test_break_minutes
75
- @backend[:foo] = make_break(5)
76
- @backend[:bar] = make_break(3)
77
- @backend[:baz] = make_break(2)
76
+ def test_break_minutes
77
+ @backend[:foo] = make_break(5)
78
+ @backend[:bar] = make_break(3)
79
+ @backend[:baz] = make_break(2)
78
80
 
79
- attrs = invoke(:report, nil, nil, *ATTR_NAMES)
80
- assert_equal(10, attrs[:break_minutes])
81
- end
81
+ attrs = invoke(:report, nil, nil, *ATTR_NAMES)
82
+ assert_equal(10, attrs[:break_minutes])
83
+ end
82
84
 
83
- private
85
+ private
84
86
 
85
- def make_break(minutes = 5)
86
- Break.new.tap do |b|
87
- b.started_at = srand
88
- b.finished_at = b.started_at + minutes * 60
87
+ def make_break(minutes = 5)
88
+ Break.new.tap do |b|
89
+ b.started_at = srand
90
+ b.finished_at = b.started_at + minutes * 60
91
+ end
89
92
  end
90
93
  end
91
94
  end