Module: GuessStructTest

Defined in:
lib/guess_struct_test.rb

Instance Method Summary collapse

Instance Method Details

#test_class(t) ⇒ Object



4
5
6
7
8
9
# 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) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



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
# 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) ⇒ Object



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
# 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