Class: Micron::Runner::Method

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz, name) ⇒ Method

Returns a new instance of Method.



12
13
14
15
16
17
18
19
# File 'lib/micron/runner/method.rb', line 12

def initialize(clazz, name)
  @passed    = false
  @durations = {}
  @assertions = 0

  @clazz     = clazz
  @name      = name
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions.



9
10
11
# File 'lib/micron/runner/method.rb', line 9

def assertions
  @assertions
end

#clazzObject (readonly)

Returns the value of attribute clazz.



8
9
10
# File 'lib/micron/runner/method.rb', line 8

def clazz
  @clazz
end

#durationsObject (readonly)

Returns the value of attribute durations.



8
9
10
# File 'lib/micron/runner/method.rb', line 8

def durations
  @durations
end

#exObject

Returns the value of attribute ex.



9
10
11
# File 'lib/micron/runner/method.rb', line 9

def ex
  @ex
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/micron/runner/method.rb', line 8

def name
  @name
end

#passedObject

Returns the value of attribute passed.



9
10
11
# File 'lib/micron/runner/method.rb', line 9

def passed
  @passed
end

#stderrObject (readonly)

Returns the value of attribute stderr.



10
11
12
# File 'lib/micron/runner/method.rb', line 10

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



10
11
12
# File 'lib/micron/runner/method.rb', line 10

def stdout
  @stdout
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/micron/runner/method.rb', line 74

def failed?
  !passed
end

#passed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/micron/runner/method.rb', line 66

def passed?
  passed
end

#runObject



21
22
23
24
25
26
27
28
# File 'lib/micron/runner/method.rb', line 21

def run
  out, err = Micron.capture_io {
    run_test()
  }
  @stdout = out
  @stderr = err
  nil
end

#run_testObject

Execute the actual test



31
32
33
34
35
36
37
38
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
# File 'lib/micron/runner/method.rb', line 31

def run_test
  t = nil

  begin
    t = clazz.create
    if t.respond_to? :micron_method= then
      t.micron_method = self # minitest compat shim
    end

    time(:setup)   { setup(t) }

    # run actual test method and measure runtime
    @runtime = Hitimes::Interval.now
    t.send(name)
    @durations[:runtime] = @runtime.stop
    self.passed = true

  rescue *PASSTHROUGH_EXCEPTIONS
    @durations[:runtime] = @runtime.stop if @runtime
    raise

  rescue Exception => e
    @durations[:runtime] = @runtime.stop if @runtime
    self.passed = false
    self.ex     = ExceptionInfo.new(e)

  ensure
    self.assertions += t._assertions if not t.nil?
    time(:teardown) {
      teardown(t) if not t.nil?
    }
    @runtime = nil
  end
end

#skipped?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/micron/runner/method.rb', line 70

def skipped?
  ex.kind_of?(Skip)
end

#statusObject



78
79
80
81
82
83
84
85
86
# File 'lib/micron/runner/method.rb', line 78

def status
  if skipped? then
    "skip"
  elsif passed? then
    "pass"
  else
    "fail"
  end
end

#total_durationObject

Get the total duration of this method’s run (setup + runtime + teardown)



89
90
91
92
93
# File 'lib/micron/runner/method.rb', line 89

def total_duration
  n = 0.0
  @durations.values.each{ |d| n += d }
  n
end