From 131d9f3253bae278eb13988507be9ae6cae4ae38 Mon Sep 17 00:00:00 2001 From: Zac Viandier Date: Sat, 16 Jan 2016 18:38:05 +0100 Subject: [PATCH 1/3] Add posibility to pass arguments to on_event rspec custom matcher function --- lib/aasm/rspec/transition_from.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/aasm/rspec/transition_from.rb b/lib/aasm/rspec/transition_from.rb index 44c2f169..dc29f160 100644 --- a/lib/aasm/rspec/transition_from.rb +++ b/lib/aasm/rspec/transition_from.rb @@ -2,8 +2,7 @@ match do |obj| @state_machine_name ||= :default obj.aasm(@state_machine_name).current_state = from_state.to_sym - # expect(obj).to receive(:broadcast_event).with(@event.to_s, obj, from_state, @to_state) - obj.send(@event) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym + obj.send(@event, *@args) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym end chain :on do |state_machine_name| @@ -14,12 +13,13 @@ @to_state = state end - chain :on_event do |event| + chain :on_event do |event, *args| @event = event + @args = args end description do - "transition state to :#{@to_state} from :#{expected} on event :#{@event} (on :#{@state_machine_name})" + "transition state to :#{@to_state} from :#{expected} on event :#{@event}, with params: #{@args} (on :#{@state_machine_name})" end failure_message do |obj| From 7c309c365c72bdcbeb2a96deb4908d5e55854baa Mon Sep 17 00:00:00 2001 From: Zac Viandier Date: Sat, 16 Jan 2016 18:39:01 +0100 Subject: [PATCH 2/3] Add exemple of use on_event with argument, in the testing with rspec matcher section --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4a488a8f..68ed80b1 100644 --- a/README.md +++ b/README.md @@ -765,6 +765,8 @@ expect(job).to allow_event :run expect(job).to_not allow_event :clean expect(job).to allow_transition_to(:running) expect(job).to_not allow_transition_to(:cleaning) +# on_event also accept arguments +expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :deframengation) # classes with multiple state machine multiple = SimpleMultipleExample.new From b185d611007618077f70f2f70894811ba87e9ca1 Mon Sep 17 00:00:00 2001 From: Zac Viandier Date: Mon, 1 Feb 2016 00:01:47 +0800 Subject: [PATCH 3/3] Fix the typo in the readme for on_event exemple. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68ed80b1..93968812 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ expect(job).to_not allow_event :clean expect(job).to allow_transition_to(:running) expect(job).to_not allow_transition_to(:cleaning) # on_event also accept arguments -expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :deframengation) +expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :defragmentation) # classes with multiple state machine multiple = SimpleMultipleExample.new