Class: CI::Reporter::RSpec

Inherits:
Spec::Runner::Formatter::BaseFormatter
  • Object
show all
Defined in:
lib/ci/reporter/rspec.rb

Overview

Custom RSpec formatter used to hook into the spec runs and capture results.

Direct Known Subclasses

RSpecDoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RSpec

Returns a new instance of RSpec.



45
46
47
48
49
50
# File 'lib/ci/reporter/rspec.rb', line 45

def initialize(*args)
  super
  @formatter ||= Spec::Runner::Formatter::ProgressBarFormatter.new(*args)
  @report_manager = ReportManager.new("spec")
  @suite = nil
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



44
45
46
# File 'lib/ci/reporter/rspec.rb', line 44

def formatter
  @formatter
end

#report_managerObject

Returns the value of attribute report_manager.



43
44
45
# File 'lib/ci/reporter/rspec.rb', line 43

def report_manager
  @report_manager
end

Instance Method Details

#add_behaviour(name) ⇒ Object

rspec 0.9



57
58
59
60
# File 'lib/ci/reporter/rspec.rb', line 57

def add_behaviour(name)
  @formatter.add_behaviour(name)
  new_suite(name)
end

#add_example_group(example_group) ⇒ Object

Compatibility with rspec < 1.2.4



63
64
65
66
# File 'lib/ci/reporter/rspec.rb', line 63

def add_example_group(example_group)
  @formatter.add_example_group(example_group)
  new_suite(example_group.description)
end

#closeObject



124
125
126
# File 'lib/ci/reporter/rspec.rb', line 124

def close
  @formatter.close
end

#dump_failure(*args) ⇒ Object



111
112
113
# File 'lib/ci/reporter/rspec.rb', line 111

def dump_failure(*args)
  @formatter.dump_failure(*args)
end

#dump_pendingObject



120
121
122
# File 'lib/ci/reporter/rspec.rb', line 120

def dump_pending
  @formatter.dump_pending
end

#dump_summary(*args) ⇒ Object



115
116
117
118
# File 'lib/ci/reporter/rspec.rb', line 115

def dump_summary(*args)
  @formatter.dump_summary(*args)
  write_report
end

#example_failed(name, counter, failure) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/ci/reporter/rspec.rb', line 82

def example_failed(name, counter, failure)
  @formatter.example_failed(name, counter, failure)
  # In case we fail in before(:all)
  if @suite.testcases.empty?
    example_started(name)
  end
  spec = @suite.testcases.last
  spec.finish
  spec.failures << RSpecFailure.new(failure)
end

#example_group_started(example_group) ⇒ Object

rspec >= 1.2.4



69
70
71
72
# File 'lib/ci/reporter/rspec.rb', line 69

def example_group_started(example_group)
  @formatter.example_group_started(example_group)
  new_suite(example_group.description)
end

#example_passed(name) ⇒ Object



93
94
95
96
97
# File 'lib/ci/reporter/rspec.rb', line 93

def example_passed(name)
  @formatter.example_passed(name)
  spec = @suite.testcases.last
  spec.finish
end

#example_pending(*args) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/ci/reporter/rspec.rb', line 99

def example_pending(*args)
  @formatter.example_pending(*args)
  spec = @suite.testcases.last
  spec.finish
  spec.name = "#{spec.name} (PENDING)"
  spec.skipped = true
end

#example_started(name) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/ci/reporter/rspec.rb', line 74

def example_started(name)
  @formatter.example_started(name)
  name = name.description if name.respond_to?(:description)
  spec = TestCase.new name
  @suite.testcases << spec
  spec.start
end

#start(spec_count) ⇒ Object



52
53
54
# File 'lib/ci/reporter/rspec.rb', line 52

def start(spec_count)
  @formatter.start(spec_count)
end

#start_dumpObject



107
108
109
# File 'lib/ci/reporter/rspec.rb', line 107

def start_dump
  @formatter.start_dump
end