module Rutema::ConfigurationDirectives

This module defines the “configuration directives” used in the configuration of Rutema

Example A configuration file needs as a minimum to define which parser to use and which tests to run.

Since rutema configuration files are valid Ruby code, you can use the full power of the Ruby language including require directives

require 'rake'
configuration.parser={:class=>Rutema::MinimalXMLParser}
configuration.tests=FileList['all/of/the/tests/**/*.*']

Attributes

check[R]
context[R]
parser[R]
paths[R]
reporters[RW]
runner[R]
setup[R]
suite_setup[R]
suite_teardown[R]
teardown[R]
tests[R]
tools[R]

Public Instance Methods

check=(path)
Alias for: suite_setup=
context=(definition) click to toggle source

Hash values for passing data to the system. It’s supposed to be used in the reporters and contain values such as version numbers, tester names etc.

# File lib/rutema/core/configuration.rb, line 83
def context= definition
  @context||=Hash.new
  raise ConfigurationException,"Only accepting hash values as context_data" unless definition.kind_of?(Hash)
  @context.merge!(definition)
end
init() click to toggle source

:stopdoc

# File lib/rutema/core/configuration.rb, line 129
def init
  @reporters={}
  @context={}
  @tests=[]
  @tools=OpenStruct.new
  @paths=OpenStruct.new
end
parser=(definition) click to toggle source

A hash defining the parser to use.

The hash is passed as is to the parser constructor and each parser should define the necessary configuration keys.

The only required key from the configurator’s point fo view is :class which should be set to the fully qualified name of the class to use.

Example:

cfg.parser={:class=>Rutema::MinimalXMLParser}
# File lib/rutema/core/configuration.rb, line 103
def parser= definition
  raise ConfigurationException,"required key :class is missing from #{definition}" unless definition[:class]
  @parser=definition
end
path=(definition) click to toggle source

Adds a path to the paths hash of the configuration

Required keys:

:name - the name to use for accessing the path in code
:path - the path

Example:

cfg.path={:name=>"sources",:path=>"/src"}
# File lib/rutema/core/configuration.rb, line 45
def path= definition
  raise ConfigurationException,"required key :name is missing from #{definition}" unless definition[:name]
  raise ConfigurationException,"required key :path is missing from #{definition}" unless definition[:path]
  @paths[definition[:name]]=definition[:path]
end
reporter=(definition) click to toggle source

Adds a reporter to the configuration.

As with the parser, the only required configuration key is :class and the definition hash is passed to the class’ constructor.

Unlike the parser, you can define multiple reporters.

# File lib/rutema/core/configuration.rb, line 124
def reporter= definition
  raise ConfigurationException,"required key :class is missing from #{definition}" unless definition[:class]
  @reporters[definition[:class]]=definition
end
runner=(definition) click to toggle source

A hash defining the runner to use.

The hash is passed as is to the runner constructor and each runner should define the necessary configuration keys.

The only required key from the configurator’s point fo view is :class which should be set to the fully qualified name of the class to use.

Example:

cfg.runner={:class=>Rutema::Runners::NoOp}
# File lib/rutema/core/configuration.rb, line 115
def runner= definition
  raise ConfigurationException,"required key :class is missing from #{definition}" unless definition[:class]
  @runner=definition
end
setup=(path) click to toggle source

Path to the setup specification. (optional)

The setup test runs before every test.

# File lib/rutema/core/configuration.rb, line 53
def setup= path
  @setup=check_path(path)
end
suite_setup=(path) click to toggle source

Path to the suite setup specification. (optional)

The suite setup test runs once in the beginning of a test run before all the tests.

If it fails no tests are run.

This is also aliased as check= for backwards compatibility

# File lib/rutema/core/configuration.rb, line 69
def suite_setup= path
  @suite_setup=check_path(path)
end
Also aliased as: check=
suite_teardown=(path) click to toggle source

Path to the suite teardown specification. (optional)

The suite teardown test runs after all the tests.

# File lib/rutema/core/configuration.rb, line 78
def suite_teardown= path
  @suite_teardown=check_path(path)
end
teardown=(path) click to toggle source

Path to the teardown specification. (optional)

The teardown test runs after every test.

# File lib/rutema/core/configuration.rb, line 59
def teardown= path
  @teardown=check_path(path)
end
tests=(array_of_identifiers) click to toggle source

Adds the specification identifiers available to this instance of Rutema

These will usually be files, but they can be anything. Essentially this is an Array of strings that mean something to your parser

# File lib/rutema/core/configuration.rb, line 92
def tests= array_of_identifiers
  @tests+=array_of_identifiers.map{|f| full_path(f)}
end
tool=(definition) click to toggle source

Adds a hash of values to the tools hash of the configuration

This hash is then accessible in the parser and reporters as a property of the configuration instance

Required keys:

:name - the name to use for accessing the path in code

Example:

configure do |cfg|
 cfg.tool={:name=>"nunit",:path=>"/bin/nunit",:configuration=>{:important=>"info"}}
end

The path to nunit can then be accessed in the parser as

@configuration.tools.nunit[:path]

This way you can pass configuration information for the tools you use

# File lib/rutema/core/configuration.rb, line 34
def tool= definition
  raise ConfigurationException,"required key :name is missing from #{definition}" unless definition[:name]
  @tools[definition[:name]]=definition
end

Private Instance Methods

check_path(path) click to toggle source

Checks if a path exists and raises a ConfigurationException if not

# File lib/rutema/core/configuration.rb, line 139
def check_path path
  path=File.expand_path(path)
  raise ConfigurationException,"#{path} does not exist" unless File.exist?(path)
  return path
end
definition_string(definition) click to toggle source

Gives back a string of key=value,key=value for a hash

# File lib/rutema/core/configuration.rb, line 145
def definition_string definition
  msg=Array.new
  definition.each{|k,v| msg<<"#{k}=#{v}"}
  return msg.join(",")
end
full_path(filename) click to toggle source
# File lib/rutema/core/configuration.rb, line 151
def full_path filename
  return File.expand_path(filename) if File.exist?(filename)
  return filename
end