[rspec-users] [Cucumber] Bug?

Ben Mabey ben at benmabey.com
Thu Apr 9 12:43:07 EDT 2009

Fedor Fomenko wrote:
> Hello,
> I have the following step for checking that a validation message is
> displayed on screen:
> Then /^(.+) should be displayed$/ do |error|
>   msg = @browser.ul(:class, 'validation-summary-errors').li(:text,
> error)
>   #pp msg.text
>   msg.should_not == nil
> end
> I run scenario with examples table which contains expected error
> messages. If I put wrong error message and pp line in step is commented
> out as shown I get green result from Cucumber, which is wrong. When I
> uncomment pp line I get exception
>  Unable to locate element, using :text, "BOOOOOOOOOO"
> (Watir::Exception::UnknownObjectException)
>  ./features/step_definitions/customer_details_steps.rb:47:in `/^(.+)
> should be displayed$/'
>  features/customer_details_full.feature:40:in `Then <Error> should be
> displayed'
> And step is shown as Red in Cucumber as it should.
> Is this a bug in Cucumber or am I missing something?

I'm not sure if I fully understand the situation... Let me try to 
summarize.  The exception being raised seems to be coming from the first 
line in the step, is that correct?  (So, having the "msg.should_not == 
nil" seems redundant.) To sum it up, when you have a pp call after you 
have watir locate the element then no exception appears to be thrown.  
However, without the pp call the exception is thrown, or at least 
reported by Cucumber.  Is that right?

 From my current understanding there could be two things going on.
A) Watir is not being consistent in when it throws an exception. OR
B) Cucumber is not being consistent on how it handles and reports 

Try catching the Watir exception yourself to see if the problem is with 
Watir not raising an exception.  So something like...

Then /^(.+) should be displayed$/ do |error|
    msg = @browser.ul(:class, 'validation-summary-errors').li(:text,
  rescue Exception =>e
    puts "This was raised: #{e.inspect}"
    raise e
  #pp msg.text

If it appears that Cucumber is not handling the exceptions consistently then open up a ticket for it. [1]


1. https://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/new

More information about the rspec-users mailing list