Forum: RSpec [Cucumber] Bug?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fedor F. (Guest)
on 2009-04-09 16:39
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?
Ben M. (Guest)
on 2009-04-09 21:10
(Received via mailing list)
Fedor Fomenko wrote:
> end
>  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
exceptions.

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|
  begin
    msg = @browser.ul(:class, 'validation-summary-errors').li(:text,
error)
  rescue Exception =>e
    puts "This was raised: #{e.inspect}"
    raise e
  end
  #pp msg.text
end


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

HTH,
Ben

1. https://rspec.lighthouseapp.com/projects/16211-cuc...
Fedor F. (Guest)
on 2009-04-10 13:43
Thank you for your help.

I found the problem. My assertion was wrong. I should have used
msg.exists?.should == true since msg.should_not == nil is allways true.
Watir always returns an object which might or might nor have text field.
Mark Anderson (Guest)
on 2009-04-10 17:28
(Received via mailing list)
I prefer to use the form 'msg.should exist' because I feel that it reads
better.  The error message is a little wordy, but still more
communicative
than expected true and got false.

                      /\/\ark

> msg.exists?.should == true since msg.should_not == nil is allways true.
> signature database 3998 (20090409) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>


__________ Information from ESET NOD32 Antivirus, version of virus
signature
database 3999 (20090410) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This topic is locked and can not be replied to.