forked from ryanb/populator
/
random_spec.rb
41 lines (34 loc) · 1.39 KB
/
random_spec.rb
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
require File.dirname(__FILE__) + '/../spec_helper.rb'
describe Populator::Random do
it "should pick a random number in range excluding last value" do
Populator.expects(:rand).with(5).returns(3)
Populator.value_in_range(10...15).should == 13
end
it "should pick a random number in range including last value" do
Populator.expects(:rand).with(5).returns(3)
Populator.value_in_range(10..14).should == 13
end
it "should pick a random time in range" do
start_time = 2.days.ago
end_time = Time.now
Populator.expects(:rand).with(end_time.to_i-start_time.to_i).returns(1)
Populator.value_in_range(start_time...end_time).should == Time.at(start_time.to_i + 1)
end
it "should pick a random date in range" do
start_date = 2.years.ago.to_date
end_date = Date.today
Populator.expects(:rand).with(end_date.jd-start_date.jd).returns(1)
Populator.value_in_range(start_date...end_date).should == Date.jd(start_date.jd + 1)
end
it "should pick a random string by converting to array" do
Kernel.expects(:rand).with(5).returns(2)
Populator.value_in_range('a'..'e').should == 'c'
end
it "should pick 3 random words" do
Populator.words(3).split.should have(3).records
end
it "should pick a random number of random words" do
Populator.expects(:rand).with(5).returns(3)
Populator.words(10...15).split.should have(13).records
end
end