lib/watirsplash/rspec_patches.rb in watirsplash-2.0.0 vs lib/watirsplash/rspec_patches.rb in watirsplash-2.0.1.rc1
- old
+ new
@@ -1,8 +1,17 @@
require 'rspec/core/formatters/html_formatter'
require 'rspec/core/formatters/snippet_extractor'
+# make sure that UnkownObjectException constant exists
+module Watir
+ module Exception
+ class WatirException < RuntimeError
+ end
+ class UnknownObjectException < WatirException; end
+ end
+end
+
# patch for https://github.com/rspec/rspec-core/issues/#issue/214
module RSpec
module Core
module Formatters
class HtmlFormatter < BaseTextFormatter
@@ -145,13 +154,25 @@
if inst_methods.include? :matches?
alias_method :__matches?, :matches?
def matches?(actual)
if @within_timeout
- Watir::Wait.until(@within_timeout) {__matches?(actual)} rescue false
+ Watir::Wait.until(@within_timeout) do
+ begin
+ __matches?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue false
elsif @during_timeout
- Watir::Wait.while(@during_timeout) {__matches?(actual)} rescue true
+ Watir::Wait.while(@during_timeout) do
+ begin
+ __matches?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue true
else
__matches?(actual)
end
end
end
@@ -159,22 +180,46 @@
if inst_methods.include? :does_not_match?
alias_method :__does_not_match?, :does_not_match?
def does_not_match?(actual)
if @within_timeout
- Watir::Wait.until(@within_timeout) {__does_not_match?(actual)} rescue false
+ Watir::Wait.until(@within_timeout) do
+ begin
+ __does_not_match?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue false
elsif @during_timeout
- Watir::Wait.while(@during_timeout) {__does_not_match?(actual)} rescue true
+ Watir::Wait.while(@during_timeout) do
+ begin
+ __does_not_match?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue true
else
__does_not_match?(actual)
end
end
elsif inst_methods.include? :matches?
def does_not_match?(actual)
if @within_timeout
- Watir::Wait.until(@within_timeout) {!__matches?(actual)} rescue false
+ Watir::Wait.until(@within_timeout) do
+ begin
+ !__matches?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue false
elsif @during_timeout
- Watir::Wait.while(@during_timeout) {!__matches?(actual)} rescue true
+ Watir::Wait.while(@during_timeout) do
+ begin
+ !__matches?(actual)
+ rescue Watir::Exception::UnknownObjectException
+ false
+ end
+ end rescue true
else
!__matches?(actual)
end
end
end