Sha256: 011b4c0632da314f9508984630bd50aec27643d2ace32999cd2784d05363c094

Contents?: true

Size: 834 Bytes

Versions: 2

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal

RSpec.describe FiniteMachine, '#inspect' do
  it "print useful information about state machine" do
    fsm = FiniteMachine.new do
      initial :green

      event :slow,  :green  => :yellow
      event :stop,  :yellow => :red
    end
    inspected = fsm.inspect
    expect(inspected).to match(/^<#FiniteMachine::StateMachine:0x#{fsm.object_id.to_s(16)} @states=\[.*\], @events=\[.*\], @transitions=\[.*\]>$/)

    event_names = eval inspected[/events=\[(.*?)\]/]
    states = eval inspected[/states=\[(.*?)\]/]
    transitions = eval inspected[/transitions=\[(.*?)\]/]

    expect(event_names).to match_array([:init, :slow, :stop])
    expect(states).to match_array([:none, :green, :yellow, :red])
    expect(transitions).to match_array([{:none => :green}, {:green => :yellow}, {:yellow => :red}])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finite_machine-0.12.1 spec/unit/inspect_spec.rb
finite_machine-0.12.0 spec/unit/inspect_spec.rb