2019-07-25 01:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-23 09:09:14 -04:00
|
|
|
RSpec::Matchers.define :have_header_with_correct_id_and_link do |level, text, id, parent = ".md"|
|
2018-04-03 06:27:56 -04:00
|
|
|
match do |actual|
|
2019-10-31 17:06:28 -04:00
|
|
|
node = find("#{parent} h#{level} a#user-content-#{id}")
|
2018-04-03 06:27:56 -04:00
|
|
|
|
|
|
|
expect(node[:href]).to end_with("##{id}")
|
|
|
|
|
|
|
|
# Work around a weird Capybara behavior where calling `parent` on a node
|
|
|
|
# returns the whole document, not the node's actual parent element
|
|
|
|
expect(find(:xpath, "#{node.path}/..").text).to eq(text)
|
|
|
|
end
|
|
|
|
end
|