Class: CI::Reporter::RSpec

Inherits:
RSpecFormatters::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.



66
67
68
69
70
71
# File 'lib/ci/reporter/rspec.rb', line 66

def initialize(*args)
  super
  @formatter ||= RSpecFormatters::ProgressFormatter.new(*args)
  @report_manager = ReportManager.new("spec")
  @suite = nil
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



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

def formatter
  @formatter
end

#report_managerObject

Returns the value of attribute report_manager.



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

def report_manager
  @report_manager
end

Instance Method Details

#add_behaviour(name) ⇒ Object

rspec 0.9



78
79
80
81
# File 'lib/ci/reporter/rspec.rb', line 78

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

#add_example_group(example_group) ⇒ Object

Compatibility with rspec < 1.2.4



84
85
86
87
# File 'lib/ci/reporter/rspec.rb', line 84

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

#closeObject



153
154
155
# File 'lib/ci/reporter/rspec.rb', line 153

def close
  @formatter.close
end

#dump_failure(*args) ⇒ Object



140
141
142
# File 'lib/ci/reporter/rspec.rb', line 140

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

#dump_pendingObject



149
150
151
# File 'lib/ci/reporter/rspec.rb', line 149

def dump_pending
  @formatter.dump_pending
end

#dump_summary(*args) ⇒ Object



144
145
146
147
# File 'lib/ci/reporter/rspec.rb', line 144

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

#example_failed(name_or_example, *rest) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ci/reporter/rspec.rb', line 102

def example_failed(name_or_example, *rest)
  @formatter.example_failed(name_or_example, *rest)

  # In case we fail in before(:all)
  example_started(name_or_example) if @suite.testcases.empty?

  if name_or_example.respond_to?(:execution_result) # RSpec 2
    failure = RSpec2Failure.new(name_or_example)
  else
    failure = RSpecFailure.new(rest[1]) # example_failed(name, counter, failure) in RSpec 1
  end

  spec = @suite.testcases.last
  spec.finish
  spec.name = description_for(name_or_example)
  spec.failures << failure
end

#example_group_started(example_group) ⇒ Object

rspec >= 1.2.4



90
91
92
93
# File 'lib/ci/reporter/rspec.rb', line 90

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

#example_passed(name_or_example) ⇒ Object



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

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

#example_pending(*args) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/ci/reporter/rspec.rb', line 127

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

#example_started(name_or_example) ⇒ Object



95
96
97
98
99
100
# File 'lib/ci/reporter/rspec.rb', line 95

def example_started(name_or_example)
  @formatter.example_started(name_or_example)
  spec = TestCase.new
  @suite.testcases << spec
  spec.start
end

#start(spec_count) ⇒ Object



73
74
75
# File 'lib/ci/reporter/rspec.rb', line 73

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

#start_dumpObject



136
137
138
# File 'lib/ci/reporter/rspec.rb', line 136

def start_dump
  @formatter.start_dump
end