Sha256: 05e34585594e7e7fc1ae3c6a35a90761652d5d470d785386803a90a9eee01fd5
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true RSpec.describe FiniteMachine, ':auto_methods' do it "allows turning off automatic methods generation" do fsm = FiniteMachine.new(auto_methods: false) do initial :green event :slow, :green => :yellow event :stop, :yellow => :red event :ready, :red => :yellow event :go, :yellow => :green # allows for fluid callback names once_on_enter_yellow do |event| 'once_on_enter_yellow' end end expect(fsm.respond_to?(:slow)).to eq(false) expect { fsm.slow }.to raise_error(NoMethodError) expect(fsm.current).to eq(:green) fsm.trigger(:slow) expect(fsm.current).to eq(:yellow) end it "allows to use any method name without auto method generation" do fsm = FiniteMachine.new(auto_methods: false) do initial :green event :fail, :green => :red end fsm.trigger(:fail) expect(fsm.current).to eq(:red) end it "detects dangerous event names" do expect { FiniteMachine.new do event :trigger, :a => :b end }.to raise_error(FiniteMachine::AlreadyDefinedError) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
finite_machine-0.12.1 | spec/unit/auto_methods_spec.rb |
finite_machine-0.12.0 | spec/unit/auto_methods_spec.rb |