Class: Roger::Test

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

Overview

The test class itself

Defined Under Namespace

Classes: Cli

Constant Summary

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::Logging

#debug, #log, #warn

Constructor Details

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



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

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.



29
30
31
# File 'lib/roger/test.rb', line 29

def config
  @config
end

#projectObject (readonly)

Returns the value of attribute project.



29
30
31
# File 'lib/roger/test.rb', line 29

def project
  @project
end

Class Method Details

.cli_mapObject

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



52
53
54
# File 'lib/roger/test.rb', line 52

def cli_map
  @_cli_map ||= {}
end

.mapObject

Mapping names to test callers



47
48
49
# File 'lib/roger/test.rb', line 47

def map
  @_map ||= {}
end

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

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



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

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

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

Instance Method Details

#get_files(globs, excludes = []) ⇒ Object

Get files from the project path



110
111
112
113
114
115
116
117
# File 'lib/roger/test.rb', line 110

def get_files(globs, excludes = [])
  files = globs.map { |g| Dir.glob(project.path + g) }.flatten
  if excludes.any?
    files.reject { |c| excludes.detect { |e| c.match(e) } }
  else
    files
  end
end

#run!Object

Run all tests and return true when succeeded



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

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.



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

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.



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

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