-
-
Save LimeBlast/edcfe156c5d719eaea1e to your computer and use it in GitHub Desktop.
`have_link_ends_with` matcher
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
require 'spec_helper' | |
describe "Activation Email" do | |
it "confirms the email when user clicks the confirmation link on activation email" do | |
register_new_user("[email protected]", "adobe password", "adobe password") | |
activation_token = User.last.activation_code | |
expect( open_last_email.default_part_body ).to have_link_with_ends_with(activation_token) | |
visit activation_path(activation_token) | |
expect(page).to have_content( "Your email has been confirmed.") | |
end | |
end |
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
# spec/features/support/have_link_ends_with.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 | |
"expected there be a link which href ends with #{matching_value.inspect} in #{@actual.text}" | |
end | |
def failure_message_when_negated | |
"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_ends_with(*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