Sha256: 35bb0e5e8d24202da27de0471c2730c06e4e9278a0fe1e635f7d47015f3dccfc

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

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

describe "Micon custom scope" do
  before :each do
    Micon.clear
    Micon.clear_registry
  end
  
  it "activate" do
    container = {}    
    Micon.should_not be_active(:custom)
    Micon.activate :custom, container
    Micon.should be_active(:custom)

    lambda{Micon.activate :custom, container}.should raise_error(/active/)

    Micon.deactivate :custom
    lambda{Micon.deactivate :custom}.should raise_error(/not active/)
    
    Micon.should_not be_active(:custom)
    Micon.activate :custom, container do
      Micon.should be_active(:custom)
    end
  end
  
  it "check" do
    Micon.register(:value, :custom){"The Object"}
    lambda{Micon[:value]}.should raise_error(/not started/)
    lambda{Micon[:value] = nil}.should raise_error(/not started/)
  end
  
  it "get" do
    Micon.register(:value, :custom){"The Object"}
    container, the_object = {}, nil
    
    Micon.activate :custom, container do
      Micon[:value].should == "The Object"
      the_object = Micon[:value]
    end
    
    Micon.activate :custom, {} do
      Micon[:value].object_id.should_not == the_object.object_id
    end
    
    Micon.activate :custom, container do
      Micon[:value].object_id.should == the_object.object_id
    end
    
    container.size.should == 1
    container[:value].should == the_object
  end
  
  it "set" do
    Micon.register(:value, :custom){"The Object"}
    container = {}
    
    Micon.activate :custom, container do
      Micon[:value].should == "The Object"
      Micon[:value] = "Another Object"
      the_object = Micon[:value]
    end
    
    Micon.activate :custom, {} do
      Micon[:value].should == "The Object"
    end
    
    Micon.activate :custom, container do
      Micon[:value].should == "Another Object"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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