From 6bfdcc54cc82b23d268987e758d7676db1061fee Mon Sep 17 00:00:00 2001 From: Mike Gaffney Date: Fri, 5 Jun 2009 13:50:39 -0500 Subject: [PATCH] Fixed Spec in Test Unit more thoroghly --- lib/webrat/selenium/selenium_session.rb | 17 +++++++++-------- spec/public/selenium/selenium_session_spec.rb | 16 +++------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 630f61b..e8b70e8 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -152,7 +152,9 @@ module Webrat begin value = yield rescue Exception => e - raise e unless yieldable_exceptions.include?(e.class) + unless is_ignorable_wait_for_exception?(e) + raise e + end end return value if value @@ -187,14 +189,13 @@ module Webrat end - def yieldable_exceptions - return [::Selenium::CommandError, Webrat::WebratError] unless lib_defined?(::Spec::Expectations::ExpectationNotMetError) - [::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError] - end - protected - def lib_defined?(library) - defined?(library) + def is_ignorable_wait_for_exception?(exception) #:nodoc: + if defined?(::Spec::Expectations::ExpectationNotMetError) + return true if exception.class == ::Spec::Expectations::ExpectationNotMetError + end + return true if [::Selenium::CommandError, Webrat::WebratError].include?(exception.class) + return false end def setup #:nodoc: diff --git a/spec/public/selenium/selenium_session_spec.rb b/spec/public/selenium/selenium_session_spec.rb index d76c95c..6e2867c 100644 --- a/spec/public/selenium/selenium_session_spec.rb +++ b/spec/public/selenium/selenium_session_spec.rb @@ -10,19 +10,9 @@ describe Webrat::SeleniumSession do @selenium = Webrat::SeleniumSession.new() end - it "should provide a list yieldable exceptions without spec if spec isn't defined" do - @selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(false) - @selenium.yieldable_exceptions.should == [::Selenium::CommandError, Webrat::WebratError] - end - - it "should provide a list yieldable exceptions with rspec" do - @selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(true) - @selenium.yieldable_exceptions.should == [::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError] - end - it "should throw timeout instead of spec expectionnotmet error" do lambda { - @selenium.wait_for(:timeout => 0.1) do + @selenium.wait_for(:timeout => 0.0001) do raise ::Spec::Expectations::ExpectationNotMetError end }.should raise_error(Webrat::TimeoutError) @@ -30,7 +20,7 @@ describe Webrat::SeleniumSession do it "should throw timeout instead of selenium command error" do lambda { - @selenium.wait_for(:timeout => 0.1) do + @selenium.wait_for(:timeout => 0.0001) do raise ::Selenium::CommandError end }.should raise_error(Webrat::TimeoutError) @@ -38,7 +28,7 @@ describe Webrat::SeleniumSession do it "should throw timeout instead of webrat error" do lambda { - @selenium.wait_for(:timeout => 0.1) do + @selenium.wait_for(:timeout => 0.0001) do raise Webrat::WebratError.new end }.should raise_error(Webrat::TimeoutError)