raise the exception rather than the exception class - Fix Issue #1785

This commit is contained in:
Thomas Walpole 2016-11-07 09:34:57 -08:00
parent 374d113f41
commit ab0d5f578a
4 changed files with 25 additions and 3 deletions

View File

@ -9,4 +9,5 @@ gem 'xpath', :git => 'git://github.com/jnicklas/xpath.git'
gem 'term-ansicolor', '< 1.4.0'
gem 'tins', '< 1.7.0' # 1.7.0 requires ruby 2.0
gem 'selenium-webdriver', '< 3.0.0' # 3.0 requires ruby 2.0
gem 'selenium-webdriver', '< 3.0.0' # 3.0 requires ruby 2.0
gem 'addressable', '< 2.5.0' # 2.5 requires public_suffix which requires ruby 2.0

View File

@ -125,7 +125,8 @@ module Capybara
begin
raise CapybaraError, "Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true"
rescue CapybaraError
raise @server.error.class, @server.error.message, @server.error.backtrace
#needed to get the cuase set correctly in JRuby -- otherwise we could just do raise @server.error
raise @server.error, @server.error.message, @server.error.backtrace
end
end
ensure

View File

@ -428,6 +428,17 @@ Capybara::SpecHelper.spec "node" do
expect(e.cause.message).to match /Your application server raised an error/
end
end
it "sets an explanatory exception as the cause of server exceptions with errors with initializers", requires: [:server, :js], twtw: true do
skip "This version of ruby doesn't support exception causes" unless Exception.instance_methods.include? :cause
quietly { @session.visit("/other_error") }
expect do
@session.find(:css, 'span')
end.to raise_error(TestApp::TestAppOtherError) do |e|
expect(e.cause).to be_a Capybara::CapybaraError
expect(e.cause.message).to match /Your application server raised an error/
end
end
end
def be_an_invalid_element_error(session)

View File

@ -6,7 +6,12 @@ require 'yaml'
class TestApp < Sinatra::Base
class TestAppError < StandardError; end
class TestAppOtherError < StandardError
def initialize(string1, msg)
@something = string1
@message = msg
end
end
set :root, File.dirname(__FILE__)
set :static, true
set :raise_errors, true
@ -125,6 +130,10 @@ class TestApp < Sinatra::Base
raise TestAppError, "some error"
end
get '/other_error' do
raise TestAppOtherError.new("something", "other error")
end
get '/load_error' do
raise LoadError
end