Class: Aspec::TestRunner
- Inherits:
-
Object
- Object
- Aspec::TestRunner
- Includes:
- Term::ANSIColor
- Defined in:
- lib/aspec/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #before_each ⇒ Object
- #formatter ⇒ Object
-
#initialize(config, paths) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #run(lines) ⇒ Object
- #slow? ⇒ Boolean
- #tests ⇒ Object
- #verbose? ⇒ Boolean
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/aspec/runner.rb', line 6 def config @config end |
#source ⇒ Object (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_each ⇒ Object
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 |
#formatter ⇒ Object
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 71 72 73 |
# 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 if failures > 0 exit(1) else exit(0) end end |
#slow? ⇒ Boolean
17 18 19 |
# File 'lib/aspec/runner.rb', line 17 def slow? config.slow? end |
#tests ⇒ Object
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
13 14 15 |
# File 'lib/aspec/runner.rb', line 13 def verbose? config.verbose? end |