Fixed Spec in Test Unit more thoroghly

This commit is contained in:
Mike Gaffney 2009-06-05 13:50:39 -05:00
parent dd8688f371
commit 6bfdcc54cc
2 changed files with 12 additions and 21 deletions

View File

@ -152,7 +152,9 @@ module Webrat
begin begin
value = yield value = yield
rescue Exception => e rescue Exception => e
raise e unless yieldable_exceptions.include?(e.class) unless is_ignorable_wait_for_exception?(e)
raise e
end
end end
return value if value return value if value
@ -187,14 +189,13 @@ module Webrat
end end
def yieldable_exceptions
return [::Selenium::CommandError, Webrat::WebratError] unless lib_defined?(::Spec::Expectations::ExpectationNotMetError)
[::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError]
end
protected protected
def lib_defined?(library) def is_ignorable_wait_for_exception?(exception) #:nodoc:
defined?(library) 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 end
def setup #:nodoc: def setup #:nodoc:

View File

@ -10,19 +10,9 @@ describe Webrat::SeleniumSession do
@selenium = Webrat::SeleniumSession.new() @selenium = Webrat::SeleniumSession.new()
end 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 it "should throw timeout instead of spec expectionnotmet error" do
lambda { lambda {
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.0001) do
raise ::Spec::Expectations::ExpectationNotMetError raise ::Spec::Expectations::ExpectationNotMetError
end end
}.should raise_error(Webrat::TimeoutError) }.should raise_error(Webrat::TimeoutError)
@ -30,7 +20,7 @@ describe Webrat::SeleniumSession do
it "should throw timeout instead of selenium command error" do it "should throw timeout instead of selenium command error" do
lambda { lambda {
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.0001) do
raise ::Selenium::CommandError raise ::Selenium::CommandError
end end
}.should raise_error(Webrat::TimeoutError) }.should raise_error(Webrat::TimeoutError)
@ -38,7 +28,7 @@ describe Webrat::SeleniumSession do
it "should throw timeout instead of webrat error" do it "should throw timeout instead of webrat error" do
lambda { lambda {
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.0001) do
raise Webrat::WebratError.new raise Webrat::WebratError.new
end end
}.should raise_error(Webrat::TimeoutError) }.should raise_error(Webrat::TimeoutError)