Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle AASM::InvalidTransition in RSpec transition_from matcher #653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/aasm/rspec/transition_from.rb
Expand Up @@ -2,7 +2,11 @@
match do |obj|
@state_machine_name ||= :default
obj.aasm(@state_machine_name).current_state = from_state.to_sym
obj.send(@event, *@args) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym
begin
obj.send(@event, *@args) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym
rescue AASM::InvalidTransition
false
end
end

chain :on do |state_machine_name|
Expand Down
3 changes: 3 additions & 0 deletions spec/unit/rspec_matcher_spec.rb
Expand Up @@ -8,14 +8,17 @@
it "works for simple state machines" do
expect(simple).to transition_from(:initialised).to(:filled_out).on_event(:fill_out)
expect(simple).to_not transition_from(:initialised).to(:authorised).on_event(:fill_out)
expect(simple).to_not transition_from(:authorised).to(:filled_out).on_event(:fill_out)
end

it "works for multiple state machines" do
expect(multiple).to transition_from(:standing).to(:walking).on_event(:walk).on(:move)
expect(multiple).to_not transition_from(:standing).to(:running).on_event(:walk).on(:move)
expect(multiple).to_not transition_from(:running).to(:walking).on_event(:walk).on(:move)

expect(multiple).to transition_from(:sleeping).to(:processing).on_event(:start).on(:work)
expect(multiple).to_not transition_from(:sleeping).to(:sleeping).on_event(:start).on(:work)
expect(multiple).to_not transition_from(:processing).to(:sleeping).on_event(:start).on(:work)
end
end

Expand Down