forked from alexch/learn_ruby
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathtimer_spec.rb
More file actions
60 lines (49 loc) · 1.28 KB
/
timer_spec.rb
File metadata and controls
60 lines (49 loc) · 1.28 KB
1
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# # Topics
#
# * classes
# * instance variables
# * string formats
# * modular arithmetic
#
# # Timer
require 'timer'
describe "Timer" do
before(:each) do
@timer = Timer.new
end
it "should initialize to 0 seconds" do
expect(@timer.seconds).to eq(0)
end
describe 'time_string' do
it "should display 0 seconds as 00:00:00" do
@timer.seconds = 0
expect(@timer.time_string).to eq("00:00:00")
end
it "should display 12 seconds as 00:00:12" do
@timer.seconds = 12
expect(@timer.time_string).to eq("00:00:12")
end
it "should display 66 seconds as 00:01:06" do
@timer.seconds = 66
expect(@timer.time_string).to eq("00:01:06")
end
it "should display 4000 seconds as 01:06:40" do
@timer.seconds = 4000
expect(@timer.time_string).to eq("01:06:40")
end
end
# One way to implement the Timer is with a helper method.
# Uncomment these specs if you want to test-drive that
# method, then call that method from inside of time_string.
describe 'padded' do
it 'pads zero' do
expect(@timer.padded(0)).to eq('00')
end
it 'pads one' do
expect(@timer.padded(1)).to eq('01')
end
it "doesn't pad a two-digit number" do
expect(@timer.padded(12)).to eq('12')
end
end
end