"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/features/step_definitions.rb" (1 Jun 2019, 1520 Bytes) of package /linux/www/asciidoctor-2.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 ASCIIDOCTOR_FEATURES_DIR = File.absolute_path __dir__
    3 ASCIIDOCTOR_LIB_DIR = ENV['ASCIIDOCTOR_LIB_DIR'] || File.join(ASCIIDOCTOR_FEATURES_DIR, '../lib')
    4 
    5 require 'simplecov' if ENV['COVERAGE'] == 'true'
    6 
    7 require File.join ASCIIDOCTOR_LIB_DIR, 'asciidoctor'
    8 Dir.chdir Asciidoctor::ROOT_DIR
    9 
   10 require 'rspec/expectations'
   11 require 'tilt'
   12 require 'slim'
   13 
   14 Given /the AsciiDoc source/ do |source|
   15   @source = source
   16 end
   17 
   18 When /it is converted to html/ do
   19   @output = Asciidoctor.convert @source
   20 end
   21 
   22 When /it is converted to docbook/ do
   23   @output = Asciidoctor.convert @source, backend: :docbook
   24 end
   25 
   26 Then /the result should (match|contain) the (HTML|XML) source/ do |matcher, format, expected|
   27   match_expectation = matcher == 'match' ? (eq expected) : (include expected)
   28   (expect @output).to match_expectation
   29 end
   30 
   31 Then /the result should (match|contain) the (HTML|XML) structure/ do |matcher, format, expected|
   32   result = @output
   33   if format == 'HTML'
   34     options = { format: :html, disable_escape: true, sort_attrs: false }
   35   else # format == 'XML'
   36     options = { format: :xhtml, disable_escape: true, sort_attrs: false }
   37     result = result.gsub '"/>', '" />' if result.include? '"/>'
   38   end
   39   result = Slim::Template.new(options) { result.each_line.map {|l| (l.start_with? '<') ? l : %(|#{l}) }.join }.render
   40   expected = Slim::Template.new(options) { expected }.render
   41   match_expectation = matcher == 'match' ? (eq expected) : (include expected)
   42   (expect result).to match_expectation
   43 end