Class: Rutema::Parsers::XML

Inherits:
SpecificationParser show all
Includes:
Elements::Minimal
Defined in:
lib/rutema/parsers/xml.rb

Overview

Basic and easily extendable parser for test specifications in XML format

Actual XML specification parsers should be derived from this class and define for each specification element foo to be parsed a method element_foo.

The method will receive a Rutema::Step instance as a parameter which it should return

Constant Summary collapse

ELEM_SPEC =

:nodoc:

"specification".freeze
ELEM_DESC =

:nodoc:

"specification/description".freeze
ELEM_TITLE =

:nodoc:

"specification/title".freeze
ELEM_SCENARIO =

:nodoc:

"specification/scenario".freeze

Instance Attribute Summary

Attributes inherited from SpecificationParser

#configuration

Instance Method Summary collapse

Methods included from Elements::Minimal

#element_command, #element_echo, #element_prompt

Methods inherited from SpecificationParser

#initialize, #parse_setup, #parse_teardown, #validate_configuration

Constructor Details

This class inherits a constructor from Rutema::Parsers::SpecificationParser

Instance Method Details

#parse_specification(param) ⇒ Object

Pass the given test specification and return a corresponding Specification instance

The passed argument can either be the path to a test specification file or the test specification itself.

This will raise ParserError if an error occurs during parsing.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rutema/parsers/xml.rb', line 39

def parse_specification(param)
  @parsed ||= []
  begin
    if File.exist?(param)
      txt = File.read(param)
      filename = File.expand_path(param)
    else
      txt = param
      filename = Dir.pwd
    end
    spec = parse_case(txt, filename)
    raise Rutema::ParserError, "Missing required attribute 'name' in specification element" unless spec.has_name? && !spec.name.empty?
    raise Rutema::ParserError, "Duplicate test name '#{spec.name}' in #{filename}" if @parsed.include?(spec.name)

    @parsed << spec.name
    extension_handling(spec)
  rescue REXML::ParseException
    raise Rutema::ParserError, $!.message
  end
end