I've added an Around hook to my Cucumber features that I had hoped would cause pry-rescue to start pry when an exception was thrown:
Around do |scenario, block|
When(/^I perform the action$/) do
I wanted to do the same thing - debug when a step fails. Your hook cannot work because a failing step exception is caught already. There seems to be no standard way of doing what you want with cucumber. But if you look at
invoke(runtime, configuration) method, you will see what I am talking about.
In the method step level exceptions are caught. And the last
rescue block is where we want to insert our debugging code. So in latest
cucumber 1.3.12, on line 74 I inserted:
require 'byebug' byebug
And now once the transient failure happens I get a prompt:
[71, 80] in /home/remote/akostadi/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.10/lib/cucumber /ast/step_invocation.rb 71: failed(configuration, e, false) 72: status!(:failed) 73: rescue Exception => e 74: require 'byebug' 75: byebug => 76: failed(configuration, e, false) 77: status!(:failed) 78: end 79: end 80: end
You can insert other debugging code in there though.
I'm thinking if cucumber project will accept a contribution to have a hook there instead.
UPDATE: here's my latest version. The positives in that version are that you get failure log before falling into a debugger. Also you can reach (at least with pry) to the cucumber
World and launch pry inside to play around as if this is your test code. I've opened a discussion in the cuke google group to see if something similar can be implemented upstream. Give your voice and suggestions if you want to have it standard in cucumber.
So just put the below code in
Cucumber::Ast::StepInvocation.class_eval do ## first make sure we don't lose original accept method unless self.instance_methods.include?(:orig_accept) alias_method :orig_accept, :accept end ## wrap original accept method to catch errors in executed step def accept(visitor) orig_accept(visitor) if @exception unless @exception.class.name.start_with?("Cucumber::") # @exception = nil # to continue with following steps # cd visitor.runtime/@support_code # cd @programming_languages.current_world # binding.pry require 'pry' binding.pry end end end end