-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenum_spec.rb
93 lines (72 loc) · 2.11 KB
/
enum_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'rubygems'
require 'spec'
require File.dirname(__FILE__) + '/enum'
describe "Color.all" do
it "should return all valid colors" do
Color.all.map { |c| c.label }.sort.should == [:dark_green, :sky_blue, :brick_red].sort
end
end
describe "A valid color" do
before(:each) do
@color = Color.new(:brick_red)
end
it "should be valid" do
@color.valid?.should be_true
end
it "should always return its label as a symbol" do
Color.new('dark_green').label.should == :dark_green
end
describe "to_s" do
it "returns the color's english name" do
"#{@color}".should == "Brick Red"
end
end
describe "label" do
it "should return the color's label" do
@color.label.should == :brick_red
end
end
describe "hash" do
it "should return the same value for two of the same colors" do
Color.new(:dark_green).hash == Color.new(:dark_green).hash
end
it "should not return the same value for two different colors" do
Color.new(:dark_green).hash != Color.new(:sky_blue).hash
end
end
describe "==" do
it "should return true for two of the same colors" do
(Color.new(:dark_green) == Color.new(:dark_green)).should be_true
end
it "should return false for two different colors" do
(Color.new(:dark_green) == Color.new(:sky_blue)).should be_false
end
end
describe "!=" do
it "should return false for two of the same colors" do
(Color.new(:dark_green) != Color.new(:dark_green)).should be_false
end
it "should return true for two different colors" do
(Color.new(:dark_green) != Color.new(:sky_blue)).should be_true
end
end
end
describe "An invalid color" do
it "should raise an ArgumentError" do
lambda {
Color.new(:asdf)
}.should raise_error(ArgumentError)
end
end
describe "A flavor" do
it "should accept a valid flavor" do
lambda {
Flavor.new(:vanilla)
}.should_not raise_error(ArgumentError)
end
it "should not accept a valid color" do
lambda {
Flavor.new(:dark_green)
}.should raise_error(ArgumentError)
end
end