<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -56,7 +56,7 @@ module RedSteak
       # If some options are already set, merge them.
       if @options
         return @options if opts.empty?
-        @options.merge(_dup_opts opts)
+        @options.merge(_dup_opts(opts))
       else
         @options = _dup_opts opts
       end</diff>
      <filename>lib/red_steak/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -118,11 +118,14 @@ module RedSteak
 
     # Returns an array of all ancestor states.
     def ancestors
-      x = [ self ]
-      if ss = superstate
-        x.push(*ss.ancestors)
-      end
-      x
+      @ancestors ||=
+        begin
+          x = [ self ]
+          if ss = superstate
+            x.push(*ss.ancestors)
+          end
+          x
+        end
     end
 
 </diff>
      <filename>lib/red_steak/state.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,18 +19,23 @@ describe RedSteak do
     # For debugging.
     attr_accessor :logger
 
+    def initialize
+      clear!
+    end
+
     def clear!
       @_machine = 
         @_args =
         @_transition =
-        @_guard =
-        @_effect =
-        @_state =
-        @_enter =
-        @_exit =
-        @_doActivity =
         @_a_to_b =
         nil
+
+      @_guard = [ ]
+      @_effect = [ ]
+      @_state = [ ]
+      @_enter = [ ]
+      @_exit = [ ] 
+      @_doActivity = [ ]
     end
 
 
@@ -38,17 +43,15 @@ describe RedSteak do
     def guard(machine, trans, *args)
       @_machine = machine
       @_transition = trans
-      @_guard = @_args = args
+      @_guard &lt;&lt; (@_args = args)
       _log
       nil # Ok
     end
 
+    # Special Guard.
     def a_to_b?(machine, trans, *args)
-      @_machine = machine
-      @_transition = trans
-      @_guard = @_args = args
+      guard(machine, trans, *args)
       @_a_to_b = args
-      _log
       true
     end
 
@@ -56,7 +59,7 @@ describe RedSteak do
     def effect(machine, trans, *args)
       @_machine = machine
       @_transition = trans
-      @_effect = @_args = args
+      @_effect &lt;&lt; (@_args = args)
       _log
     end
 
@@ -64,7 +67,8 @@ describe RedSteak do
     def enter(machine, state, *args)
       @_machine = machine
       @_state = state
-      @_enter = @_args = args
+      @_args = args
+      @_enter &lt;&lt; [ state.to_s, *args ]
       _log
     end
 
@@ -72,7 +76,8 @@ describe RedSteak do
     def exit(machine, state, *args)
       @_machine = machine
       @_state = state
-      @_exit = @_args = args
+      @_args = args
+      @_exit &lt;&lt; [ state.to_s, *args ]
       _log
     end
 
@@ -80,7 +85,8 @@ describe RedSteak do
     def doActivity(machine, state, *args)
       @_machine = machine
       @_state = state
-      @_doActivity = @_args = args
+      @_args = args
+      @_doActivity &lt;&lt; [ state.to_s, *args ]
       _log
     end
 
@@ -296,11 +302,11 @@ describe RedSteak do
     c._machine.should == m
     c._state.should == m.stateMachine.states[:a]
     c._transition.should == nil
-    c._guard.should == nil
-    c._effect.should == nil
-    # c._enter.should == [ ]
-    c._exit.should == nil
-    c._doActivity.should == [ ]
+    c._guard.should == [ ]
+    c._effect.should == [ ]
+    c._enter.should == [ [ &quot;a&quot; ] ]
+    c._exit.should == [ ]
+    c._doActivity.should == [ [ &quot;a&quot; ] ]
     m.history.size.should == 1
 
     #################################
@@ -308,7 +314,7 @@ describe RedSteak do
     #
 
     c.clear!
-    m.transition! &quot;a_to_b&quot;, :arg
+    m.transition! &quot;a_to_b&quot;, :arg1
     m.at_start?.should == false
     m.at_end?.should == false
 
