Sha256: a067967b7154138f2c90c066e87067c0dd09b3e7e1df8991df28dbf2b41e0652

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8

require 'spec_helper'

RSpec.describe FiniteMachine::StateParser, '#parse' do
  let(:object) { described_class }

  subject(:parser) { object.new(attrs) }

  context 'when no attributes' do
    let(:attrs) { { } }

    it "raises error for no transitions" do
      expect {
        parser.parse
      }.to raise_error(FiniteMachine::NotEnoughTransitionsError)
    end
  end

  context 'when :from and :to keys' do
    let(:attrs) { { from: :green, to: :yellow }}

    it "removes :from and :to keys" do
      expect(parser.parse).to eq({green: :yellow})
    end
  end

  context 'when only :from key' do
    let(:attrs) { { from: :green }}

    it "adds to state as copy of from" do
      expect(parser.parse).to eq({green: :green})
    end
  end

  context 'when only :to key' do
    let(:attrs) { { to: :green }}

    it "inserts :any from state" do
      expect(parser.parse).to eq({any: :green})
    end
  end

  context 'when attribuets as hash' do
    let(:attrs) { { green: :yellow } }

    it "copies attributes over" do
      expect(parser.parse).to eq({green: :yellow})
    end
  end

  context 'when array of from states' do
    let(:attrs) { { [:green, :red] => :yellow } }

    it "extracts states" do
      expect(parser.parse).to include({red: :yellow, green: :yellow})
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
finite_machine-0.11.3 spec/unit/state_parser/parse_spec.rb
finite_machine-0.11.2 spec/unit/state_parser/parse_spec.rb
finite_machine-0.11.1 spec/unit/state_parser/parse_spec.rb
finite_machine-0.11.0 spec/unit/state_parser/parse_spec.rb
finite_machine-0.10.2 spec/unit/state_parser/parse_spec.rb