Class: Micron::Runner::TestFile

Inherits:
Object
  • Object
show all
Defined in:
lib/micron/runner/test_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, method_patterns) ⇒ TestFile

Returns a new instance of TestFile.



6
7
8
9
# File 'lib/micron/runner/test_file.rb', line 6

def initialize(filename, method_patterns)
  @filename        = filename
  @method_patterns = method_patterns
end

Instance Method Details

#collect_coverageObject

Simply load the file and collect coverage



25
26
27
28
29
30
31
32
# File 'lib/micron/runner/test_file.rb', line 25

def collect_coverage
  worker = ForkWorker.new do
    load(true)
    EasyCov.dump
  end
  worker.run
  worker.wait
end

#load(coverage = false) ⇒ Object

Load the test file



14
15
16
17
18
19
20
21
22
# File 'lib/micron/runner/test_file.rb', line 14

def load(coverage=false)
  if coverage then
    file = @filename
    EasyCov.filters << lambda { |f| f == file }
    EasyCov.start
  end
  require @filename
  return nil
end

#run(run_clazz) ⇒ Array<Object>

Execute the tests in the file, using the given Clazz

Parameters:

Returns:

  • (Array<Object>)

    array of Clazz and Exception objects



39
40
41
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
74
75
76
77
# File 'lib/micron/runner/test_file.rb', line 39

def run(run_clazz)

  results = []
  test_clazz = TestCase.subclasses.last

  # run before_class
  begin
    test_clazz.before_class
  rescue Exception => ex
    # skip rest of class on error
    return skip_all_tests(test_clazz, ex)
  end

  begin
    clazz = run_clazz.new(test_clazz, @filename, @method_patterns)

    Micron.runner.report(:start_class, clazz)
    if !clazz.methods.empty? then
      clazz.run
      results << clazz
    end

    # run after_class
    begin
      test_clazz.after_class
    rescue Exception => ex
      Micron.runner.report(:after_class_error, ex)
    end

    Micron.runner.report(:end_class, clazz)

  rescue Exception => ex
    # Error with loading the test class itself
    results << ex
    return results
  end

  return results
end

#run_method(test_clazz, test_method, run_clazz) ⇒ Method

Run the given test method

Parameters:

  • test_clazz (String)

    Name of the TestCase Class

  • test_method (String)

    Method name

  • run_clazz (Clazz)

    Clazz to run with

Returns:



86
87
88
89
90
91
92
# File 'lib/micron/runner/test_file.rb', line 86

def run_method(test_clazz, test_method, run_clazz)
  clazz = run_clazz.new(test_clazz, @filename)
  method = clazz.methods.find{ |m| m.name.to_s == test_method }
  method.run

  return method
end