tests/testthat/test-scrape_menu_rule.R

test_that("scrape_menu_rule works", {
  # check inputs
  expect_error(scrape_menu_rule())
  expect_error(scrape_menu_rule("a", "b", "c"))

  # check outputs
  url_to_scrape <-
    "http://www.prarulebook.co.uk/rulebook/Content/Chapter/242047/16-11-2007"
  nodes_only <-
    httr::GET(url_to_scrape) %>% PRArulebook:::extract_results()
  nodes_only <-
    nodes_only %>%
    xml2::read_html() %>%
    rvest::html_nodes("a")
  rules_date <- "16-11-2007"
  # function call
  rule_menu <-
    scrape_menu_rule(url_to_scrape,
                     nodes_only,
                     rulebook_date = rules_date)
  # does it return a data frame?
  expect_s3_class(rule_menu, "data.frame")
  # are the names correct?
  expected_names <-
    c(
      "rule_url",
      "rule_id",
      "rule_number_sel",
      "rule_text_sel",
      "rule_link_sel",
      "chapter_url"
    )
  returned_names <- names(rule_menu)
  expect_identical(expected_names, returned_names)
})
mroliversmith/PRAClone documentation built on Jan. 11, 2020, 2:05 a.m.