Last active
December 27, 2015 11:29
-
-
Save tuomasj/7319412 to your computer and use it in GitHub Desktop.
Have a link that ends with specific text, Capybara matcher
This file contains 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
# have_link_endswith.rb | |
module Capybara | |
module RSpecMatchers | |
class HaveLinkEndswith < Matcher | |
attr_reader :matching_value | |
def initialize(*args) | |
@matching_value = args.first | |
end | |
def matches?(actual) | |
@actual = wrap(actual) | |
@actual.has_selector?( :css, "a[href$='#{matching_value}']") | |
end | |
def does_not_match?(actual) | |
@actual = wrap(actual) | |
@actual.has_no_selector?( :css, "a[href$='#{matching_value}']") | |
end | |
def failure_message_for_should | |
"expected there be a link which href ends with #{matching_value.inspect} in #{@actual.text}" | |
end | |
def failure_message_for_should_not | |
"expected there not be a link which href ends with #{matching_value.inspect} in #{@actual.text}" | |
end | |
def description | |
"link with href that ends with #{format(content)}" | |
end | |
end | |
def have_link_that_endswith(*args) | |
HaveLinkEndswith.new(*args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment