Sha256: 12b48cf205688bf5e4fbf75557c324ef4e5bc65338ca5918791430dc0ef9a31a

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe Finite::StateMachine do
  before(:each) do
    @elevator = Elevator.new
    @machine = Finite::StateMachine.machines[Elevator]
  end

  context 'adding events' do
    it 'has events' do
      expect(@machine.events.count).to be(10)
    end

    it 'cannot have events with the same name' do
      expect{@machine.add_event(:prepare){}}.to raise_error
    end

    it 'cannot be stupid with your event naming' do
      expect{@machine.add_event(:to_s)}.to raise_error
    end

    it 'increases in size when an event is added' do
      @machine.add_event(:random_event){}
      expect(@machine.events.count).to be(11)
    end
    it 'adds the proper helper methods' do
      expect(@elevator.methods).to include(:random_event)
      expect(@elevator.methods).to include(:can_random_event?)
    end
  end

  context 'adding states' do
    it 'has states' do
      expect(@machine.states.count).to be(9)
    end

    it 'cannot be stupid with your state naming' do
      expect{@machine.add_state(:const_defined){}}.to raise_error
    end

    it 'cannot have states with the same name' do
      @machine.add_state(:doors_closing){}
      expect(@machine.states.count).to be(9)
    end

    it 'increases in size when a state is added' do
      @machine.add_state(:random_state){}
      expect(@machine.states.count).to be(10)
    end

    it 'adds the proper helper method' do
      expect(@elevator.methods).to include(:random_state?)
    end
  end

  context 'callbacks' do
    it 'has after and before keys' do
      expect(@machine.callbacks).to include(:before)
      expect(@machine.callbacks).to include(:after)
    end

    it 'adds callbacks' do
      expect(@machine.callbacks[:before]).to include(:doors_closing)
      expect(@machine.callbacks[:before]).to include(:doors_opening)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finite-1.1.0 spec/machine_spec.rb
finite-1.0.0 spec/machine_spec.rb