Class: Testrus::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/testrus/tester.rb,
lib/testrus/tester/formatter/default.rb

Defined Under Namespace

Modules: Formatter

Constant Summary collapse

SOURCES =

Internal: Defines the relationship between input sources and their corresponding class names.

{
  :file => Testrus::Input::File
}
FORMATTERS =

Internal: Defines the formatters to allow specifying a custom formatter in the options.

{
  :default => Formatter::Default
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Tester

Public: Initializes a tester object. The tester is responsible for coordinating the input from the input source and the runner, and passing the final results to the formatter.

options - The Hash containing the options for the Tester:

:source  - The Symbol marking the input source, valid options
are defined in the class constant Tester::SOURCES.
:command - The String specifying the command to run program that
the the input will be given to via STDIN.


27
28
29
# File 'lib/testrus/tester.rb', line 27

def initialize(options)
  @options = default_options.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/testrus/tester.rb', line 3

def options
  @options
end

Instance Method Details

#formatterObject

Public: Returns the formatter class.



46
47
48
# File 'lib/testrus/tester.rb', line 46

def formatter
  FORMATTERS[@options[:formatter]]
end

#runObject

Public: Runs the input from the source against the runner. Return the results to the formatter.



52
53
54
55
56
# File 'lib/testrus/tester.rb', line 52

def run
  source.tests.each do |test|
    formatter.new(runner.run(test)).report
  end
end

#runnerObject

Public: Returns the instance of the runner which is responsible for running the program against the input.



41
42
43
# File 'lib/testrus/tester.rb', line 41

def runner
  @runner ||= Testrus::Runner.new(options[:command])
end

#sourceObject

Public: Maps the human source to the class that is responsible for the given source.

Returns a corresponding Class constant.



35
36
37
# File 'lib/testrus/tester.rb', line 35

def source
  @source ||= SOURCES[@options[:source]].new
end