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