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)
16 def test_generate_should_abort_on_invalid_contact
18 Contact.generate(:invalid_contact)
24 def test_normalize_should_accept_a_string
26 output = {:contacts => ['tom']}
27 assert_equal(output, Contact.normalize(input))
30 def test_normalize_should_accept_an_array_of_strings
31 input = ['tom', 'kevin']
32 output = {:contacts => ['tom', 'kevin']}
33 assert_equal(output, Contact.normalize(input))
36 def test_normalize_should_accept_a_hash_with_contacts_string
37 input = {:contacts => 'tom'}
38 output = {:contacts => ['tom']}
39 assert_equal(output, Contact.normalize(input))
42 def test_normalize_should_accept_a_hash_with_contacts_array_of_strings
43 input = {:contacts => ['tom', 'kevin']}
44 output = {:contacts => ['tom', 'kevin']}
45 assert_equal(output, Contact.normalize(input))
48 def test_normalize_should_stringify_priority
49 input = {:contacts => 'tom', :priority => 1}
50 output = {:contacts => ['tom'], :priority => '1'}
51 assert_equal(output, Contact.normalize(input))
54 def test_normalize_should_stringify_category
55 input = {:contacts => 'tom', :category => :product}
56 output = {:contacts => ['tom'], :category => 'product'}
57 assert_equal(output, Contact.normalize(input))
60 def test_normalize_should_raise_on_non_string_array_hash
62 assert_raise ArgumentError do
63 Contact.normalize(input)
67 def test_normalize_should_raise_on_non_string_array_contacts_key
68 input = {:contacts => 1}
69 assert_raise ArgumentError do
70 Contact.normalize(input)
74 def test_normalize_should_raise_on_non_string_containing_array
76 assert_raise ArgumentError do
77 Contact.normalize(input)
81 def test_normalize_should_raise_on_non_string_containing_array_contacts_key
82 input = {:contacts => [1]}
83 assert_raise ArgumentError do
84 Contact.normalize(input)
88 def test_normalize_should_raise_on_absent_contacts_key
90 assert_raise ArgumentError do
91 Contact.normalize(input)
95 def test_normalize_should_raise_on_extra_keys
96 input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
97 assert_raise ArgumentError do
98 Contact.normalize(input)
104 def test_notify_should_be_abstract
105 assert_raise(AbstractMethodNotOverriddenError) do
106 Contact.new.notify(:a, :b, :c, :d, :e)