Sha256: 51b820f3d4b3c0251a24bfbdc835b2594e343bc4e5643e13f7c6b1ef2186c3a8

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

RSpec.describe FiniteMachine, '#is?' do

  it "allows to check if state is reachable" do
    fsm = FiniteMachine.new do
      initial :green

      event :slow,  :green  => :yellow
      event :stop,  :yellow => :red
      event :ready, :red    => :yellow
      event :go,    :yellow => :green
    end

    expect(fsm.current).to eql(:green)

    expect(fsm.is?(:green)).to be true
    expect(fsm.is?(:yellow)).to be false
    expect(fsm.is?([:green,  :red])).to be true
    expect(fsm.is?([:yellow, :red])).to be false

    fsm.slow

    expect(fsm.is?(:green)).to be false
    expect(fsm.is?(:yellow)).to be true
    expect(fsm.is?([:green, :red])).to be false
    expect(fsm.is?([:yellow, :red])).to be true
  end

  it "defines helper methods to check current state" do
    fsm = FiniteMachine.new do
      initial :green

      event :slow,  :green  => :yellow
      event :stop,  :yellow => :red
      event :ready, :red    => :yellow
      event :go,    :yellow => :green
    end
    expect(fsm.current).to eql(:green)

    expect(fsm.green?).to be true
    expect(fsm.yellow?).to be false

    fsm.slow

    expect(fsm.green?).to be false
    expect(fsm.yellow?).to be true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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