<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,32 +1,40 @@
 require File.dirname(__FILE__) + &quot;/../lib/contextr&quot;
 
+module EasyInitializerMixin
+  def initialize(options = {})
+    options.each do |key, value| 
+      self.send(&quot;#{key}=&quot;, value)
+    end
+  end
+end
+
 class Employer  
   attr_accessor :name
+  include EasyInitializerMixin
 end
 class Person  
-  attr_accessor :name  
-  attr_accessor :employer
+  attr_accessor :name, :employer
+  include EasyInitializerMixin
 end
 
 
 class Employer  
-  def display    
-    puts &quot;Employer&quot;    
-    puts &quot;Name: %s&quot; % self.name  
+  def to_s    
+    &quot;Employer\n&quot; +    
+    &quot;Name: %s&quot; % self.name  
   end
 end
 class Person  
-  def display    
-    puts &quot;Person&quot;    
-    puts &quot;Name: %s&quot; % self.name  
+  def to_s    
+    &quot;Person\n&quot; +    
+    &quot;Name: %s&quot; % self.name  
   end
 end
 
 class Person  
   in_layer :employment do
-    def display      
-      super      
-      yield(:receiver).employer.display    
+    def to_s      
+      super + &quot;\n%s&quot; % yield(:receiver).employer
     end  
   end
 end
@@ -34,18 +42,18 @@ end
 class Employer  
   attr_accessor :address  
   in_layer :detailed_info do   
-    def display      
-      super      
-      puts &quot;Address: %s&quot; % yield(:receiver).address     
+    def to_s      
+      super + &quot;\n&quot; + 
+      &quot;Address: %s&quot; % yield(:receiver).address     
     end  
   end
 end
 class Person  
   attr_accessor :address  
   in_layer :detailed_info do   
-    def display      
-      super      
-      puts &quot;Address: %s&quot; % yield(:receiver).address     
+    def to_s      
+      super + &quot;\n&quot; + 
+      &quot;Address: %s&quot; % yield(:receiver).address     
     end  
   end
 end
@@ -58,28 +66,164 @@ pascal.name = &quot;Pascal&quot;
 pascal.employer = vub
 pascal.address = &quot;Brussels&quot;
 
-vub.display
+puts vub
 puts
-pascal.display
+puts pascal
 puts &quot; - - - - - - - - &quot;
 
 ContextR::with_layer :employment do
-  vub.display
+  puts vub
   puts
-  pascal.display
+  puts pascal
   puts &quot; - - - - - - - - &quot;
 end
 
 ContextR::with_layer :detailed_info do
-  vub.display
+  puts vub
   puts
-  pascal.display
+  puts pascal
   puts &quot; - - - - - - - - &quot;
 
   ContextR::with_layer :employment do
-    vub.display
+    puts vub
     puts
-    pascal.display
+    puts pascal
     puts &quot; - - - - - - - - &quot;
   end
 end
+
+describe ContextR do
+  it &quot;should show all currently active layers&quot; do
+    ContextR::with_layer :employment do
+      ContextR::active_layers.should == [:employment]
+
+      ContextR::with_layer :detailed_info do
+        ContextR::active_layers.should == 
+                        [:detailed_info, :employment]
+      end
+  
+      ContextR::active_layers.should == [:employment]
+    end
+  end
+
+  it &quot;should show all layers ever used&quot; do
+    ContextR::layers.should == [:employment, :detailed_info]
+  end
+end
+
+describe ContextR do
+  it &quot;should list all extended methods&quot; do
+    Person.in_layer(:employment).instance_methods.should == [&quot;to_s&quot;]
+    Employer.in_layer(:employment).instance_methods.should be_empty
+  end
+end
+
+
+describe ContextR do
+  it &quot;should execute later layers first, earlier layers later&quot; do
+    ContextR::with_layer :detailed_info do
+      ContextR::with_layer :employment do
+
+        ContextR::active_layers.should ==
+                                    [:employment, :detailed_info]
+      end
+    end
+
+    ContextR::with_layer :detailed_info, :employment do
+
+      ContextR::active_layers.should ==
+                                    [:employment, :detailed_info]
+    end
+  end
+end
+
+describe ContextR do          
+  it &quot;should hide deactivated layers&quot; do
+    ContextR::with_layer :detailed_info, :employment do
+                              
+      ContextR::active_layers.should ==
+                                    [:employment, :detailed_info]
+                              
+      ContextR::without_layer :employment do
+        ContextR::active_layers.should == [:detailed_info]
+      end                     
+                              
+      ContextR::without_layer :detailed_info do
+        ContextR::active_layers.should == [:employment]
+      end
+    end
+  end
+end
+
+describe ContextR do
+  it &quot;should update order at repetitive activation&quot; do
+    ContextR::with_layer :detailed_info, :employment do
+                           
+      ContextR::active_layers.should == [:employment, :detailed_info]
+                           
+      ContextR::with_layer :detailed_info do
+        ContextR::active_layers.should == [:detailed_info, :employment]
+      end                  
+                           
+      ContextR::with_layer :employment do
+        ContextR::active_layers.should == [:employment, :detailed_info]
+      end
+    end                               
+  end 
+end 
+
+describe ContextR do
+  it &quot;should activate layer, even when they were explicitly deactivated&quot; do
+    ContextR::with_layer :detailed_info, :employment do
+      ContextR::without_layer :employment do
+        ContextR::with_layer :employment do
+          ContextR::active_layers.should == [:employment, :detailed_info]
+        end
+      end
+    end
+  end
+end 
+
+describe ContextR do
+  def step(index, *layers)
+    @step += 1
+    @step.should == index
+    ContextR::active_layers.should == layers
+  end
+
+  def task_one
+    @mutex.lock
+    ContextR::with_layer :employment do
+      step(2, :employment, :detailed_info)
+      @mutex.unlock
+      sleep(0.1)
+      @mutex.lock
+      step(4, :employment, :detailed_info)
+    end
+    @mutex.unlock
+  end
+  
+  def task_two
+    @mutex.lock
+    step(3, :detailed_info)
+    @mutex.unlock
+  end
+
+  before do
+    @mutex = Mutex.new
+    @step = 0
+  end
+  
+  it &quot;should consider dynamic scope&quot; do
+    ContextR::with_layer :detailed_info do
+      step(1, :detailed_info)
+    
+      one = Thread.new { task_one }
+      two = Thread.new { task_two }
+      
+      one.join
+      two.join
+      step(5, :detailed_info)
+    end
+  end
+end</diff>
      <filename>examples/employer.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>60bb7acca4d786a81d36d93ebdf9b5e9f7d763a3</id>
    </parent>
  </parents>
  <author>
    <name>Gregor Schmidt</name>
    <email>ruby@schmidtwisser.de</email>
  </author>
  <url>http://github.com/schmidt/contextr/commit/9615e57b4c27f8a79eabd210dc25ab1871f77009</url>
  <id>9615e57b4c27f8a79eabd210dc25ab1871f77009</id>
  <committed-date>2008-01-17T09:21:09-08:00</committed-date>
  <authored-date>2008-01-17T09:21:09-08:00</authored-date>
  <message>More details in employer example - due to changes in the thesis</message>
  <tree>b33240014aba5112e1a0f1eccc5bc02c602d4604</tree>
  <committer>
    <name>Gregor Schmidt</name>
    <email>ruby@schmidtwisser.de</email>
  </committer>
</commit>
