Sha256: 98f2bacc554776d94135ca8fa6f44a4fe16c53937a11ede3b84d420cfe2f3e7c

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe FiniteMachine::Transition, 'parsed_states' do
  let(:machine) { double(:machine) }

  subject(:transition) { described_class.new(machine, attrs) }

  context 'with :to key only' do
    let(:attrs) { { parsed_states: { any: :red } } }

    it "groups states" do
      expect(transition.from_states).to eq([:any])
      expect(transition.to_states).to eq([:red])
      expect(transition.map).to eql({any: :red})
    end
  end

  context 'when from array' do
    let(:attrs) { {parsed_states: { :green => :red, :yellow => :red} } }

    it "groups states" do
      expect(transition.from_states).to match_array([:green, :yellow])
      expect(transition.to_states).to eql([:red, :red])
    end
  end

  context 'when hash of states' do
    let(:attrs) {
      { parsed_states:
        { :initial => :low,
          :low     => :medium,
          :medium  => :high } }
     }

    it "groups states" do
      expect(transition.from_states).to match_array([:initial, :low, :medium])
      expect(transition.to_states).to eql([:low, :medium, :high])
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
finite_machine-0.10.0 spec/unit/transition/parse_states_spec.rb
finite_machine-0.9.2 spec/unit/transition/parse_states_spec.rb
finite_machine-0.9.1 spec/unit/transition/parse_states_spec.rb
finite_machine-0.9.0 spec/unit/transition/parse_states_spec.rb
finite_machine-0.8.1 spec/unit/transition/parse_states_spec.rb
finite_machine-0.8.0 spec/unit/transition/parse_states_spec.rb
finite_machine-0.7.1 spec/unit/transition/parse_states_spec.rb
finite_machine-0.7.0 spec/unit/transition/parse_states_spec.rb