Sha256: 568f8b2043d2964890e9f831f233999922583fd7f31c5f32abe91207b72f147f

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

class Noodle
  
  attr_accessor :shape, :cooked
  
  def initialize
    @shape = "farfalla"
    @cooked = false
  end
  
  def cook
    @cooked = true
  end
  
  def transform(shape)
    @shape = shape
  end
  
end

context "Action Invokation" do

  setup do
    @noodle = Noodle.new
  end
  
  specify "Proc actions" do
    sm = Statemachine.build do |smb|
      smb.trans :cold, :fire, :hot, Proc.new { @cooked = true } 
    end
    
    sm.context = @noodle
    sm.fire
    
    @noodle.cooked.should_be true
  end
  
  specify "Symbol actions" do
    sm = Statemachine.build do |smb|
      smb.trans :cold, :fire, :hot, :cook
      smb.trans :hot, :mold, :changed, :transform
    end
  
    sm.context = @noodle
    sm.fire
  
    @noodle.cooked.should_be true
    
    sm.mold "capellini"
    
    @noodle.shape.should_eql "capellini"
  end

  specify "String actions" do
    sm = Statemachine.build do |smb|
      smb.trans :cold, :fire, :hot, "@shape = 'fettucini'; @cooked = true"
    end
    sm.context = @noodle
    
    sm.fire
    @noodle.shape.should_eql "fettucini"
    @noodle.cooked.should_be true
  end

  
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
statemachine-0.2.0 spec/action_invokation_spec.rb
statemachine-0.3.0 spec/action_invokation_spec.rb