Class: Aspec::TestRunner

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/aspec/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, paths) ⇒ TestRunner

Returns a new instance of TestRunner


8
9
10
11
# File 'lib/aspec/runner.rb', line 8

def initialize(config, paths)
  @paths = paths
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


6
7
8
# File 'lib/aspec/runner.rb', line 6

def config
  @config
end

#sourceObject (readonly)

Returns the value of attribute source


6
7
8
# File 'lib/aspec/runner.rb', line 6

def source
  @source
end

Instance Method Details

#before_eachObject


36
37
38
39
40
# File 'lib/aspec/runner.rb', line 36

def before_each
  if before_block = config.get_before
    before_block.call
  end
end

#formatterObject


21
22
23
# File 'lib/aspec/runner.rb', line 21

def formatter
  config.formatter
end

#run(lines) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/aspec/runner.rb', line 42

def run(lines)
  successes = 0
  failures = 0
  if lines.any?
    run_tests = tests.select {|test| lines.any? {|line_num| test.contains_line?(line_num)}}
  else
    run_tests = tests
  end

  run_tests.each do |test|
    before_each
    if test.run(config)
      successes += 1 unless test.comment_only?
      puts if verbose?
    else
      failures += 1
      puts
    end
    formatter.clear
  end
  color = send(failures > 0 ? :red : :green)
  formatter.dump_summary color + "#{successes} passed, #{failures} failed." + reset

  if after_suite_block = config.get_after_suite
    after_suite_block.call
  end

  failures
end

#slow?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/aspec/runner.rb', line 17

def slow?
  config.slow?
end

#testsObject


25
26
27
28
29
30
31
32
33
34
# File 'lib/aspec/runner.rb', line 25

def tests
  @tests ||= begin
    result = []
    @paths.each do |path|
      parser = Parser.new(File.read(path))
      result += parser.tests
    end
    result.flatten
  end
end

#verbose?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/aspec/runner.rb', line 13

def verbose?
  config.verbose?
end