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



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



68
69
70
# File 'lib/micron/runner/method.rb', line 68

def failed?
  !passed
end

#passed?Boolean



60
61
62
# File 'lib/micron/runner/method.rb', line 60

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
# 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) }

    time(:runtime) { t.send(name) }
    self.passed = true

  rescue *PASSTHROUGH_EXCEPTIONS
    raise

  rescue Exception => e
    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?
    }
  end
end

#skipped?Boolean



64
65
66
# File 'lib/micron/runner/method.rb', line 64

def skipped?
  ex.kind_of?(Skip)
end

#statusObject



72
73
74
75
76
77
78
79
80
# File 'lib/micron/runner/method.rb', line 72

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)



83
84
85
86
87
# File 'lib/micron/runner/method.rb', line 83

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