module GuessStructTest
Public Instance Methods
test_class(t)
click to toggle source
# File lib/guess_struct_test.rb, line 4 def test_class(t) s = GuessStruct.new(:foo, :bar, :baz) unless Class === s t.error("GuessStruct instance is not Class") end end
test_clear(t)
click to toggle source
# File lib/guess_struct_test.rb, line 73 def test_clear(t) s = GuessStruct.new(:foo, :bar, :baz) si = s.new(foo: :sym) unless s.definition == { foo: Symbol, bar: nil, baz: nil } t.error("definition miss") end s.clear unless s.definition == { foo: nil, bar: nil, baz: nil } t.error("clear miss") end end
test_make_struct(t)
click to toggle source
# File lib/guess_struct_test.rb, line 11 def test_make_struct(t) s = GuessStruct.new(:foo, :bar, :baz) si = s.new si.foo = 1 unless 1 == si.foo t.error("set value was changed") end si.foo = 2 unless 2 == si.foo t.error("set value was changed") end unless si.bar.nil? && si.baz.nil? t.error("other attr was changed") end begin si.foo = "a" rescue GuessStruct::GuessError else t.error("Not raise error when different type from first") end si = s.new begin si.foo = "a" rescue GuessStruct::GuessError else t.error("miss share guess class") end si.foo = 1 si.foo = nil si.foo = 5 end
test_make_struct_with_key_args(t)
click to toggle source
# File lib/guess_struct_test.rb, line 46 def test_make_struct_with_key_args(t) s = GuessStruct.new(:foo, :bar, :baz) si = s.new(foo: "a") unless "a" == si.foo t.error("initial value dose not setted") end si.foo = "b" unless "b" == si.foo t.error("initial value dose not setted") end begin si.foo = 1 rescue GuessStruct::GuessError else t.error("invalid value") end begin s.new(foo: 1) rescue GuessStruct::GuessError else t.error("invalid value") end end