collimator 0.0.1

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.
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ class TestProgressBar < Test::Unit::TestCase
4
+ include Collimator
5
+
6
+ def teardown
7
+ $stdout = STDOUT
8
+ end
9
+
10
+ def test_progress
11
+ out = capture_output do
12
+ ProgressBar.start({:min => 0, :max => 100, :method => :percent, :step_size => 1})
13
+ end
14
+
15
+ s = out.string.clone
16
+ assert_equal 102, s.count("\b")
17
+
18
+ s.gsub!("\b", "")
19
+ assert_equal "| 0.0% |", s
20
+ assert_equal s.length, 102
21
+
22
+ out = capture_output do
23
+ ProgressBar.increment
24
+ end
25
+
26
+ s = out.string.clone
27
+ s.gsub!("\b", "")
28
+ assert_equal "|- 1.0% |", s
29
+
30
+ 5.times do
31
+ out = capture_output do
32
+ ProgressBar.increment
33
+ end
34
+ end
35
+
36
+ out = capture_output do
37
+ ProgressBar.increment
38
+ end
39
+
40
+ s = out.string.clone
41
+ s.gsub!("\b", "")
42
+ assert_equal "|------- 7.0% |", s
43
+
44
+ 75.times do
45
+ out = capture_output do
46
+ ProgressBar.increment
47
+ end
48
+ end
49
+
50
+ out = capture_output do
51
+ ProgressBar.increment
52
+ end
53
+
54
+ s = out.string.clone
55
+ s.gsub!("\b", "")
56
+ assert_equal "|-----------------------------------------------83.0% ------------------------------ |", s
57
+
58
+ end
59
+
60
+ def test_completion
61
+ out = capture_output do
62
+ ProgressBar.start({:min => 0, :max => 100, :method => :percent, :step_size => 10})
63
+ end
64
+
65
+ 5.times do
66
+ out = capture_output do
67
+ ProgressBar.increment
68
+ end
69
+ end
70
+
71
+ out = capture_output do
72
+ ProgressBar.increment
73
+ end
74
+ s = out.string.clone
75
+ s.gsub!("\b", "")
76
+ assert_equal "|-----------------------------------------------60.0% ------- |", s
77
+
78
+ out = capture_output do
79
+ ProgressBar.complete
80
+ end
81
+
82
+ s = out.string.clone
83
+ s.gsub!("\b", "")
84
+ assert_equal " \n", s
85
+
86
+ end
87
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class TestProgressBar < Test::Unit::TestCase
4
+ include Collimator
5
+
6
+ def teardown
7
+ $stdout = STDOUT
8
+ end
9
+
10
+ def test_spinner
11
+ spin_time = 1
12
+ out = capture_output do
13
+ Spinner.spin
14
+ sleep spin_time
15
+ Spinner.stop
16
+ end
17
+
18
+ length_should_be = (spin_time / 0.1) * 2
19
+ s = out.string.clone
20
+ assert_equal length_should_be, s.length
21
+
22
+ spin_time = 0.2
23
+ out = capture_output do
24
+ Spinner.spin
25
+ sleep spin_time
26
+ Spinner.stop
27
+ end
28
+
29
+ length_should_be = (spin_time / 0.1) * 2
30
+ s = out.string.clone
31
+ assert_equal length_should_be, s.length
32
+ end
33
+
34
+ end