Skip to content

Commit

Permalink
Clean up exception raising
Browse files Browse the repository at this point in the history
Update protractor.get test
  • Loading branch information
bootstraponline committed Jun 15, 2015
1 parent 20b8d91 commit 2033489
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/angular_webdriver/protractor/protractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def base_url= url
return @base_url = nil unless url

uri = URI.parse(url) rescue false
raise "Invalid URL #{url.inspect}. Must contain scheme and host." unless uri && uri.scheme && uri.host
fail ArgumentError, "Invalid URL #{url.inspect}. Must contain scheme and host." unless uri && uri.scheme && uri.host
@base_url = url
end

Expand Down Expand Up @@ -111,10 +111,10 @@ def get destination, opt_timeout=driver.max_page_wait_seconds

timeout = opt_timeout

raise "Invalid timeout #{timeout}" unless timeout.is_a?(Numeric)
fail ArgumentError, "Invalid timeout #{timeout}" unless timeout.is_a?(Numeric)

unless destination.is_a?(String) || destination.is_a?(URI)
raise "Invalid destination #{destination}"
fail ArgumentError, "Invalid destination #{destination}"
end

# http://about:blank doesn't work. it must be exactly about:blank
Expand Down Expand Up @@ -157,7 +157,7 @@ def get destination, opt_timeout=driver.max_page_wait_seconds
url = executeScript_('return window.location.href;', msg.call('get url'))
not_on_reset_url = url != reset_url
destination_is_reset = destination == reset_url
raise 'still on reset url' unless not_on_reset_url || destination_is_reset
fail 'still on reset url' unless not_on_reset_url || destination_is_reset
end

# now that the url has changed, make sure Angular has loaded
Expand Down Expand Up @@ -240,7 +240,7 @@ def initialize opts={}
@watir = opts[:watir]

valid_watir = defined?(Watir::Browser) && @watir.is_a?(Watir::Browser)
raise "Driver must be a Watir::Browser not #{@driver.class}" unless valid_watir
fail ArgumentError, "Driver must be a Watir::Browser not #{@driver.class}" unless valid_watir
@driver = @watir.driver

unless Selenium::WebDriver::SearchContext::FINDERS.keys.include?(NEW_FINDERS_KEYS)
Expand Down
10 changes: 7 additions & 3 deletions spec/helpers/expect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ def expect_no_element_error &block
# Compare to expect_no_element_error which sets wait to 0 before
# invoking the block.
def expect_no_element_error_with_wait &block
expect { block.call }.to raise_error no_such_element_error
expect_error no_such_element_error, &block
end

def expect_no_method_error &block
expect { block.call }.to raise_error NoMethodError
expect_error NoMethodError, &block
end

def expect_javascript_error &block
expect { block.call }.to raise_error Selenium::WebDriver::Error::JavascriptError
expect_error Selenium::WebDriver::Error::JavascriptError, &block
end

def expect_argument_error &block
expect_error ArgumentError, &block
end

# Expects block to raise error
Expand Down
4 changes: 2 additions & 2 deletions spec/protractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
protractor.ignore_sync = true
expect_no_error { driver.get protractor.reset_url }

# should raise error on invalid destination
expect_error { driver.get({ invalid: 'object '}) }
# protractor.get should raise error on invalid destination
expect_argument_error { protractor.get({ invalid: 'object '}) }
end

it 'driver_get' do
Expand Down

0 comments on commit 2033489

Please sign in to comment.