Sha256: b2be4214fa5772afc551b7465a0a277bfbeb5947127ee86cffd5873f813ab08f

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

require "spec_helper"

module Test
  module DependencyMap
    class Weapon; end
    class Armor; end
  end
end

describe Scorpion::DependencyMap do
  let( :scorpion ) { double Scorpion }
  let( :map ) { Scorpion::DependencyMap.new scorpion }

  describe "#chart" do
    it "yields itself when arg expected" do
      map.chart do |itself|
        expect( map ).to be itself
      end
    end
  end

  describe "#find" do
    it "returns a match" do
      map.chart do
        hunt_for Test::DependencyMap::Weapon
        hunt_for Test::DependencyMap::Armor
      end

      expect( map.find( Test::DependencyMap::Armor ).contract ).to eq Test::DependencyMap::Armor
    end

    it "returns nil when no match" do
      map.chart do
        hunt_for Test::DependencyMap::Weapon
      end

      expect( map.find( Test::DependencyMap::Armor ) ).to be_nil
    end

    it "returns nil when no match" do
      map.chart do
        hunt_for Test::DependencyMap::Weapon
      end

      expect( map.find( Test::DependencyMap::Armor ) ).to be_nil
    end

  end

  describe "#hunt_for" do
    it "adds a Dependency" do
      expect( map ).to be_empty

      map.chart do
        hunt_for Test::DependencyMap::Weapon
      end

      expect( map.first ).to be_a Scorpion::Dependency
    end
  end

  describe "#replicate_from" do
    it "does not dup shared dependency" do
      # Instead of duping shared dependencies, the scorpion should delegate to
      # its parent which shares the same instance with all of its children.
      map.chart do
        share do
          capture Test::DependencyMap::Weapon
        end
      end

      replica = Scorpion::DependencyMap.new scorpion
      replica.replicate_from( map )

      expect( replica ).to be_empty
    end

    it "dups captured dependency" do
      map.chart do
        capture Test::DependencyMap::Weapon
      end

      replica = Scorpion::DependencyMap.new scorpion
      replica.replicate_from( map )

      expect( replica ).not_to be_empty
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.10 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.8 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.7 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.6 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.4 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.3 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.2 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.1 spec/lib/scorpion/dependency_map_spec.rb
scorpion-ioc-1.0.0 spec/lib/scorpion/dependency_map_spec.rb