Sha256: 4183f83c15aeee3c371767afc0e9d842005f0cd226129f6859615476c423cf2a

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

dir = File.expand_path(File.dirname(__FILE__))
require "#{dir}/../micon_spec_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

2 entries across 2 versions & 1 rubygems

Version Path
ruby-ext-0.4.1 spec/micon/static_scope_spec.rb
ruby-ext-0.4.0 spec/micon/static_scope_spec.rb