Sha256: ce787e47509c500702768dc73a2ee9961e68c8a053b88a9ffdf9b389dfcca8dc

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

dir = File.expand_path(File.dirname(__FILE__))
require "#{dir}/helper"

describe "Application and Instance scopes" do  
  before :each do
    Micon.clear
    Micon.clear_registry
  end
  
  it "instance scope" do    
    Micon.register(:value, :instance){"The Object"}
    
    Micon[:value].should == "The Object"
    Micon[:value].object_id.should_not == Micon[:value].object_id
  end
  
  it "application scope" do
    Micon.register(:value, :application){"The Object"}
    
    Micon[:value].should == "The Object"
    Micon[:value].object_id.should == Micon[:value].object_id
  end

  it "application scope, outjection" do
    the_object = "The Object"
    Micon.register :value, :application
    
    Micon[:value].should be_nil
    Micon[:value] = the_object
    Micon[:value].object_id.should == the_object.object_id
  end
  
  it "cycle reference" do
    class CycleB; end
  
    class CycleA
      inherit Micon::Managed
      scope :application
      inject :b => CycleB
    end
  
    class CycleB
      inherit Micon::Managed
      scope :application
      inject :a => CycleA
    end
    
    a = Micon[CycleA]
    b = Micon[CycleB]
    a.b.equal?(b).should be_true
    b.a.equal?(a).should be_true
  end        
    
  it "unregister" do      
    Micon.register(:value, :application){"The Object"}
    Micon[:value].should == "The Object"
    
    Micon.unregister :value
    lambda{Micon[:value]}.should raise_error(/Name is not Managed/)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-ext-0.4.2 spec/micon/static_scope_spec.rb