Created
August 3, 2011 12:55
-
-
Save atzkey/1122563 to your computer and use it in GitHub Desktop.
assert_url_has_param
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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