require_relative 'test_helper' module BNF class TreeTest < Minitest::Test def test_yield_to_a_block_for_each block_called = false @tree.each do |h| block_called = true break end assert block_called end def test_find_by_name_capitalised heading = @tree.find('Paracetamol') refute_nil heading assert_equal 'https://www.evidence.nhs.uk/formulary/bnf/current/4-central-nervous-system/47-analgesics/471-non-opioid-analgesics-and-compound-analgesic-preparations/paracetamol', heading.uri assert_equal 'PARACETAMOL', heading.title end def test_find_by_name_lowercase heading = @tree.find('dalteparin sodium') refute_nil heading assert_equal 'DALTEPARIN SODIUM', heading.title end def test_find_by_name_uppercase heading = @tree.find('DALTEPARIN SODIUM') refute_nil heading assert_equal 'DALTEPARIN SODIUM', heading.title end def test_find_by_name_ignore_whitespace heading = @tree.find(' DALTEPARIN SODIUM ') refute_nil heading assert_equal 'DALTEPARIN SODIUM', heading.title end def test_find_by_regex heading = @tree.find(/^DALTEPARIN/) refute_nil heading assert_equal 'DALTEPARIN SODIUM', heading.title end def setup @@tree ||= BNF::Tree.new(:bnf) @tree = @@tree end end end