Sha256: 2d9c5fd94cc4275d1ccdfc61765aa044877f58f29b72add9c42b2224398a09ab

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

require 'assert'
require 'sanford/router'

require 'test/support/factory'

class Sanford::Router

  class UnitTests < Assert::Context
    desc "Sanford::Host"
    setup do
      @router = Sanford::Router.new
    end
    subject{ @router }

    should have_readers :routes
    should have_imeths :service_handler_ns, :service

    should "build an empty array for its routes by default" do
      assert_equal [], subject.routes
    end

    should "not have a service handler ns by default" do
      assert_nil subject.service_handler_ns
    end

    should "allow setting its service handler ns" do
      namespace = Factory.string
      subject.service_handler_ns namespace
      assert_equal namespace, subject.service_handler_ns
    end

    should "allow adding routes using `service`" do
      service_name = Factory.string
      handler_name = Factory.string
      subject.service service_name, handler_name

      route = subject.routes.last
      assert_instance_of Sanford::Route, route
      assert_equal service_name, route.name
      assert_equal handler_name, route.handler_class_name
    end

    should "use its service handler ns when adding routes" do
      namespace = Factory.string
      subject.service_handler_ns namespace

      service_name = Factory.string
      handler_name = Factory.string
      subject.service service_name, handler_name

      route = subject.routes.last
      expected = "#{namespace}::#{handler_name}"
      assert_equal expected, route.handler_class_name
    end

    should "know its custom inspect" do
      reference = '0x0%x' % (subject.object_id << 1)
      expected = "#<#{subject.class}:#{reference} " \
                   "@service_handler_ns=#{subject.service_handler_ns.inspect}>"
      assert_equal expected, subject.inspect
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sanford-0.13.0 test/unit/router_tests.rb
sanford-0.12.0 test/unit/router_tests.rb
sanford-0.11.1 test/unit/router_tests.rb
sanford-0.11.0 test/unit/router_tests.rb