even more test coverage
[god.git] / test / test_contact.rb
blob1926b8c4fe0b2f2b36e9985d839210c1e8e9c37b
1 require File.dirname(__FILE__) + '/helper'
3 class TestContact < Test::Unit::TestCase
4   def test_exists
5     God::Contact
6   end
7   
8   # generate
9   
10   def test_generate_should_raise_on_invalid_kind
11     assert_raise(NoSuchContactError) do
12       Contact.generate(:invalid)
13     end
14   end
15   
16   # normalize
17   
18   def test_normalize_should_accept_a_string
19     input = 'tom'
20     output = {:contacts => ['tom']}
21     assert_equal(output, Contact.normalize(input))
22   end
23   
24   def test_normalize_should_accept_an_array_of_strings
25     input = ['tom', 'kevin']
26     output = {:contacts => ['tom', 'kevin']}
27     assert_equal(output, Contact.normalize(input))
28   end
29   
30   def test_normalize_should_accept_a_hash_with_contacts_string
31     input = {:contacts => 'tom'}
32     output = {:contacts => ['tom']}
33     assert_equal(output, Contact.normalize(input))
34   end
35   
36   def test_normalize_should_accept_a_hash_with_contacts_array_of_strings
37     input = {:contacts => ['tom', 'kevin']}
38     output = {:contacts => ['tom', 'kevin']}
39     assert_equal(output, Contact.normalize(input))
40   end
41   
42   def test_normalize_should_stringify_priority
43     input = {:contacts => 'tom', :priority => 1}
44     output = {:contacts => ['tom'], :priority => '1'}
45     assert_equal(output, Contact.normalize(input))
46   end
47   
48   def test_normalize_should_stringify_category
49     input = {:contacts => 'tom', :category => :product}
50     output = {:contacts => ['tom'], :category => 'product'}
51     assert_equal(output, Contact.normalize(input))
52   end
53   
54   def test_normalize_should_raise_on_non_string_array_hash
55     input = 1
56     assert_raise ArgumentError do
57       Contact.normalize(input)
58     end
59   end
60   
61   def test_normalize_should_raise_on_non_string_array_contacts_key
62     input = {:contacts => 1}
63     assert_raise ArgumentError do
64       Contact.normalize(input)
65     end
66   end
67   
68   def test_normalize_should_raise_on_non_string_containing_array
69     input = [1]
70     assert_raise ArgumentError do
71       Contact.normalize(input)
72     end
73   end
74   
75   def test_normalize_should_raise_on_non_string_containing_array_contacts_key
76     input = {:contacts => [1]}
77     assert_raise ArgumentError do
78       Contact.normalize(input)
79     end
80   end
81   
82   def test_normalize_should_raise_on_absent_contacts_key
83     input = {}
84     assert_raise ArgumentError do
85       Contact.normalize(input)
86     end
87   end
88   
89   def test_normalize_should_raise_on_extra_keys
90     input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
91     assert_raise ArgumentError do
92       Contact.normalize(input)
93     end
94   end
95   
96   # notify
97   
98   def test_notify_should_be_abstract
99     assert_raise(AbstractMethodNotOverriddenError) do
100       Contact.new.notify(:a, :b, :c, :d)
101     end
102   end