Skip to content

Commit

Permalink
Receiver#flunk accepts stacktrace as final arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Mar 17, 2013
1 parent f42f118 commit b7eeff0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote - 2.3.1 not yet released

- Receiver#flunk accepts stacktrace as final argument
- allow for "1x == 2x" (turn it into "'1x' == '2x'") (== and !=)
- fix parsing '2013-02-08T17:36:10Z' (reported by Hartog de Mik)

Expand Down
6 changes: 5 additions & 1 deletion lib/ruote/receiver/base.rb
Expand Up @@ -78,12 +78,16 @@ def flunk(workitem, error_class_or_instance_or_message, *err_arguments)
err = error_class_or_instance_or_message

if err.is_a?(String)

err = RuntimeError.new(err)
err.set_backtrace(caller)

elsif err.is_a?(Class)

trace = err_arguments.last.is_a?(Array) ? err_arguments.pop : nil

err = err.new(*err_arguments)
err.set_backtrace(caller)
err.set_backtrace(trace || caller)
end

workitem = workitem.h if workitem.respond_to?(:h)
Expand Down
25 changes: 25 additions & 0 deletions test/functional/ft_25_receiver.rb
Expand Up @@ -224,6 +224,14 @@ def on_cancel
end
end

class BacktraceFlunkParticipant < Ruote::Participant

def on_workitem

flunk(workitem, ArgumentError, 'nada', %w[ aaa bbb ccc ])
end
end

def test_flunk

@dashboard.register :alpha, FlunkParticipant
Expand Down Expand Up @@ -255,5 +263,22 @@ def test_string_flunk
assert_equal 'out of order', r['error']['message']
assert_match __FILE__, r['error']['trace'].first
end

def test_backtrace_flunk

@dashboard.register :alpha, BacktraceFlunkParticipant

wfid =
@dashboard.launch(Ruote.define do
alpha
end)

r = @dashboard.wait_for(wfid)

assert_equal 'error_intercepted', r['action']
assert_equal 'ArgumentError', r['error']['class']
assert_equal 'nada', r['error']['message']
assert_equal %w[ aaa bbb ccc ], r['error']['trace']
end
end

0 comments on commit b7eeff0

Please sign in to comment.