paradeiser 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,41 +1,44 @@
1
1
  require 'helper'
2
2
 
3
- class TestPomodoriView < ViewTest
4
- def setup
5
- @pom = produce(Pomodoro)
6
- @pom.id = 1
7
- end
8
-
9
- def test_start
10
- assert_match(/^Started pomodoro #1\.$/m, render(:start))
11
- end
12
-
13
- def test_finish
14
- assert_match(/^Finished pomodoro #1 after .* minutes\.$/m, render(:finish))
15
- end
16
-
17
- def test_cancel
18
- cancel!
19
- assert_match(/^Canceled pomodoro #1 after .* minutes\.$/m, render(:cancel))
20
- end
21
-
22
- def test_interrupt_internal
23
- @interrupt_type = 'internally'
24
- assert_match(/^Marked pomodoro #1 as internally interrupted\.$/m, render(:interrupt))
25
- end
26
-
27
- def test_interrupt_external
28
- @interrupt_type = 'externally'
29
- assert_match(/^Marked pomodoro #1 as externally interrupted\.$/m, render(:interrupt))
30
- end
31
-
32
- def test_annotate
33
- assert_match(/^Successfully annotated pomodoro #1\.$/m, render(:annotate))
34
- end
35
-
36
- protected
37
-
38
- def model
39
- 'Pomodoro'
3
+ module ParadeiserTest
4
+ class TestPomodoriView < ViewTest
5
+ def setup
6
+ super
7
+ @pom = produce(Pomodoro)
8
+ @pom.id = 1
9
+ end
10
+
11
+ def test_start
12
+ assert_match(/^Started pomodoro #1\.$/m, render(:start))
13
+ end
14
+
15
+ def test_finish
16
+ assert_match(/^Finished pomodoro #1 after .* minutes\.$/m, render(:finish))
17
+ end
18
+
19
+ def test_cancel
20
+ cancel!
21
+ assert_match(/^Canceled pomodoro #1 after .* minutes\.$/m, render(:cancel))
22
+ end
23
+
24
+ def test_interrupt_internal
25
+ @interrupt_type = 'internally'
26
+ assert_match(/^Marked pomodoro #1 as internally interrupted\.$/m, render(:interrupt))
27
+ end
28
+
29
+ def test_interrupt_external
30
+ @interrupt_type = 'externally'
31
+ assert_match(/^Marked pomodoro #1 as externally interrupted\.$/m, render(:interrupt))
32
+ end
33
+
34
+ def test_annotate
35
+ assert_match(/^Successfully annotated pomodoro #1\.$/m, render(:annotate))
36
+ end
37
+
38
+ protected
39
+
40
+ def model
41
+ 'Pomodoro'
42
+ end
40
43
  end
41
44
  end
@@ -1,164 +1,167 @@
1
1
  require 'helper'
2
2
 
3
- class TestPomodoro < MiniTest::Test
4
- def setup
5
- @pom = produce(Pomodoro)
6
- end
7
-
8
- def test_finish_active
9
- assert_equal(:active, @pom.status_name)
3
+ module ParadeiserTest
4
+ class TestPomodoro < UnitTest
5
+ def setup
6
+ super
7
+ @pom = produce(Pomodoro)
8
+ end
10
9
 
11
- now = srand
10
+ def test_finish_active
11
+ assert_equal(:active, @pom.status_name)
12
12
 
13
- Time.stub :now, Time.at(now) do
14
- finish!
15
- end
13
+ now = srand
16
14
 
17
- assert_equal(:finished, @pom.status_name)
18
- assert_equal(now, @pom.finished_at.to_i)
19
- refute(@pom.canceled_at)
20
- end
15
+ Time.stub :now, Time.at(now) do
16
+ finish!
17
+ end
21
18
 
22
- def test_finish_finished
23
- finish!
24
- assert_raises StateMachine::InvalidTransition do
25
- finish!
19
+ assert_equal(:finished, @pom.status_name)
20
+ assert_equal(now, @pom.finished_at.to_i)
21
+ refute(@pom.canceled_at)
26
22
  end
27
- refute(@pom.canceled_at)
28
- end
29
23
 
30
- def test_finish_canceled
31
- cancel!
32
- assert_raises StateMachine::InvalidTransition do
24
+ def test_finish_finished
33
25
  finish!
26
+ assert_raises StateMachine::InvalidTransition do
27
+ finish!
28
+ end
29
+ refute(@pom.canceled_at)
34
30
  end
35
- refute(@pom.finished_at)
36
- end
37
-
38
- def test_length
39
- assert_equal(25 * 60, @pom.length)
40
- end
41
31
 
42
- def test_duration_started
43
- later = @started + rand(42)
32
+ def test_finish_canceled
33
+ cancel!
34
+ assert_raises StateMachine::InvalidTransition do
35
+ finish!
36
+ end
37
+ refute(@pom.finished_at)
38
+ end
44
39
 
45
- Time.stub :now, Time.at(later) do
46
- assert_equal(later - @started, @pom.duration)
40
+ def test_length
41
+ assert_equal(25 * 60, @pom.length)
47
42
  end
48
- end
49
43
 
50
- def test_duration_finished
51
- later = @started + rand(42)
44
+ def test_duration_started
45
+ later = @started + rand(42)
52
46
 
53
- Time.stub :now, Time.at(later) do
54
- finish!
47
+ Time.stub :now, Time.at(later) do
48
+ assert_equal(later - @started, @pom.duration)
49
+ end
55
50
  end
56
51
 
57
- assert_equal(later - @started, @pom.duration)
58
- end
52
+ def test_duration_finished
53
+ later = @started + rand(42)
59
54
 
60
- def test_duration_canceled
61
- later = @started + rand(42)
55
+ Time.stub :now, Time.at(later) do
56
+ finish!
57
+ end
62
58
 
63
- Time.stub :now, Time.at(later) do
64
- cancel!
59
+ assert_equal(later - @started, @pom.duration)
65
60
  end
66
61
 
67
- assert_equal(later - @started, @pom.duration)
68
- end
62
+ def test_duration_canceled
63
+ later = @started + rand(42)
69
64
 
70
- def test_start
71
- assert_equal(:active, @pom.status_name)
72
- assert_equal(@started, @pom.started_at.to_i)
73
- end
65
+ Time.stub :now, Time.at(later) do
66
+ cancel!
67
+ end
74
68
 
75
- def test_remaining_active
76
- Time.stub :now, Time.at(@started) do
77
- assert_equal(Pomodoro::MINUTES_25 * 60, @pom.remaining)
69
+ assert_equal(later - @started, @pom.duration)
78
70
  end
79
71
 
80
- delta = 600
81
- later = @started + delta
82
-
83
- Time.stub :now, Time.at(later) do
84
- assert_equal(Pomodoro::MINUTES_25 * 60 - delta, @pom.remaining)
72
+ def test_start
73
+ assert_equal(:active, @pom.status_name)
74
+ assert_equal(@started, @pom.started_at.to_i)
85
75
  end
86
- end
87
76
 
88
- def test_interrupt
89
- assert_equal(0, @pom.interrupts.size)
77
+ def test_remaining_active
78
+ Time.stub :now, Time.at(@started) do
79
+ assert_equal(Pomodoro::MINUTES_25 * 60, @pom.remaining)
80
+ end
90
81
 
91
- now = srand
82
+ delta = 600
83
+ later = @started + delta
92
84
 
93
- Time.stub :now, Time.at(now) do
94
- interrupt!
85
+ Time.stub :now, Time.at(later) do
86
+ assert_equal(Pomodoro::MINUTES_25 * 60 - delta, @pom.remaining)
87
+ end
95
88
  end
96
89
 
97
- assert_equal(1, @pom.interrupts.size)
90
+ def test_interrupt
91
+ assert_equal(0, @pom.interrupts.size)
98
92
 
99
- int = @pom.interrupts.first
100
- assert_equal(now, int.created_at.to_i)
101
- assert_equal(:internal, int.type)
102
- end
93
+ now = srand
103
94
 
104
- def test_interrupt_internal
105
- interrupt!(:internal)
106
- assert_equal(1, @pom.interrupts.size)
107
- int = @pom.interrupts.first
108
- assert_equal(:internal, int.type)
109
- end
95
+ Time.stub :now, Time.at(now) do
96
+ interrupt!
97
+ end
110
98
 
111
- def test_interrupt_external
112
- interrupt!(:external)
113
- assert_equal(1, @pom.interrupts.size)
114
- int = @pom.interrupts.first
115
- assert_equal(:external, int.type)
116
- end
99
+ assert_equal(1, @pom.interrupts.size)
117
100
 
118
- def test_interrupt_unknown
119
- assert_raises InvalidTypeError do
120
- interrupt!(:unknown)
101
+ int = @pom.interrupts.first
102
+ assert_equal(now, int.created_at.to_i)
103
+ assert_equal(:internal, int.type)
121
104
  end
122
- end
123
105
 
124
- def test_interrupt_finished
125
- finish!
126
- assert_raises StateMachine::InvalidTransition do
127
- interrupt!
106
+ def test_interrupt_internal
107
+ interrupt!(:internal)
108
+ assert_equal(1, @pom.interrupts.size)
109
+ int = @pom.interrupts.first
110
+ assert_equal(:internal, int.type)
128
111
  end
129
- end
130
112
 
131
- def test_interrupt_canceled
132
- cancel!
133
- assert_raises StateMachine::InvalidTransition do
134
- interrupt!
113
+ def test_interrupt_external
114
+ interrupt!(:external)
115
+ assert_equal(1, @pom.interrupts.size)
116
+ int = @pom.interrupts.first
117
+ assert_equal(:external, int.type)
135
118
  end
136
- end
137
119
 
138
- def test_cancel_active
139
- assert_equal(:active, @pom.status_name)
120
+ def test_interrupt_unknown
121
+ assert_raises InvalidTypeError do
122
+ interrupt!(:unknown)
123
+ end
124
+ end
140
125
 
141
- now = srand
126
+ def test_interrupt_finished
127
+ finish!
128
+ assert_raises StateMachine::InvalidTransition do
129
+ interrupt!
130
+ end
131
+ end
142
132
 
143
- Time.stub :now, Time.at(now) do
133
+ def test_interrupt_canceled
144
134
  cancel!
135
+ assert_raises StateMachine::InvalidTransition do
136
+ interrupt!
137
+ end
145
138
  end
146
139
 
147
- assert_equal(:canceled, @pom.status_name)
148
- assert_equal(now, @pom.canceled_at.to_i)
149
- refute(@pom.finished_at)
150
- end
140
+ def test_cancel_active
141
+ assert_equal(:active, @pom.status_name)
151
142
 
152
- def test_annotate_active
153
- annotations = @pom.annotations
154
- assert(annotations)
155
- assert_empty(annotations)
143
+ now = srand
156
144
 
157
- text = 'foobar something'
158
- @pom.annotate(text)
145
+ Time.stub :now, Time.at(now) do
146
+ cancel!
147
+ end
159
148
 
160
- assert_equal(:active, @pom.status_name)
161
- refute_empty(@pom.annotations)
162
- assert_equal(text, @pom.annotations.first)
149
+ assert_equal(:canceled, @pom.status_name)
150
+ assert_equal(now, @pom.canceled_at.to_i)
151
+ refute(@pom.finished_at)
152
+ end
153
+
154
+ def test_annotate_active
155
+ annotations = @pom.annotations
156
+ assert(annotations)
157
+ assert_empty(annotations)
158
+
159
+ text = 'foobar something'
160
+ @pom.annotate(text)
161
+
162
+ assert_equal(:active, @pom.status_name)
163
+ refute_empty(@pom.annotations)
164
+ assert_equal(text, @pom.annotations.first)
165
+ end
163
166
  end
164
167
  end
@@ -1,218 +1,220 @@
1
1
  require 'helper'
2
- require 'tmpdir'
3
-
4
- class TestPomodoroHooks < MiniTest::Test
5
- def setup
6
- # Cannot use fakefs because hooks will not execute under it, but as part of
7
- # the real FS. Instead, we set the $PAR_DIR to point to a temp directory
8
- @orig_PAR_DIR = ENV['PAR_DIR']
9
- ENV['PAR_DIR'] = Dir.mktmpdir
10
- end
11
-
12
- def teardown
13
- FileUtils.rm_rf(Paradeiser.par_dir)
14
- ENV['PAR_DIR'] = @orig_PAR_DIR
15
- end
16
2
 
17
- def test_before_start_pomodoro_success
18
- hook_name = 'before-start-pomodoro'
19
- token_file = create_hook('Pomodoro', hook_name)
20
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
21
- pom = produce(Pomodoro)
22
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
23
- assert_equal(:active, pom.status_name)
24
- assert_match(/Pomodoro \d \d{1,2}:\d{1,2}/ , File.read(token_file).chomp)
25
- end
3
+ module ParadeiserTest
4
+ class TestPomodoroHooks < UnitTest
5
+ def setup
6
+ super
7
+ @token_file_registry = TokenFileRegistry.new
8
+ end
26
9
 
27
- def test_before_finish_pomodoro_success
28
- hook_name = 'before-finish-pomodoro'
29
- pom = produce(Pomodoro)
30
- pom.id = SecureRandom.random_number(1000)
31
- token_file = create_hook('Pomodoro', hook_name)
32
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
33
- pom.finish
34
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
35
- assert_equal(:finished, pom.status_name)
36
- assert_equal("Pomodoro #{pom.id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
37
- end
10
+ def teardown
11
+ if passed?
12
+ @token_file_registry.cleanup
13
+ super
14
+ end
15
+ end
38
16
 
39
- def test_before_finish_pomodoro_error
40
- hook_name = 'before-finish-pomodoro'
41
- pom = produce(Pomodoro)
42
- pom.id = SecureRandom.random_number(1000)
43
- token_file = create_hook('Pomodoro', hook_name, false)
44
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
17
+ def test_before_start_pomodoro_success
18
+ hook_name = 'before-start-pomodoro'
19
+ token_file = create_hook('Pomodoro', hook_name)
20
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
21
+ pom = produce(Pomodoro)
22
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
23
+ assert_equal(:active, pom.status_name)
24
+ assert_match(/^Pomodoro \d+ $/, File.read(token_file).chomp, "Token file: #{token_file}")
25
+ end
45
26
 
46
- assert_raises HookFailedError do
27
+ def test_before_finish_pomodoro_success
28
+ hook_name = 'before-finish-pomodoro'
29
+ pom = produce(Pomodoro)
30
+ pom.id = SecureRandom.random_number(1000)
31
+ token_file = create_hook('Pomodoro', hook_name)
32
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
47
33
  pom.finish
34
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
35
+ assert_equal(:finished, pom.status_name)
36
+ assert_equal("Pomodoro #{pom.id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
48
37
  end
49
38
 
50
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
51
- assert_equal(:active, pom.status_name)
52
- end
39
+ def test_before_finish_pomodoro_error
40
+ hook_name = 'before-finish-pomodoro'
41
+ pom = produce(Pomodoro)
42
+ pom.id = SecureRandom.random_number(1000)
43
+ token_file = create_hook('Pomodoro', hook_name, false)
44
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
53
45
 
54
- def test_before_finish_break_success
55
- hook_name = 'before-finish-break'
56
- br3ak = Break.new
57
- br3ak.id = SecureRandom.random_number(1000)
58
- token_file = create_hook('Break', hook_name)
59
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
60
- br3ak.finish
61
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
62
- assert_equal(:finished, br3ak.status_name)
63
- assert_equal("Break #{br3ak.id} #{br3ak.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
64
- end
46
+ assert_raises HookFailedError do
47
+ pom.finish
48
+ end
65
49
 
66
- def test_before_finish_break_error
67
- hook_name = 'before-finish-break'
68
- br3ak = Break.new
69
- br3ak.id = SecureRandom.random_number(1000)
70
- token_file = create_hook('Break', hook_name, false)
71
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
50
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
51
+ assert_equal(:active, pom.status_name)
52
+ end
72
53
 
73
- assert_raises HookFailedError do
54
+ def test_before_finish_break_success
55
+ hook_name = 'before-finish-break'
56
+ br3ak = Break.new
57
+ br3ak.id = SecureRandom.random_number(1000)
58
+ token_file = create_hook('Break', hook_name)
59
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
74
60
  br3ak.finish
61
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
62
+ assert_equal(:finished, br3ak.status_name)
63
+ assert_equal("Break #{br3ak.id} #{br3ak.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
75
64
  end
76
65
 
77
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
78
- assert_equal(:active, br3ak.status_name)
79
- end
66
+ def test_before_finish_break_error
67
+ hook_name = 'before-finish-break'
68
+ br3ak = Break.new
69
+ br3ak.id = SecureRandom.random_number(1000)
70
+ token_file = create_hook('Break', hook_name, false)
71
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
80
72
 
81
- def test_before_interrupt_success
82
- hook_name = 'before-interrupt-pomodoro'
83
- pom = produce(Pomodoro)
84
- token_file = create_hook('Pomodoro', hook_name)
85
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
86
- pom.interrupt
87
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
88
- assert_equal(:active, pom.status_name)
89
- assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
90
- end
73
+ assert_raises HookFailedError do
74
+ br3ak.finish
75
+ end
91
76
 
92
- def test_before_interrupt_error
93
- hook_name = 'before-interrupt-pomodoro'
94
- pom = produce(Pomodoro)
95
- token_file = create_hook('Pomodoro', hook_name, false)
96
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
77
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
78
+ assert_equal(:active, br3ak.status_name)
79
+ end
97
80
 
98
- assert_raises HookFailedError do
81
+ def test_before_interrupt_success
82
+ hook_name = 'before-interrupt-pomodoro'
83
+ pom = produce(Pomodoro)
84
+ token_file = create_hook('Pomodoro', hook_name)
85
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
99
86
  pom.interrupt
87
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
88
+ assert_equal(:active, pom.status_name)
89
+ assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
100
90
  end
101
91
 
102
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
103
- assert_equal(:active, pom.status_name)
104
- end
92
+ def test_before_interrupt_error
93
+ hook_name = 'before-interrupt-pomodoro'
94
+ pom = produce(Pomodoro)
95
+ token_file = create_hook('Pomodoro', hook_name, false)
96
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
105
97
 
106
- def test_after_interrupt_success
107
- hook_name = 'after-interrupt-pomodoro'
108
- pom = produce(Pomodoro)
109
- token_file = create_hook('Pomodoro', hook_name, false)
110
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
98
+ assert_raises HookFailedError do
99
+ pom.interrupt
100
+ end
111
101
 
112
- assert_raises HookFailedError do
113
- pom.interrupt
102
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
103
+ assert_equal(:active, pom.status_name)
114
104
  end
115
105
 
116
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
117
- assert_equal(:active, pom.status_name)
118
- end
106
+ def test_after_interrupt_success
107
+ hook_name = 'after-interrupt-pomodoro'
108
+ pom = produce(Pomodoro)
109
+ token_file = create_hook('Pomodoro', hook_name, false)
110
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
119
111
 
120
- def test_after_interrupt_error
121
- hook_name = 'after-interrupt-pomodoro'
122
- pom = produce(Pomodoro)
123
- token_file = create_hook('Pomodoro', hook_name)
124
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
125
- pom.interrupt
126
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
127
- assert_equal(:active, pom.status_name)
128
- assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
129
- end
112
+ assert_raises HookFailedError do
113
+ pom.interrupt
114
+ end
130
115
 
131
- def test_before_cancel_success
132
- hook_name = 'before-cancel-pomodoro'
133
- pom = produce(Pomodoro)
134
- token_file = create_hook('Pomodoro', hook_name)
135
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
136
- pom.cancel
137
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
138
- assert_equal(:canceled, pom.status_name)
139
- assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
140
- end
116
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
117
+ assert_equal(:active, pom.status_name)
118
+ end
141
119
 
142
- def test_before_cancel_error
143
- hook_name = 'before-cancel-pomodoro'
144
- pom = produce(Pomodoro)
145
- token_file = create_hook('Pomodoro', hook_name, false)
146
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
120
+ def test_after_interrupt_error
121
+ hook_name = 'after-interrupt-pomodoro'
122
+ pom = produce(Pomodoro)
123
+ token_file = create_hook('Pomodoro', hook_name)
124
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
125
+ pom.interrupt
126
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
127
+ assert_equal(:active, pom.status_name)
128
+ assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
129
+ end
147
130
 
148
- assert_raises HookFailedError do
131
+ def test_before_cancel_success
132
+ hook_name = 'before-cancel-pomodoro'
133
+ pom = produce(Pomodoro)
134
+ token_file = create_hook('Pomodoro', hook_name)
135
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
149
136
  pom.cancel
137
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
138
+ assert_equal(:canceled, pom.status_name)
139
+ assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
150
140
  end
151
141
 
152
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
153
- assert_equal(:active, pom.status_name)
154
- end
142
+ def test_before_cancel_error
143
+ hook_name = 'before-cancel-pomodoro'
144
+ pom = produce(Pomodoro)
145
+ token_file = create_hook('Pomodoro', hook_name, false)
146
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
155
147
 
156
- def test_after_cancel_success
157
- hook_name = 'after-cancel-pomodoro'
158
- pom = produce(Pomodoro)
159
- token_file = create_hook('Pomodoro', hook_name, false)
160
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
148
+ assert_raises HookFailedError do
149
+ pom.cancel
150
+ end
161
151
 
162
- assert_raises HookFailedError do
163
- pom.cancel
152
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
153
+ assert_equal(:active, pom.status_name)
164
154
  end
165
155
 
166
- refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
167
- assert_equal(:canceled, pom.status_name)
168
- end
156
+ def test_after_cancel_success
157
+ hook_name = 'after-cancel-pomodoro'
158
+ pom = produce(Pomodoro)
159
+ token_file = create_hook('Pomodoro', hook_name, false)
160
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
169
161
 
170
- def test_after_cancel_error
171
- hook_name = 'after-cancel-pomodoro'
172
- pom = produce(Pomodoro)
173
- token_file = create_hook('Pomodoro', hook_name)
174
- refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
175
- pom.cancel
176
- assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
177
- assert_equal(:canceled, pom.status_name)
178
- assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
179
- end
162
+ assert_raises HookFailedError do
163
+ pom.cancel
164
+ end
180
165
 
181
- private
166
+ refute_path_exists(token_file, "#{hook_name} hook should have created a token file")
167
+ assert_equal(:canceled, pom.status_name)
168
+ end
169
+
170
+ def test_after_cancel_error
171
+ hook_name = 'after-cancel-pomodoro'
172
+ pom = produce(Pomodoro)
173
+ token_file = create_hook('Pomodoro', hook_name)
174
+ refute_path_exists(token_file, "Token file must not exist before #{hook_name} hook is executed")
175
+ pom.cancel
176
+ assert_path_exists(token_file, "#{hook_name} hook should have created a token file")
177
+ assert_equal(:canceled, pom.status_name)
178
+ assert_equal("Pomodoro #{Repository.next_id} #{pom.started_at.strftime('%H:%M')}", File.read(token_file).chomp)
179
+ end
180
+
181
+ private
182
182
 
183
- def create_hook(thing, hook_name, hook_succeeds = true)
184
- token_file = File.join(Dir.tmpdir, SecureRandom.uuid)
183
+ def create_hook(thing, hook_name, hook_succeeds = true)
184
+ token_file = @token_file_registry.create
185
185
 
186
- hooks_dir = Paradeiser.hooks_dir
187
- FileUtils.mkdir(hooks_dir)
186
+ hooks_dir = Paradeiser.hooks_dir
187
+ FileUtils.mkdir(hooks_dir)
188
188
 
189
- hook_file = File.join(hooks_dir, hook_name)
189
+ hook_file = File.join(hooks_dir, hook_name)
190
190
 
191
- File.open(hook_file, 'w') do |f|
192
- if hook_succeeds
193
- f.write(hook_contents_success(thing, token_file))
194
- else
195
- f.write(hook_contents_failure)
191
+ File.open(hook_file, 'w') do |f|
192
+ if hook_succeeds
193
+ f.write(hook_contents_success(thing, token_file))
194
+ else
195
+ f.write(hook_contents_failure)
196
+ end
196
197
  end
197
- end
198
198
 
199
- File.chmod(0700, hook_file)
199
+ File.chmod(0700, hook_file)
200
200
 
201
- assert(File.exist?(hook_file))
202
- token_file
203
- end
201
+ assert(File.exist?(hook_file), "Hook #{hook_file} must exist")
202
+ assert(File.executable?(hook_file), "Hook #{hook_file} must be executable")
203
+ token_file
204
+ end
204
205
 
205
- def hook_contents_success(thing, token_file)
206
- hook_contents =<<"EOF"
207
- #!/bin/sh
208
- echo "#{thing} $PAR_#{thing.upcase}_ID $PAR_#{thing.upcase}_STARTED_AT" > #{token_file}
209
- EOF
210
- end
206
+ def hook_contents_success(thing, token_file)
207
+ <<~EOF
208
+ #!/bin/sh
209
+ echo "#{thing} $PAR_#{thing.upcase}_ID $PAR_#{thing.upcase}_STARTED_AT" > #{token_file}
210
+ EOF
211
+ end
211
212
 
212
- def hook_contents_failure
213
- hook_contents =<<"EOF"
214
- #!/bin/sh
215
- exit 1
216
- EOF
213
+ def hook_contents_failure
214
+ <<~EOF
215
+ #!/bin/sh
216
+ exit 1
217
+ EOF
218
+ end
217
219
  end
218
220
  end