test/test_helper.rb in asciidoctor-0.1.2 vs test/test_helper.rb in asciidoctor-0.1.3
- old
+ new
@@ -2,16 +2,10 @@
require 'pathname'
require 'test/unit'
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/asciidoctor.rb"
-begin
- require 'mocha/setup'
-rescue LoadError
- require 'mocha'
-end
-require 'htmlentities'
require 'nokogiri'
require 'pending'
ENV['SUPPRESS_DEBUG'] ||= 'true'
@@ -80,10 +74,15 @@
results = doc.css(path)
end
count == 1 ? results.first : results
end
+ # Generate an xpath attribute matcher that matches a name in the class attribute
+ def contains_class(name)
+ %(contains(concat(' ', normalize-space(@class), ' '), ' #{name} '))
+ end
+
def assert_css(css, content, count = nil)
assert_path(:css, css, content, count)
end
def assert_xpath(xpath, content, count = nil)
@@ -98,11 +97,17 @@
type_name = 'CSS'
end
results = xmlnodes_at_path type, path, content
- if (count && results.length != count)
+ if (count == true || count == false)
+ if (count != results)
+ flunk "#{type_name} #{path} yielded #{results} rather than #{count} for:\n#{content}"
+ else
+ assert true
+ end
+ elsif (count && results.length != count)
flunk "#{type_name} #{path} yielded #{results.length} elements rather than #{count} for:\n#{content}"
elsif (count.nil? && results.empty?)
flunk "#{type_name} #{path} not found in:\n#{content}"
else
assert true
@@ -141,9 +146,15 @@
end
def parse_header_metadata(source)
reader = Asciidoctor::Reader.new source.lines.entries
[Asciidoctor::Lexer.parse_header_metadata(reader), reader]
+ end
+
+ # Expand the character for an entity such as — so
+ # it can be used to match in an XPath expression
+ def expand_entity(number)
+ [number].pack('U*')
end
def invoke_cli_to_buffer(argv = [], filename = 'sample.asciidoc', &block)
invoke_cli(argv, filename, [StringIO.new, StringIO.new], &block)
end