Repository navigation
Expand file tree
/
Copy pathsham_spec.rb
More file actions
61 lines (53 loc) · 1.6 KB
/
Copy pathsham_spec.rb
File metadata and controls
61 lines (53 loc) · 1.6 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
61
require File.dirname(__FILE__) + '/spec_helper'
require 'sham'
describe Sham do
it "should ensure generated values are unique" do
Sham.clear
Sham.half_index {|index| index/2 }
values = (1..10).map { Sham.half_index }
values.should == (0..9).to_a
end
it "should generate non-unique values when asked" do
Sham.clear
Sham.coin_toss(:unique => false) {|index| index % 2 == 1 ? 'heads' : 'tails' }
values = (1..4).map { Sham.coin_toss }
values.should == ['heads', 'tails', 'heads', 'tails']
end
it "should generate more than a dozen values" do
Sham.clear
Sham.index {|index| index }
values = (1..25).map { Sham.index }
values.should == (1..25).to_a
end
it "should generate the same sequence of values after a reset" do
Sham.clear
Sham.random { rand }
values1 = (1..10).map { Sham.random }
Sham.reset
values2 = (1..10).map { Sham.random }
values2.should == values1
end
it "should die when it runs out of unique values" do
Sham.clear
Sham.limited {|index| index%10 }
lambda {
(1..100).map { Sham.limited }
}.should raise_error(RuntimeError)
end
it "should allow over-riding the name method" do
Sham.clear
Sham.name {|index| index }
Sham.name.should == 1
end
describe "define method" do
it "should repeat messages in its block to Sham" do
block = Proc.new {}
Sham.should_receive(:name).with(&block).once.ordered
Sham.should_receive(:slug).with(:arg, &block).once.ordered
Sham.define do
name &block
slug :arg, &block
end
end
end
end