Class: Spec::Runner::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/runner/reporter.rb

Defined Under Namespace

Classes: Failure

Instance Method Summary collapse

Constructor Details

#initialize(formatter, backtrace_tweaker) ⇒ Reporter

Returns a new instance of Reporter.



5
6
7
8
9
10
11
# File 'lib/spec/runner/reporter.rb', line 5

def initialize(formatter, backtrace_tweaker)
  @formatter = formatter
  @context_names = []
  @failures = []
  @spec_names = []
  @backtrace_tweaker = backtrace_tweaker
end

Instance Method Details

#add_context(name) ⇒ Object



13
14
15
16
17
# File 'lib/spec/runner/reporter.rb', line 13

def add_context(name)
  #TODO - @context_names.empty? tells the formatter whether this is the first context or not - that's a little slippery
  @formatter.add_context(name, @context_names.empty?)
  @context_names << name
end

#dumpObject

Dumps the summary and returns the total number of failures



43
44
45
46
47
48
# File 'lib/spec/runner/reporter.rb', line 43

def dump
  @formatter.start_dump
  dump_failures
  @formatter.dump_summary(duration, @spec_names.length, @failures.length)
  @failures.length
end

#endObject



38
39
40
# File 'lib/spec/runner/reporter.rb', line 38

def end
  @end_time = Time.new
end

#spec_finished(name, error = nil, failure_location = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/spec/runner/reporter.rb', line 24

def spec_finished(name, error=nil, failure_location=nil)
  if error.nil?
    spec_passed(name)
  else
    @backtrace_tweaker.tweak_backtrace(error, failure_location)
    spec_failed(name, Failure.new(@context_names.last, name, error))
  end
end

#spec_started(name) ⇒ Object



19
20
21
22
# File 'lib/spec/runner/reporter.rb', line 19

def spec_started(name)
  @spec_names << name
  @formatter.spec_started(name)
end

#start(number_of_specs) ⇒ Object



33
34
35
36
# File 'lib/spec/runner/reporter.rb', line 33

def start(number_of_specs)
  @start_time = Time.new
  @formatter.start(number_of_specs)
end