class CI::Reporter::RSpec
Custom RSpec
formatter used to hook into the spec runs and
capture results.
Attributes
formatter[RW]
report_manager[RW]
Public Class Methods
new(*args)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 99 def initialize(*args) @formatter ||= RSpecFormatters::ProgressFormatter.new(*args) @report_manager = ReportManager.new("spec") @suite = nil end
Public Instance Methods
add_behaviour(name)
click to toggle source
rspec 0.9
# File lib/ci/reporter/rspec.rb, line 106 def add_behaviour(name) @formatter.add_behaviour(name) new_suite(name) end
add_example_group(example_group)
click to toggle source
Compatibility with rspec < 1.2.4
# File lib/ci/reporter/rspec.rb, line 112 def add_example_group(example_group) @formatter.add_example_group(example_group) new_suite(description_for(example_group)) end
dump_summary(*args)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 164 def dump_summary(*args) @formatter.dump_summary(*args) write_report @formatter.dump_failures end
example_failed(name_or_example, *rest)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 130 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, @formatter) 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)
click to toggle source
rspec >= 1.2.4
# File lib/ci/reporter/rspec.rb, line 118 def example_group_started(example_group) @formatter.example_group_started(example_group) new_suite(description_for(example_group)) end
example_passed(name_or_example)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 148 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)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 155 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)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 123 def example_started(name_or_example) @formatter.example_started(name_or_example) spec = TestCase.new @suite.testcases << spec spec.start end
method_missing(meth,*args,&block)
click to toggle source
Pass through other methods to RSpec formatter for compatibility
# File lib/ci/reporter/rspec.rb, line 175 def method_missing(meth,*args,&block) @formatter.send(meth,*args,&block) end
respond_to?(*args)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 170 def respond_to?(*args) @formatter.respond_to?(*args) end
Private Instance Methods
description_for(name_or_example)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 180 def description_for(name_or_example) if name_or_example.respond_to?(:full_description) name_or_example.full_description elsif name_or_example.respond_to?(:metadata) name_or_example.metadata[:example_group][:full_description] elsif name_or_example.respond_to?(:description) name_or_example.description else "UNKNOWN" end end
new_suite(name)
click to toggle source
# File lib/ci/reporter/rspec.rb, line 199 def new_suite(name) write_report if @suite @suite = TestSuite.new name @suite.start end
write_report()
click to toggle source
# File lib/ci/reporter/rspec.rb, line 192 def write_report if @suite @suite.finish @report_manager.write_report(@suite) end end