From e338a862e12887ba5fec277fbd6e1d1ec89dad6f Mon Sep 17 00:00:00 2001 From: Daniel Perez Date: Tue, 22 Mar 2016 12:26:02 +0900 Subject: [PATCH] Add NotSupportedError. --- lib/hound/exceptions.ex | 11 +++++++++++ test/exceptions_test.exs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/exceptions_test.exs diff --git a/lib/hound/exceptions.ex b/lib/hound/exceptions.ex index 41a7a3a..5853cb0 100644 --- a/lib/hound/exceptions.ex +++ b/lib/hound/exceptions.ex @@ -14,3 +14,14 @@ defmodule Hound.InvalidElementError do "Could not transform value #{inspect(err.value)} to element" end end + +defmodule Hound.NotSupportedError do + defexception [:function, :browser, :driver] + + def message(err) do + {:ok, info} = Hound.ConnectionServer.driver_info + driver = err.driver || info.driver + browser = err.browser || info.browser + "#{err.function} is not supported by driver #{driver} with browser #{browser}" + end +end diff --git a/test/exceptions_test.exs b/test/exceptions_test.exs new file mode 100644 index 0000000..d47d299 --- /dev/null +++ b/test/exceptions_test.exs @@ -0,0 +1,17 @@ +defmodule HoundNotSupportedErrorTest do + use ExUnit.Case + + test "message" do + {:ok, info} = Hound.ConnectionServer.driver_info + function_name = "foo" + err = try do + raise Hound.NotSupportedError, function: function_name + rescue + e -> Exception.message(e) + end + assert err =~ "not supported" + assert err =~ function_name + assert err =~ info.driver + assert err =~ info.browser + end +end