Sha256: ac78dd9ac93710c38a5c64e317ac328911f8f33a63b7254b5dea46e9da74901a

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 KB

Contents

require "#{File.dirname(__FILE__)}/../screw_unit_spec_helper"

module ScrewUnit
  describe Dispatcher do
    attr_reader :dispatcher, :locator_1, :locator_2
    before do
      @locator_1 = Object.new
      @locator_2 = Object.new
      @dispatcher = Dispatcher.new(configuration)
    end

    describe "#locate_resource(path)" do
      context "when there are #resource_locators" do
        def configuration
          return @configuration if @configuration
          @configuration = Configuration.new
          @configuration.add_resource_locator(locator_1)
          @configuration.add_resource_locator(locator_2)
          @configuration
        end

        context "when one of the custom locators returns a resource" do
          attr_reader :resource
          before do
            @resource = Object.new
            mock(locator_2).locate_resource("/foo").ordered { nil }
            mock(locator_1).locate_resource("/foo").ordered { resource }
          end

          it "returns that resource" do
            dispatcher.locate_resource("/foo").should == resource
          end
        end

        context "when no custom locators return a resource" do
          before do
            mock(locator_2).locate_resource("/foo").ordered { nil }
            mock(locator_1).locate_resource("/foo").ordered { nil }
          end

          it "performs the normal dispatch starting at Resources::Root" do
            mock.instance_of(Resources::Root).locate("foo")
            dispatcher.locate_resource("/foo")
          end
        end
      end

      context "when there are no #resource_locators" do
        def configuration
          @configuration ||= Configuration.new
        end

        it "performs the normal dispatch starting at Resources::Root" do
          mock.instance_of(Resources::Root).locate("foo")
          dispatcher.locate_resource("/foo")
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
coolerator.vision-0.2.10 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.9 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.8 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.7 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.6 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.5 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.4 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.3 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.2 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.1 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb
coolerator.vision-0.2.0 spec/support/vendor/screw-unit/spec/screw_unit/dispatcher_spec.rb