spec/point_spec.rb in moosex-0.0.11 vs spec/point_spec.rb in moosex-0.0.12
- old
+ new
@@ -108,17 +108,16 @@
end
end
end
class Point3D < Point
-
- has x: { # override original attr!
- is: :rw,
- isa: Integer,
- default: 1,
+ has x: {
+ is: :rw, # Redefine attribute
+ isa: String, # should be String
+ default: "5", # default value is "5" (constant)
}
-
+
has z: {
is: :rw, # read-write (mandatory)
isa: Integer, # should be Integer
default: 0, # default value is 0 (constant)
}
@@ -129,41 +128,49 @@
writter: :set_the_color_of_this_point,
default: :red,
}
def clear
- self.x= 0 # to run with type-check you must
- self.y= 0 # use the setter instad @x=
+ self.x= "0" # to run with type-check you must
+ self.y= 0 # use the setter instad @x=
self.z= 0
end
end
describe "Point3D" do
describe "should has an intelligent constructor" do
it "without arguments, should initialize with default values" do
p = Point3D.new
- p.x.should == 1
+ p.x.should == "5"
p.y.should be_zero
p.z.should be_zero
p.what_is_the_color_of_this_point.should == :red
end
it "should initialize only y" do
- p = Point3D.new( x: 5 )
- p.x.should == 5
+ p = Point3D.new( x: "7" )
+ p.x.should == "7"
p.y.should be_zero
p.z.should be_zero
p.what_is_the_color_of_this_point.should == :red
end
it "should initialize x and y" do
- p = Point3D.new( x: 5, y: 4, z: 8, color: :yellow)
- p.x.should == 5
+ p = Point3D.new( x: "5", y: 4, z: 8, color: :yellow)
+ p.x.should == "5"
p.y.should == 4
p.z.should == 8
p.what_is_the_color_of_this_point.should == :yellow
end
+
+ it "for x, with type check" do
+ p = Point3D.new
+ expect {
+ p.x = 666
+ }.to raise_error(MooseX::Types::TypeCheckError,
+ "isa check for x=: Type violation: value '666' (Fixnum) is not an instance of [Type String]")
+ end
end
describe "should create a getter and a setter" do
it "for z" do
p = Point3D.new
@@ -185,12 +192,12 @@
}.to raise_error(MooseX::Types::TypeCheckError,
"isa check for field z: Type violation: value 'lol' (String) is not an instance of [Type Integer]")
end
it "clear should clean attributes" do
- p = Point3D.new( x: 5, y: 4, z: 9)
+ p = Point3D.new( x: "5", y: 4, z: 9)
p.clear
- p.x.should be_zero
+ p.x.should == "0"
p.y.should be_zero
p.z.should be_zero
end
end