Sha256: 1fdb88b33e6a833f6b86676a4f8d117c8c287ea8a5ce7725872768adccba17e0

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'spec'
require 'statemachine'

def check_transition(transition, origin_id, destination_id, event, action)
  transition.should_not equal(nil)
  transition.event.should equal(event)
  transition.origin_id.should equal(origin_id)
  transition.destination_id.should equal(destination_id)
  transition.action.should eql(action)
end

module SwitchStatemachine
  
  def create_switch
    @status = "off"
    @sm = Statemachine.build do
      trans :off, :toggle, :on, Proc.new { @status = "on" } 
      trans :on, :toggle, :off, Proc.new { @status = "off" }
    end
    @sm.context = self
  end
  
end

module TurnstileStatemachine
  
  def create_turnstile
    @locked = true
    @alarm_status = false
    @thankyou_status = false
    @lock = "@locked = true"
    @unlock = "@locked = false"
    @alarm = "@alarm_status = true"
    @thankyou = "@thankyou_status = true"
  
    @sm = Statemachine.build do
      trans :locked, :coin, :unlocked, "@locked = false"
      trans :unlocked, :pass, :locked, "@locked = true"
      trans :locked, :pass, :locked, "@alarm_status = true"
      trans :unlocked, :coin, :locked, "@thankyou_status = true"
    end
    @sm.context = self
  end

end

TEST_DIR = File.expand_path(File.dirname(__FILE__) + "/../test_dir/")

def test_dir(name = nil)
  Dir.mkdir(TEST_DIR) if !File.exist?(TEST_DIR)
  return TEST_DIR if name.nil?
  dir = File.join(TEST_DIR, name)
  Dir.mkdir(dir) if !File.exist?(dir)
  return dir
end

def remove_test_dir(name)
  system "rm -rf #{test_dir(name)}" if File.exist?(test_dir(name))
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statemachine-1.0.0 spec/spec_helper.rb
statemachine-0.5.1 spec/spec_helper.rb
statemachine-0.5.0 spec/spec_helper.rb