Skip to content

Instantly share code, notes, and snippets.

@atzkey
Created August 3, 2011 12:55
Show Gist options
  • Save atzkey/1122563 to your computer and use it in GitHub Desktop.
Save atzkey/1122563 to your computer and use it in GitHub Desktop.
assert_url_has_param
##
# Passes if +url+ contains +param+ in its query string.
#
# Example:
# assert_url_has_param("http://google.com/?q=RTFM", 'q=RTFM')
def assert_url_has_param(url, param, message = nil)
message = build_message message, "<?> does not contain param <?>", url, param
assert_block message do
URI.parse(url).query.split('&').any?{|p| p == param}
end
end
# Live example:
should "include campaign id for Omniture in all links" do
assert_select "a[href]" do |links|
links.each do |a|
assert_url_has_param a.attributes["href"], "cid=100500"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment