AssertURL
This is my Elixir version of Ruby's AssertURL.
It's a collection of functions to test URLs. The main goal of this module is to develop a better testing habit when dealing with URLs.
Instead of doing assert url == "http://example.com/path?foo=bar where any part of the string will
make the expectation fail, AssertURL proposes to do the following:
assert AssertURL.path_equal "/path", "http://example.com/path"
# => true
assert AssertURL.path_equal "/path", "http://example.com/poth"
# ** (AssertURL.PathError) Expected /path, got /poth.
# stacktrace:
# ...The error messages are colorized for readability.
The functions available are the following:
AssertURL.scheme_equal "http", "http://example.com"AssertURL.host_equal "example.com", "http://example.com"AssertURL.port_equal 80, "http://example.com"AssertURL.path_equal "/path", "http://example.com/path"AssertURL.query_equal [foo: "bar"], "http://example.com/path?foo=bar&baz=wow"AssertURL.query_include "foo=bar&baz=wow", "http://example.com/path?foo=bar&baz=wow"AssertURL.fragment_equal "frag", "http://example.com/path#frag"
I recommend that you take a look at the tests for a full list of examples.
Installation
If available in Hex, the package can be installed as:
-
Add
assert_urlto your list of dependencies inmix.exs:
```elixir
def deps do
[{:assert_url, "~> 0.1.0"}]
end
```-
Ensure
assert_urlis started before your application:
```elixir
def application do
[applications: [:assert_url]]
end
```