forked from UWE-Ruby/RubyFall2013
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_spec.rb
More file actions
37 lines (29 loc) · 684 Bytes
/
timer_spec.rb
File metadata and controls
37 lines (29 loc) · 684 Bytes
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
require './code_timer.rb'
describe CodeTimer do
it "should run our code" do
flag = false
CodeTimer.time_code do
#test that block actually gets run
flag = true
end
flag.should eq true
end
it "should time our code" do
Time.stub(:now).and_return(0,3)
run_time = CodeTimer.time_code do
end
#we are 'faking' time
run_time.should be_within(0.1).of(3.0)
end
it "should run our code multiple times" do
i = 0
CodeTimer.time_code(10) { i += 1}
i.should eq 10
end
it "should give average time" do
run_time = CodeTime.time_code(10){
sleep(1)
}
run_time.should be_within(0.1).of(1.0)
end
end