spec/properties_spec.rb in efo_nelfo-1.5.3 vs spec/properties_spec.rb in efo_nelfo-1.5.4
- old
+ new
@@ -37,14 +37,43 @@
it "adds a getter method for :foo" do
obj.foo.must_equal 'I am foo'
end
it "adds a setter method for :foo" do
- obj.foo = 'Test'
- obj.foo.must_equal 'Test'
+ obj.foo = 'abc'
+ obj.foo.must_equal 'abc'
end
+ it "cuts off strings longer than the limit" do
+ obj.foo = "Long string"
+ obj.foo.must_equal "Lon"
+ end
+
+ it "won't cut off strings" do
+ # bar has no limit specified, uses defaults
+ obj.bar = "hahaha"
+ obj.bar.must_equal "hahaha"
+
+ # numbers are ignored, even if specified type is string
+ obj.bar = 123
+ obj.bar.must_equal 123
+
+ obj.foo = 123456
+ obj.foo.must_equal 123456
+
+ obj.foo = "123456"
+ obj.foo.must_equal "123"
+ end
+
+ it "raises exception if string is longer than limit and strict_mode is enabled" do
+ EfoNelfo.strict_mode = true
+ lambda {
+ obj.foo = "Long"
+ }.must_raise ArgumentError
+ EfoNelfo.strict_mode = false
+ end
+
it "adds a question method for boolean types" do
obj.doable?.must_equal false
obj.doable = true
obj.doable?.must_equal true
end
@@ -53,14 +82,14 @@
obj.foo = 'Sjøhest'
obj.foo.encoding.name.must_equal 'UTF-8'
end
it "adds an alias getter and setter for foo" do
- obj.foo = 'Test'
- obj.Føbar.must_equal 'Test'
- obj.Føbar = 'Hacked'
- obj.Føbar.must_equal 'Hacked'
- obj.foo.must_equal 'Hacked'
+ obj.foo = 'ABC'
+ obj.Føbar.must_equal 'ABC'
+ obj.Føbar = 'CDE'
+ obj.Føbar.must_equal 'CDE'
+ obj.foo.must_equal 'CDE'
end
it "assigns default values" do
obj.bar.must_be_nil
obj.foo.must_equal 'I am foo'