class Roger::Test

The test class itself

Attributes

config[R]
project[R]

Public Class Methods

cli_map() click to toggle source

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

# File lib/roger/test.rb, line 54
def cli_map
  @_cli_map ||= {}
end
map() click to toggle source

Mapping names to test callers

# File lib/roger/test.rb, line 49
def map
  @_map ||= {}
end
new(project, config = {}) click to toggle source
# File lib/roger/test.rb, line 59
def initialize(project, config = {})
  defaults = {}

  @config = {}.update(defaults).update(config)
  @project = project
  @stack = []
end
register(name, test, cli = nil) click to toggle source

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

# 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

Public Instance Methods

run!() click to toggle source

Run all tests and return true when succeeded

# 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) click to toggle source

Run a specific test by stack index.

# 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 = {}) click to toggle source

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

@examples

test.use :jshint, config
# 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

Protected Instance Methods

call_test(task) click to toggle source
# File lib/roger/test.rb, line 110
def call_test(task)
  if task.is_a?(Array)
    task[0].call(self, task[1])
  else
    task.call(self)
  end
end
get_files_default_path() click to toggle source
# File lib/roger/test.rb, line 106
def get_files_default_path
  project.path
end
register_in_cli(name, stack_index, klass) click to toggle source
# File lib/roger/test.rb, line 118
def register_in_cli(name, stack_index, klass)
  long_desc = "Run #{name} tests"

  if klass && klass.is_a?(Class) && klass <= Roger::Test::Cli
    usage = "#{name} #{klass.arguments.map(&:banner).join(' ')}"
    thor_class = klass
  else
    usage = name.to_s
    thor_class = Class.new(Roger::Test::Cli)
  end

  if thor_class.respond_to?(:stack_index=)
    thor_class.stack_index = stack_index
  end

  Roger::Cli::Test.register thor_class, name, usage, long_desc
end