Sha256: f63eb7fe0e438bca302c7be751c52c2752fcac4e3cac889f9813f9a018c8ea6b

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'assert'

class Sanford::HostData

  class BaseTests < Assert::Context
    desc "Sanford::HostData"
    setup do
      TestHost.init_has_been_called = false
      @host_data = Sanford::HostData.new(TestHost)
    end
    teardown do
      TestHost.init_has_been_called = false
    end
    subject{ @host_data }

    should have_instance_methods :name, :logger, :verbose, :keep_alive, :runner,
      :error_procs, :run, :handler_class_for

    should "default it's configuration from the service host, but allow overrides" do
      host_data = Sanford::HostData.new(TestHost, :verbose_logging => false)

      assert_equal TestHost.receives_keep_alive, host_data.keep_alive
      assert_equal false, host_data.verbose
    end

    should "ignore nil values passed as overrides" do
      host_data = Sanford::HostData.new(TestHost, :verbose_logging => nil)
      assert_not_nil host_data.verbose
    end

    should "have called the setup proc" do
      assert_equal true, TestHost.init_has_been_called
    end

    should "constantize a host's handlers" do
      handlers = subject.instance_variable_get("@handlers")
      assert_equal TestHost::Authorized,  handlers['authorized']
      assert_equal TestHost::Bad,         handlers['bad']
      assert_equal TestHost::Echo,        handlers['echo']
      assert_equal TestHost::HaltIt,      handlers['halt_it']
      assert_equal TestHost::Multiply,    handlers['multiply']
    end

    should "look up handler classes with #handler_class_for" do
      assert_equal TestHost::Echo, subject.handler_class_for('echo')
    end

    should "raise a custom error when handler_class_for is called with an unknown service" do
      assert_raises(Sanford::NotFoundError) do
        subject.handler_class_for('not_defined')
      end
    end

    should "raise a custom error when a service is configured with an undefined class" do
      assert_raises(Sanford::NoHandlerClassError) do
        Sanford::HostData.new(UndefinedHandlersHost).setup
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sanford-0.8.0 test/unit/host_data_tests.rb