1 2 3 4 5 6 7 8 9 10 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 45 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
require File.dirname(__FILE__) + '/helper'
class TestContact < Minitest::Test
def test_exists
God::Contact
end
# generate
def test_generate_should_raise_on_invalid_kind
assert_raises(NoSuchContactError) do
Contact.generate(:invalid)
end
end
def test_generate_should_abort_on_invalid_contact
assert_abort do
Contact.generate(:invalid_contact)
end
end
# normalize
def test_normalize_should_accept_a_string
input = 'tom'
output = {:contacts => ['tom']}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_accept_an_array_of_strings
input = ['tom', 'kevin']
output = {:contacts => ['tom', 'kevin']}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_accept_a_hash_with_contacts_string
input = {:contacts => 'tom'}
output = {:contacts => ['tom']}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_accept_a_hash_with_contacts_array_of_strings
input = {:contacts => ['tom', 'kevin']}
output = {:contacts => ['tom', 'kevin']}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_stringify_priority
input = {:contacts => 'tom', :priority => 1}
output = {:contacts => ['tom'], :priority => '1'}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_stringify_category
input = {:contacts => 'tom', :category => :product}
output = {:contacts => ['tom'], :category => 'product'}
assert_equal(output, Contact.normalize(input))
end
def test_normalize_should_raise_on_non_string_array_hash
input = 1
assert_raises ArgumentError do
Contact.normalize(input)
end
end
def test_normalize_should_raise_on_non_string_array_contacts_key
input = {:contacts => 1}
assert_raises ArgumentError do
Contact.normalize(input)
end
end
def test_normalize_should_raise_on_non_string_containing_array
input = [1]
assert_raises ArgumentError do
Contact.normalize(input)
end
end
def test_normalize_should_raise_on_non_string_containing_array_contacts_key
input = {:contacts => [1]}
assert_raises ArgumentError do
Contact.normalize(input)
end
end
def test_normalize_should_raise_on_absent_contacts_key
input = {}
assert_raises ArgumentError do
Contact.normalize(input)
end
end
def test_normalize_should_raise_on_extra_keys
input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
assert_raises ArgumentError do
Contact.normalize(input)
end
end
# notify
def test_notify_should_be_abstract
assert_raises(AbstractMethodNotOverriddenError) do
Contact.new.notify(:a, :b, :c, :d, :e)
end
end
end
|