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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Guardfile +16 -11
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/TODO.md +12 -1
- data/bin/par +5 -2
- data/lib/paradeiser.rb +22 -2
- data/lib/paradeiser/controllers/controller.rb +1 -0
- data/lib/paradeiser/controllers/paradeiser_controller.rb +0 -1
- data/lib/paradeiser/models/hook.rb +4 -0
- data/lib/paradeiser/models/repository.rb +1 -1
- data/lib/paradeiser/models/scheduled.rb +4 -0
- data/lib/paradeiser/version.rb +1 -1
- data/paradeiser.gemspec +1 -6
- data/templates/linux/hooks/after-finish-break +2 -0
- data/templates/linux/hooks/after-finish-pomodoro +2 -0
- data/templates/linux/hooks/after-start-break +2 -0
- data/templates/linux/hooks/after-start-pomodoro +2 -0
- data/templates/mac/hooks/after-finish-break +2 -0
- data/templates/mac/hooks/after-finish-pomodoro +2 -0
- data/templates/mac/hooks/after-start-break +2 -0
- data/templates/mac/hooks/after-start-pomodoro +2 -0
- data/test/helper.rb +14 -36
- data/test/integration/test_annotate.rb +15 -13
- data/test/integration/test_finish.rb +7 -5
- data/test/integration/test_interrupt.rb +7 -5
- data/test/integration/test_log.rb +9 -7
- data/test/integration/test_no_args.rb +5 -3
- data/test/integration/test_start.rb +5 -3
- data/test/integration/test_status.rb +8 -6
- data/test/integration/test_unknown.rb +5 -3
- data/test/lib/controller_test.rb +4 -2
- data/test/lib/integration_test.rb +8 -2
- data/test/lib/paradeiser_controller_test.rb +7 -1
- data/test/lib/token_file_registry.rb +19 -0
- data/test/lib/unit_test.rb +47 -0
- data/test/lib/view_test.rb +13 -8
- data/test/scripts/create-failing-hooks +17 -0
- data/test/scripts/fail +5 -0
- data/test/unit/test_break.rb +43 -40
- data/test/unit/test_break_view.rb +17 -14
- data/test/unit/test_breaks_controller.rb +55 -52
- data/test/unit/test_interrupt.rb +27 -24
- data/test/unit/test_paradeiser_controller_export.rb +103 -100
- data/test/unit/test_paradeiser_controller_init.rb +2 -2
- data/test/unit/test_paradeiser_controller_report.rb +72 -69
- data/test/unit/test_paradeiser_controller_status.rb +78 -75
- data/test/unit/test_paradeiser_view_init.rb +5 -3
- data/test/unit/test_paradeiser_view_report.rb +116 -114
- data/test/unit/test_paradeiser_view_status.rb +14 -11
- data/test/unit/test_pomodori_controller.rb +319 -316
- data/test/unit/test_pomodori_view.rb +40 -37
- data/test/unit/test_pomodoro.rb +116 -113
- data/test/unit/test_pomodoro_hooks.rb +172 -170
- data/test/unit/test_repository.rb +98 -95
- data/test/unit/test_scheduler.rb +39 -30
- data/test/unit/test_token_file_registry.rb +40 -0
- metadata +59 -49
@@ -1,41 +1,44 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
data/test/unit/test_pomodoro.rb
CHANGED
@@ -1,164 +1,167 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
10
|
+
def test_finish_active
|
11
|
+
assert_equal(:active, @pom.status_name)
|
12
12
|
|
13
|
-
|
14
|
-
finish!
|
15
|
-
end
|
13
|
+
now = srand
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
Time.stub :now, Time.at(now) do
|
16
|
+
finish!
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
-
|
43
|
-
|
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
|
-
|
46
|
-
assert_equal(
|
40
|
+
def test_length
|
41
|
+
assert_equal(25 * 60, @pom.length)
|
47
42
|
end
|
48
|
-
end
|
49
43
|
|
50
|
-
|
51
|
-
|
44
|
+
def test_duration_started
|
45
|
+
later = @started + rand(42)
|
52
46
|
|
53
|
-
|
54
|
-
|
47
|
+
Time.stub :now, Time.at(later) do
|
48
|
+
assert_equal(later - @started, @pom.duration)
|
49
|
+
end
|
55
50
|
end
|
56
51
|
|
57
|
-
|
58
|
-
|
52
|
+
def test_duration_finished
|
53
|
+
later = @started + rand(42)
|
59
54
|
|
60
|
-
|
61
|
-
|
55
|
+
Time.stub :now, Time.at(later) do
|
56
|
+
finish!
|
57
|
+
end
|
62
58
|
|
63
|
-
|
64
|
-
cancel!
|
59
|
+
assert_equal(later - @started, @pom.duration)
|
65
60
|
end
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
def test_duration_canceled
|
63
|
+
later = @started + rand(42)
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
65
|
+
Time.stub :now, Time.at(later) do
|
66
|
+
cancel!
|
67
|
+
end
|
74
68
|
|
75
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
89
|
-
|
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
|
-
|
82
|
+
delta = 600
|
83
|
+
later = @started + delta
|
92
84
|
|
93
|
-
|
94
|
-
|
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
|
-
|
90
|
+
def test_interrupt
|
91
|
+
assert_equal(0, @pom.interrupts.size)
|
98
92
|
|
99
|
-
|
100
|
-
assert_equal(now, int.created_at.to_i)
|
101
|
-
assert_equal(:internal, int.type)
|
102
|
-
end
|
93
|
+
now = srand
|
103
94
|
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
139
|
-
|
120
|
+
def test_interrupt_unknown
|
121
|
+
assert_raises InvalidTypeError do
|
122
|
+
interrupt!(:unknown)
|
123
|
+
end
|
124
|
+
end
|
140
125
|
|
141
|
-
|
126
|
+
def test_interrupt_finished
|
127
|
+
finish!
|
128
|
+
assert_raises StateMachine::InvalidTransition do
|
129
|
+
interrupt!
|
130
|
+
end
|
131
|
+
end
|
142
132
|
|
143
|
-
|
133
|
+
def test_interrupt_canceled
|
144
134
|
cancel!
|
135
|
+
assert_raises StateMachine::InvalidTransition do
|
136
|
+
interrupt!
|
137
|
+
end
|
145
138
|
end
|
146
139
|
|
147
|
-
|
148
|
-
|
149
|
-
refute(@pom.finished_at)
|
150
|
-
end
|
140
|
+
def test_cancel_active
|
141
|
+
assert_equal(:active, @pom.status_name)
|
151
142
|
|
152
|
-
|
153
|
-
annotations = @pom.annotations
|
154
|
-
assert(annotations)
|
155
|
-
assert_empty(annotations)
|
143
|
+
now = srand
|
156
144
|
|
157
|
-
|
158
|
-
|
145
|
+
Time.stub :now, Time.at(now) do
|
146
|
+
cancel!
|
147
|
+
end
|
159
148
|
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
113
|
-
pom.
|
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
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
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
|
-
|
163
|
-
pom.
|
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
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
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
|
-
|
184
|
-
|
183
|
+
def create_hook(thing, hook_name, hook_succeeds = true)
|
184
|
+
token_file = @token_file_registry.create
|
185
185
|
|
186
|
-
|
187
|
-
|
186
|
+
hooks_dir = Paradeiser.hooks_dir
|
187
|
+
FileUtils.mkdir(hooks_dir)
|
188
188
|
|
189
|
-
|
189
|
+
hook_file = File.join(hooks_dir, hook_name)
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
199
|
+
File.chmod(0700, hook_file)
|
200
200
|
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|
-
|
206
|
-
|
207
|
-
#!/bin/sh
|
208
|
-
echo "#{thing} $PAR_#{thing.upcase}_ID $PAR_#{thing.upcase}_STARTED_AT" > #{token_file}
|
209
|
-
EOF
|
210
|
-
|
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
|
-
|
213
|
-
|
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
|