Class: Roger::Test

Inherits:
Object
  • Object
show all
Extended by:
Helpers::GetCallable
Includes:
Helpers::GetFiles, Helpers::Logging
Defined in:
lib/roger/test.rb

Overview

The test class itself

Defined Under Namespace

Classes: Cli

Constant Summary

Constants included from Helpers::GetFiles

Helpers::GetFiles::GLOB_OPTIONS

Constants included from Helpers::Logging

Helpers::Logging::GRAY, Helpers::Logging::RED

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::GetCallable

get_callable

Methods included from Helpers::GetFiles

#get_files, #match_path

Methods included from Helpers::Logging

#debug, #log, #warn

Constructor Details

#initialize(project, config = {}) ⇒ Test

Returns a new instance of Test.



59
60
61
62
63
64
65
# File 'lib/roger/test.rb', line 59

def initialize(project, config = {})
  defaults = {}

  @config = {}.update(defaults).update(config)
  @project = project
  @stack = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



31
32
33
# File 'lib/roger/test.rb', line 31

def config
  @config
end

#projectObject (readonly)

Returns the value of attribute project.



31
32
33
# File 'lib/roger/test.rb', line 31

def project
  @project
end

Class Method Details

.cli_mapObject

Mapping names to CLI handlers (this gives the option to add custom subcommands like ‘init’)



54
55
56
# File 'lib/roger/test.rb', line 54

def cli_map
  @_cli_map ||= {}
end

.mapObject

Mapping names to test callers



49
50
51
# File 'lib/roger/test.rb', line 49

def map
  @_map ||= {}
end

.register(name, test, cli = nil) ⇒ Object

Register a test method to Roger::Test so it can be used in the Rogerfile

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
# File 'lib/roger/test.rb', line 38

def register(name, test, cli = nil)
  if map.key?(name)
    raise ArgumentError, "Another test has already claimed the name #{name.inspect}"
  end

  raise ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
  map[name] = test
  cli_map[name] = cli if cli
end

Instance Method Details

#run!Object

Run all tests and return true when succeeded



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/roger/test.rb', line 80

def run!
  project.mode = :test

  success = true
  @stack.each do |task|
    ret = call_test(task) # Don't put this on one line, you will fail... :)
    success &&= ret
  end

  success
ensure
  project.mode = nil
end

#run_test!(index) ⇒ Object

Run a specific test by stack index.



95
96
97
98
99
100
101
102
# File 'lib/roger/test.rb', line 95

def run_test!(index)
  test = @stack[index]
  if test
    call_test(test)
  else
    false
  end
end

#use(processor, options = {}) ⇒ Object

Use a certain test, this will also register it on the CLI if you supply a symbol.



71
72
73
74
75
76
77
# File 'lib/roger/test.rb', line 71

def use(processor, options = {})
  test = self.class.get_callable(processor, Roger::Test.map)
  if processor.is_a?(Symbol)
    register_in_cli(processor, @stack.size, self.class.cli_map[processor])
  end
  @stack << [test, options]
end