test/test_casts.rb in tracksperanto-2.9.8 vs test/test_casts.rb in tracksperanto-2.9.9
- old
+ new
@@ -8,10 +8,11 @@
include Tracksperanto::Casts
attr_accessor :vanilla, :str_attr, :int_attr, :float_attr
cast_to_string :str_attr
cast_to_int :int_attr
cast_to_float :float_attr
+ cast_to_bool :truthy
end
class Junk
def to_s
"Random"
@@ -29,10 +30,27 @@
t.float_attr = "a"
assert_kind_of Float, t.float_attr
assert_in_delta 0, t.float_attr, D
end
-
+
+ def test_cast_to_bool
+ t = Testable.new
+ assert_equal false, t.truthy
+
+ t.truthy = nil
+ assert_equal false, t.truthy
+
+ t.truthy = false
+ assert_equal false, t.truthy
+
+ t.truthy = "yes"
+ assert_equal true, t.truthy
+
+ t.truthy = 1
+ assert_equal true, t.truthy
+ end
+
def test_cast_to_int
t = Testable.new
assert_equal 0, t.int_attr, "Uninitialized int attr should be an int"