@@ -317,13 +323,13 @@ describe RedSteak do
 
     c._machine.should == m
     c._transition.name.should == :a_to_b
-    c._guard.should == [ :arg ]
-    c._a_to_b.should == [ :arg ]
-    c._effect.should == [ :arg ]
+    c._guard.should == [ [ :arg1 ] ]
+    c._a_to_b.should == [ :arg1 ]
+    c._effect.should == [ [ :arg1 ] ]
     c._state.name.should == :b
-    c._enter.should == [ :arg ]
-    c._exit.should == [ :arg ]
-    c._doActivity.should == [ :arg ]
+    c._enter.should == [ [ &quot;b&quot;, :arg1 ] ]
+    c._exit.should == [ [ &quot;a&quot;, :arg1 ] ]
+    c._doActivity.should == [ [ &quot;b&quot;, :arg1 ] ]
     m.history.size.should == 2
 
     #################################
@@ -504,8 +510,8 @@ describe RedSteak do
     m.state.name.should == :a
     c._machine.should == m
     c._state.name.should == :a
-    c._enter.should == [ :foo, :bar ]
-    c._exit.should == nil
+    c._enter.should == [ [ &quot;a&quot;, :foo, :bar ] ]
+    c._exit.should == [ ]
  
     render_graph m, :show_history =&gt; true
 
@@ -596,14 +602,34 @@ describe RedSteak do
     sm.state[:c].state.map{|s| s.to_s}.should == [ ]
     sm.state[:c].source.map{|s| s.to_s}.should == [&quot;a::a&quot;, &quot;a::b&quot;, &quot;a::c&quot;, &quot;b&quot;, &quot;b::a&quot;]
 
-    m = sm.machine
-    m.history = [ ]
+    m = machine_with_context(sm)
+    c = m.context
     m.logger = $stderr
+
+    c.clear!
     m.start!
+    c._exit.should == [ ]
+    c._enter.should == [ [ &quot;a&quot; ], [ &quot;a::a&quot; ] ]
+
+    c.clear!
     m.transition_to! &quot;b&quot;
+    c._exit.should == [[&quot;a::a&quot;], [&quot;a&quot;]]
+    c._enter.should == [ [ &quot;b&quot; ], [ &quot;b::a&quot; ] ]
+
+    c.clear!
     m.transition_to! &quot;b::b&quot;
+    c._exit.should == [[&quot;b::a&quot;]]
+    c._enter.should == [[&quot;b::b&quot;]]
+
+    c.clear!
     m.transition_to! &quot;a::b&quot;
+    c._exit.should == [[&quot;b::b&quot;], [&quot;b&quot;]]
+    c._enter.should == [[&quot;a&quot;], [&quot;a::b&quot;]] 
+
+    c.clear!
     m.transition_to! &quot;c&quot;
+    c._exit.should == [[&quot;a::b&quot;], [&quot;a&quot;]]
+    c._enter.should == [[&quot;c&quot;]]
 
     render_graph m, :show_history =&gt; true
 </diff>
      <filename>test/red_steak.spec</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e650828cfd442fe46480d0f4d9cc1fffbe37d1bc</id>
    </parent>
  </parents>
  <author>
    <name>Kurt Stephens</name>
    <email>ks.github@kurtstephens.com</email>
  </author>
  <url>http://github.com/kstephens/red_steak/commit/59bdbe3cf423936f5ffb6cf905422ceb9d4d585c</url>
  <id>59bdbe3cf423936f5ffb6cf905422ceb9d4d585c</id>
  <committed-date>2008-12-30T22:57:36-08:00</committed-date>
  <authored-date>2008-12-30T22:57:36-08:00</authored-date>
  <message>Better tests for superstate exit/enter behavior.</message>
  <tree>19bf8998d2e36c4adb7351a44e17addef6cc3d6e</tree>
  <committer>
    <name>Kurt Stephens</name>
    <email>ks.github@kurtstephens.com</email>
  </committer>
</commit>
