Interactive Console Debugger for Cucumber

92 views
Skip to first unread message

Demetrius Nunes

unread,
Oct 4, 2009, 9:56:04 PM10/4/09
to cu...@googlegroups.com
Hi guys,

I maintain a little Cucumber related tool called Swinger, for testing Java/Swing apps using Cucumber and JRuby.

I've recently added a really useful feature to Swinger that is a interactive console debugger that gets activated once it finds a step "When console!" or a feature tagged with "@console".


It's really simple code really.

Once the console debugger gets activated, we get into a regular IRB session in the middle of a feature execution with all the local, global and World scope available for inspection and manipulation. To get it going again, just exit the IRB session and Cucumber carries on.

It's been a real time saver for us, so I was wondering if it would be interesting to have it as built-in feature in Cucumber itself. What do you think?

I'd rather have only the "tag-based activation", but to get rid of the "When console!" step, we'd have to have a BeforeStep hook available (debugging is a nice use case for BeforeStep, btw - what happened to it?).

Best regards,
Demetrius
--
____________________________
http://www.demetriusnunes.com

Ben Mabey

unread,
Oct 4, 2009, 10:29:46 PM10/4/09
to cu...@googlegroups.com

Hi Demetrius,
Creative use of tagging - I like it. About the console part.. how is it
different from using ruby-debug and placing a debugger statement
(breakpoint) in a step? If you "set autoeval" then you can treat the
ruby-debug session just like an IRB session in addition to the other
regular debugging commands/tools.


-Ben

Demetrius Nunes

unread,
Oct 4, 2009, 10:47:56 PM10/4/09
to cu...@googlegroups.com
Ben, it's really not that different, besides the convenience of adding a tag (or a step) to the feature file, instead of messing up with the step definition code.
--
____________________________
http://www.demetriusnunes.com

Demetrius Nunes

unread,
Oct 4, 2009, 10:59:00 PM10/4/09
to cu...@googlegroups.com
Also, ruby-debug support for JRuby is still flaky and requires quite a bit of trouble to get it working as seen here:
--
____________________________
http://www.demetriusnunes.com

Demetrius Nunes

unread,
Oct 4, 2009, 11:17:10 PM10/4/09
to cu...@googlegroups.com
Ben, I've just tried the ruby-debug approach and it was quite troublesome to reach the correct scope by using the "debugger" method within a step definition. I found myself inside StepInvocation internals and it was quite difficult to get out. 

Not sure if it was my lack of ability with ruby-debug but there is definitely a learning curve there, whereas a simple IRB session in the correct World scope binding is really easier to use.

This feature in its final form could even have a choice of using ruby-debug (if available) or going into a simple IRB session. What do you think?
--
____________________________
http://www.demetriusnunes.com

Luke Melia

unread,
Oct 4, 2009, 11:27:40 PM10/4/09
to cu...@googlegroups.com
We have a step matcher defined "And I debug the test" that looks like this:

When /^I debug (?:the|this) test$/ do
  require "rubygems"; require "ruby-debug"; debugger
  1 #intentionally force debugger context in this method
end

Works a treat. I'm not clear of the advantage of what's proposed.

What would be cool would be to be able to have a command in the IRB debugger session to continue to the first line of the next step matcher that is executed. No idea how to go about that, but as long as we're on this topic.

Cheers,
Luke

Demetrius Nunes

unread,
Oct 4, 2009, 11:33:40 PM10/4/09
to cu...@googlegroups.com
Luke, that "1 #intentionally force debugger context in this method" trick is great. Worked like a charm.

But I believe my other arguments are still valid: built-in, easier to use simple IRB session support with no dependency on ruby-debug, which is requires some work to get it going on JRuby.

--
____________________________
http://www.demetriusnunes.com

Ben Mabey

unread,
Oct 4, 2009, 11:55:56 PM10/4/09
to cu...@googlegroups.com
Luke Melia wrote:
> We have a step matcher defined "And I debug the test" that looks like
> this:
>
> When /^I debug (?:the|this) test$/ do
> require "rubygems"; require "ruby-debug"; debugger
> 1 #intentionally force debugger context in this method
> end
>
> Works a treat. I'm not clear of the advantage of what's proposed.
>
> What would be cool would be to be able to have a command in the IRB
> debugger session to continue to the first line of the next step
> matcher that is executed. No idea how to go about that, but as long as
> we're on this topic.
>
> Cheers,
> Luke
>

Yep, I do something similar. While we are on the topic of ruby-debug
tips here is my ~/.rdebugrc file:
set autolist
set autoeval
set autoreload


Ruby debug will use these settings every time so you don't have to type
them in for each new session. :)

-Ben
> lu...@lukemelia.com <mailto:lu...@lukemelia.com>
> http://www.lukemelia.com/
>
>
> >

Demetrius Nunes

unread,
Oct 5, 2009, 12:07:58 AM10/5/09
to cu...@googlegroups.com
Added ruby-debug support in Swinger:

Now, with: "When debug!", I have "Debugger.start_session binding" and that tries to use ruby-debug if it's available.

Thanks for the good ideas guys. Still would like to see this built into Cucumber... ;)
--
____________________________
http://www.demetriusnunes.com
Reply all
Reply to author
Forward
0 new messages