From b8918956171eb03adb317bb6bb7961d6fa68c381 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Tue, 15 Mar 2016 22:54:35 +0300 Subject: [PATCH] Eager error message --- lib/aasm/errors.rb | 8 ++++---- spec/unit/exception_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 spec/unit/exception_spec.rb diff --git a/lib/aasm/errors.rb b/lib/aasm/errors.rb index d9b5792..f4ba67c 100644 --- a/lib/aasm/errors.rb +++ b/lib/aasm/errors.rb @@ -3,18 +3,18 @@ module AASM class UnknownStateMachineError < RuntimeError; end class InvalidTransition < RuntimeError - attr_reader :object, :event_name, :state_machine_name, :failures + attr_reader :object, :event_name, :originating_state, :failures def initialize(object, event_name, state_machine_name, failures = []) - @object, @event_name, @state_machine_name, @failures = object, event_name, state_machine_name, failures + @object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures end def message - "Event '#{event_name}' cannot transition from '#{object.aasm(state_machine_name).current_state}'. #{reasoning}" + "Event '#{event_name}' cannot transition from '#{originating_state}'. #{reasoning}" end def reasoning - "Failed callback(s): #{@failures}." unless failures.empty? + "Failed callback(s): #{failures}." unless failures.empty? end end diff --git a/spec/unit/exception_spec.rb b/spec/unit/exception_spec.rb new file mode 100644 index 0000000..5c04d18 --- /dev/null +++ b/spec/unit/exception_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe AASM::InvalidTransition do + it 'should not be lazy detecting originating state' do + process = ProcessWithNewDsl.new + expect { process.stop! }.to raise_error do |err| + process.start + expect(err.message).to eql("Event 'stop' cannot transition from 'sleeping'. ") + end + end +end