Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
  • Loading branch information
nulldef committed Dec 3, 2017
1 parent 7eebe71 commit adc3501
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/statum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module Statum
UnknownEventError = Class.new(ArgumentError)
ErrorTransitionError = Class.new(StandardError)
ExistingMachineError = Class.new(ArgumentError)

This comment has been minimized.

Copy link
@JelF

JelF Dec 3, 2017

Avoid inheriting ArgumentError in case it not raised during arguments list normalization

Also, it is a good idea to make a superclass for all Statum errors, but it is not really required


STATE_MACHINES_VARIABLE = '@__statum_machines'.freeze

Expand All @@ -31,7 +32,7 @@ def state_machines

def add_machine(machine)
if state_machines.any? { |m| m.name == machine.name }
raise "State machine for #{machine.name} already exists"
raise ExistingMachineError, "State machine for #{machine.name} already exists"
end
instance_variable_set(STATE_MACHINES_VARIABLE, state_machines + [machine])
end
Expand Down
16 changes: 16 additions & 0 deletions spec/multimachine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ class MultiCar
end
end

class ExistsCar
include Statum

attr_accessor :state, :engine

statum :state do
state :riding
state :idle
end
end

RSpec.describe "Statum multimachine" do
let(:car) { MultiCar.new }

Expand All @@ -40,4 +51,9 @@ class MultiCar
expect(car.state).to eq(:riding)
expect(car.engine).to eq(:started)
end

it "raises error when defining exists machine" do
expect { ExistsCar.instance_eval { statum :state } }
.to raise_error(Statum::ExistingMachineError)
end
end

0 comments on commit adc3501

Please sign in to comment.