Sha256: 81a4350a92ab2e2ba1466c36b9bbe84a34177ba9744bea712bb8572c0add75f6

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'assert'

module Sanford::Host

  class BaseTests < Assert::Context
    desc "Sanford::Host"
    setup do
      @configuration = MyHost.configuration.to_hash
    end
    teardown do
      MyHost.configuration.apply(@configuration)
    end
    subject{ MyHost.instance }

    should have_instance_methods :configuration, :name, :ip, :port, :pid_file,
      :logger, :verbose_logging, :runner, :error, :init, :service_handler_ns,
      :service, :services

    should "get and set it's configuration options with their matching methods" do
      subject.name 'my_awesome_host'

      assert_equal 'my_awesome_host',           subject.name
      assert_equal subject.configuration.port,  subject.port
    end

    should "allow adding a service with #service" do
      subject.service_handler_ns 'MyNamespace'
      subject.service('test', 'MyServiceHandler')

      assert_equal 'MyNamespace::MyServiceHandler', subject.services['test']
    end

    should "ignore a namespace when a service class has leading colons" do
      subject.service_handler_ns 'MyNamespace'
      subject.service('test', '::MyServiceHandler')

      assert_equal '::MyServiceHandler', subject.services['test']
    end

  end

  class ClassMethodsTests < Assert::Context
    desc "Sanford::Host class"
    subject{ MyHost }

    should "proxy it's method to it's instance" do
      assert_equal subject.instance.name, subject.name
      assert subject.respond_to?(:pid_file)
    end

    should "have registered the class with sanford's known hosts" do
      assert_includes subject, Sanford.hosts
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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