From 3c60a40b796843e62ba2b56f4878a569c86a9d6e Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 11 Sep 2007 00:41:54 -0700 Subject: [PATCH] even more test coverage --- lib/god/contact.rb | 2 +- test/test_contact.rb | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_god.rb | 22 ++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/lib/god/contact.rb b/lib/god/contact.rb index c2e04a6..c382183 100644 --- a/lib/god/contact.rb +++ b/lib/god/contact.rb @@ -80,7 +80,7 @@ module God spec else - raise ArgumentError.new("must be a String (contact name) or Hash (contact specification)") + raise ArgumentError.new("must be a String (contact name), Array (of contact names), or Hash (contact specification)") end end diff --git a/test/test_contact.rb b/test/test_contact.rb index 32f0749..1926b8c 100644 --- a/test/test_contact.rb +++ b/test/test_contact.rb @@ -4,4 +4,100 @@ class TestContact < Test::Unit::TestCase def test_exists God::Contact end + + # generate + + def test_generate_should_raise_on_invalid_kind + assert_raise(NoSuchContactError) do + Contact.generate(:invalid) + 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_raise ArgumentError do + Contact.normalize(input) + end + end + + def test_normalize_should_raise_on_non_string_array_contacts_key + input = {:contacts => 1} + assert_raise ArgumentError do + Contact.normalize(input) + end + end + + def test_normalize_should_raise_on_non_string_containing_array + input = [1] + assert_raise ArgumentError do + Contact.normalize(input) + end + end + + def test_normalize_should_raise_on_non_string_containing_array_contacts_key + input = {:contacts => [1]} + assert_raise ArgumentError do + Contact.normalize(input) + end + end + + def test_normalize_should_raise_on_absent_contacts_key + input = {} + assert_raise 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_raise ArgumentError do + Contact.normalize(input) + end + end + + # notify + + def test_notify_should_be_abstract + assert_raise(AbstractMethodNotOverriddenError) do + Contact.new.notify(:a, :b, :c, :d) + end + end end \ No newline at end of file diff --git a/test/test_god.rb b/test/test_god.rb index 98cb01e..998adc1 100644 --- a/test/test_god.rb +++ b/test/test_god.rb @@ -201,6 +201,12 @@ class TestGod < Test::Unit::TestCase assert God.inited end + def test_contact_should_abort_on_invalid_contact_kind + assert_abort do + God.contact(:foo) { |c| c.name = 'tom' } + end + end + def test_contact_should_create_and_store_contact contact = nil God.contact(:fake_contact) { |c| c.name = 'tom'; contact = c } @@ -339,6 +345,22 @@ class TestGod < Test::Unit::TestCase assert_equal({'foo' => {:state => :unmonitored}}, God.status) end + # running_log + + def test_running_log_should_call_watch_log_since_on_main_log + God.watch { |w| w.name = 'foo'; w.start = 'bar' } + t = Time.now + LOG.expects(:watch_log_since).with('foo', t) + God.running_log('foo', t) + end + + def test_running_log_should_raise_on_unknown_watch + God.internal_init + assert_raise(NoSuchWatchError) do + God.running_log('foo', Time.now) + end + end + # running_load def test_running_load_should_eval_code -- 2.11.4.GIT