1 require File.dirname(__FILE__) + '/helper'
3 class TestContact < Test::Unit::TestCase
10 def test_generate_should_raise_on_invalid_kind
11 assert_raise(NoSuchContactError) do
12 Contact.generate(:invalid)
18 def test_normalize_should_accept_a_string
20 output = {:contacts => ['tom']}
21 assert_equal(output, Contact.normalize(input))
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))
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))
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))
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))
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))
54 def test_normalize_should_raise_on_non_string_array_hash
56 assert_raise ArgumentError do
57 Contact.normalize(input)
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)
68 def test_normalize_should_raise_on_non_string_containing_array
70 assert_raise ArgumentError do
71 Contact.normalize(input)
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)
82 def test_normalize_should_raise_on_absent_contacts_key
84 assert_raise ArgumentError do
85 Contact.normalize(input)
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)
98 def test_notify_should_be_abstract
99 assert_raise(AbstractMethodNotOverriddenError) do
100 Contact.new.notify(:a, :b, :c, :d)