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? -- Posted via http://www.ruby-forum.com/.
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 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-cucumber/tickets/new
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. -- Posted via http://www.ruby-forum.com/.
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> -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Fedor Fomenko > Sent: Friday, April 10, 2009 4:43 AM > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] [Cucumber] Bug? > > 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. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > __________ Information from ESET NOD32 Antivirus, version of virus > 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