Skip to content

Instantly share code, notes, and snippets.

@mk2310
mk2310 / url_matcher.rb
Created April 13, 2018 14:02 — forked from SirRawlins/url_matcher.rb
RSpec url matcher.
# Drop this into /spec/support/matchers
# Usage: result.should be_url
# Passes if result is a valid url, returns error "expected result to be url" if not.
# Matcher to see if a string is a URL or not.
RSpec::Matchers.define :be_url do |expected|
# The match method, returns true if valie, false if not.
match do |actual|
# Use the URI library to parse the string, returning false if this fails.
URI.parse(actual) rescue false