You are currently browsing the tag archive for the ‘Capybara’ tag.
Tag Archive
Capybara: use current_path_info instead of current_path / current_url
2011-11-26 in Ruby | Tags: Capybara | Leave a comment
Capybara has current_url, which returns an url that is unmatcheable since it includes a randomized port, and current_path with contains neither query nor fragment(aka hash/anchor) and is therefore rather useless.
Behold the perfect current_path_info, which returns the full path and query + fragment.
Code
def current_path_info
current_url.sub(%r{.*?://},'')[%r{[/\?\#].*}] || '/'
end
