/
raffle_spec.rb
56 lines (41 loc) · 1.36 KB
/
raffle_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require File.dirname(__FILE__) + '/spec_helper.rb'
require File.dirname(__FILE__) + '/../lib/raffle'
def create_raffle
@raffle = Raffle.new(["matt", "dominic"])
end
describe "a generic Raffle" do
before(:each) do
create_raffle
end
it "should be able to create a new instance of itself" do
lambda { Raffle.new }.should_not raise_error
end
it "should have participants" do
@raffle.participants.should == ["matt", "dominic"]
end
it "should be able to assign participants" do
@raffle.participants = ["matt", "dominic"]
@raffle.participants.should == ["matt", "dominic"]
end
it "should pick a winner" do
["matt", "dominic"].include?(@raffle.pick_a_winner).should be_true
end
it "should remove winners from the participants" do
amount_of_participants = @raffle.participants.size
@raffle.pick_a_winner
@raffle.participants.size.should == amount_of_participants - 1
end
end
describe 'in teasing mode' do
before(:each) do
create_raffle
@raffle.teasing_mode
end
it "should be able to run in teasing mode" do
@raffle.mode.should == 'teasing'
end
end
describe 'randomize' do
['test1', 'test2', 'test3', 'test4'].randomize.should_not == ['test1', 'test2', 'test3', 'test4']
['test1', 'test2', 'test3', 'test4'].randomize.sort.should == ['test1', 'test2', 'test3', 'test4']
end