Sha256: e57302bfc69482e0d8a9b74946eb8cfc96e975e897353a06f955ec25b97cb3d5

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

RSpec.describe FiniteMachine::Transition, '#states' do
  let(:machine) { double(:machine) }

  it "groups states with :to key only" do
    attrs = {states: {:any => :red}}
    transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
    expect(transition.states).to eql({any: :red})
  end

  it "groups states when from array" do
    attrs = {states: { :green => :red, :yellow => :red}}
    transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
    expect(transition.states.keys).to match_array([:green, :yellow])
    expect(transition.states.values).to eql([:red, :red])
  end


  it "groups states when hash of states" do
    attrs = {states: {
              :initial => :low,
              :low     => :medium,
              :medium  => :high }}
    transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
    expect(transition.states.keys).to match_array([:initial, :low, :medium])
    expect(transition.states.values).to eql([:low, :medium, :high])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finite_machine-0.12.1 spec/unit/transition/states_spec.rb
finite_machine-0.12.0 spec/unit/transition/states_spec.rb