Sha256: 10ad45e59ca3ca1bc1fd1640d4786f64abbf86af0b09fd5805149ab2a84bb892
Contents?: true
Size: 1.57 KB
Versions: 51
Compression:
Stored size: 1.57 KB
Contents
require "test_helper" class GovspeakLinkExtractorTest < Minitest::Test def document_body %{ ## Heading [link](http://www.example.com) [link_two](http://www.gov.com) [not_a_link](#somepage) [mailto:](mailto:someone@www.example.com) [absolute_path](/cais-trwydded-yrru-dros-dro) <a href="http://www.example.com/from/html">raw_html_link</a> [empty_markdown_link]() [a_different_empty_markdown_link]( ) <a>empty_raw_html_link</a> <a href="">a_second_empty_raw_link</a> <a href=" ">a_third_empty_raw_link</a> <a href>a_fourth_empty_raw_link</a> } end def doc @doc ||= Govspeak::Document.new(document_body) end def links doc.extracted_links end test "Links are extracted from the body" do expected_links = %w[http://www.example.com http://www.gov.com /cais-trwydded-yrru-dros-dro http://www.example.com/from/html] assert_equal expected_links, links end test "Other content is not extracted from the body" do refute_includes %w[Heading], links end test "Links are not extracted if they begin with #" do refute_includes ["#somepage"], links end test "Links are not extracted if they begin with mailto:" do refute_includes ["mailto:someone@www.example.com"], links end test "Links are not extracted if they are blank" do refute_includes [""], links refute_includes [nil], links end test "Absolute links are transformed to a url when website_root passed in" do urls = doc.extracted_links(website_root: "http://www.example.com") assert urls.include?("http://www.example.com/cais-trwydded-yrru-dros-dro") end end
Version data entries
51 entries across 51 versions & 1 rubygems