From 59a53d5a4d1ec76f49b9ba92806fb6f8fe7f8432 Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Fri, 16 May 2014 16:52:16 +0100 Subject: [PATCH 1/5] Add failing spec --- spec/statesman/machine_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/statesman/machine_spec.rb b/spec/statesman/machine_spec.rb index 41b42440..e789e231 100644 --- a/spec/statesman/machine_spec.rb +++ b/spec/statesman/machine_spec.rb @@ -440,6 +440,18 @@ def after_initialize; end end it { should be_false } end + + context "when a non statesman exception is raised" do + before do + instance.stub(:transition_to!).and_raise(RuntimeError, 'user defined exception') + end + + it "should raised not rescue the exception" do + expect { + instance.transition_to(:some_state, metadata) + }.to raise_error(RuntimeError, 'user defined exception') + end + end end shared_examples "a callback filter" do |definer, phase| From 17a84d74a2240897a7b00ed85ab491d49cb12f50 Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Fri, 16 May 2014 16:52:57 +0100 Subject: [PATCH 2/5] Only rescue from TransitionFailedError and GuardFailedError when calling #transition_to --- lib/statesman/machine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statesman/machine.rb b/lib/statesman/machine.rb index 37e6b892..048d2ab7 100644 --- a/lib/statesman/machine.rb +++ b/lib/statesman/machine.rb @@ -196,7 +196,7 @@ def execute(phase, initial_state, new_state, transition) def transition_to(new_state, metadata = nil) self.transition_to!(new_state, metadata) - rescue + rescue TransitionFailedError, GuardFailedError false end From 30119e9832c11d1b4b816331c02b94a41d54ff83 Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Fri, 16 May 2014 16:56:43 +0100 Subject: [PATCH 3/5] Fix typo --- spec/statesman/machine_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/statesman/machine_spec.rb b/spec/statesman/machine_spec.rb index e789e231..2cc523b4 100644 --- a/spec/statesman/machine_spec.rb +++ b/spec/statesman/machine_spec.rb @@ -446,7 +446,7 @@ def after_initialize; end instance.stub(:transition_to!).and_raise(RuntimeError, 'user defined exception') end - it "should raised not rescue the exception" do + it "should not rescue the exception" do expect { instance.transition_to(:some_state, metadata) }.to raise_error(RuntimeError, 'user defined exception') From c804f80b38cc5656559e7eb79c6b269c5965263a Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Fri, 16 May 2014 17:04:21 +0100 Subject: [PATCH 4/5] Styleguide changes --- spec/statesman/machine_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/statesman/machine_spec.rb b/spec/statesman/machine_spec.rb index 2cc523b4..fb798fb1 100644 --- a/spec/statesman/machine_spec.rb +++ b/spec/statesman/machine_spec.rb @@ -443,13 +443,13 @@ def after_initialize; end context "when a non statesman exception is raised" do before do - instance.stub(:transition_to!).and_raise(RuntimeError, 'user defined exception') + instance.stub(:transition_to!).and_raise(RuntimeError, + 'user defined exception') end it "should not rescue the exception" do - expect { - instance.transition_to(:some_state, metadata) - }.to raise_error(RuntimeError, 'user defined exception') + expect { instance.transition_to(:some_state, metadata) }.to + raise_error(RuntimeError, 'user defined exception') end end end From c5f58abcb448464a32225c1dff1d0135afa30a46 Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Fri, 16 May 2014 17:06:32 +0100 Subject: [PATCH 5/5] Further rubocop tweaks --- spec/statesman/machine_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/statesman/machine_spec.rb b/spec/statesman/machine_spec.rb index fb798fb1..475fbbb5 100644 --- a/spec/statesman/machine_spec.rb +++ b/spec/statesman/machine_spec.rb @@ -448,8 +448,11 @@ def after_initialize; end end it "should not rescue the exception" do - expect { instance.transition_to(:some_state, metadata) }.to - raise_error(RuntimeError, 'user defined exception') + expectation = expect do + instance.transition_to(:some_state, metadata) + end + + expectation.to raise_error(RuntimeError, 'user defined exception') end end end