spec/unit/inspect_spec.rb in finite_machine-0.11.3 vs spec/unit/inspect_spec.rb in finite_machine-0.12.0

- old
+ new

@@ -1,17 +1,22 @@ -# encoding: utf-8 +# frozen_string_literal -require 'spec_helper' - RSpec.describe FiniteMachine, '#inspect' do it "print useful information about state machine" do - fsm = FiniteMachine.define do + fsm = FiniteMachine.new do initial :green - events { - event :slow, :green => :yellow - event :stop, :yellow => :red - } + event :slow, :green => :yellow + event :stop, :yellow => :red end - expect(fsm.inspect).to match(/^<#FiniteMachine::StateMachine:0x#{fsm.object_id.to_s(16)} @states=\[:none, :green, :yellow, :red\], @events=\[:init, :slow, :stop\], @transitions=\[{:none=>:green}, {:green=>:yellow}, {:yellow=>:red}\]>$/) + 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