Skip to content

Commit

Permalink
Preparing for 1.3 release
Browse files Browse the repository at this point in the history
- Include full message in failure/error stack trace
- RSpec 0.9 compatibility


git-svn-id: http://svn.caldersphere.net/svn/main/rubyforge/ci_reporter/trunk@93 b03c2d0b-2f10-0410-a2f9-fc8001506dfa
  • Loading branch information
nicksieger committed May 17, 2007
1 parent 6dfadcd commit 68aca7c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 19 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
== 1.3

- Fixed to be compatible with RSpec 0.9
- Failure location text now contains both the exception message and class name (in case the type and message attributes were truncated)

== 1.2.4

- Allow to report on RSpec specs when working with non-gem RSpec
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Expand Up @@ -4,7 +4,7 @@ require 'hoe'
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "LICENSE.txt", "Rakefile",
"lib/**/*.rb", "spec/**/*.rb", "tasks/**/*.rake"]

Hoe.new("ci_reporter", "1.2.5") do |p|
Hoe.new("ci_reporter", "1.3") do |p|
p.rubyforge_name = "caldersphere"
p.url = "http://caldersphere.rubyforge.org/ci_reporter"
p.author = "Nick Sieger"
Expand All @@ -23,7 +23,8 @@ Rake::Task['default'].send :instance_variable_set, "@prerequisites", FileList[]
task :default => :spec

Spec::Rake::SpecTask.new do |t|
t.spec_opts = ["--diff", "unified"]
t.spec_opts ||= []
t.spec_opts << "--diff" << "unified"
end

# Automated manifest
Expand Down
2 changes: 1 addition & 1 deletion lib/ci/reporter/rake/rspec.rb
Expand Up @@ -7,7 +7,7 @@
task :rspec do
rm_rf ENV["CI_REPORTS"] || "spec/reports"
ENV["RSPECOPTS"] ||= ""
ENV["RSPECOPTS"] += [" --require", "#{File.dirname(__FILE__)}/rspec_loader.rb",
ENV["RSPECOPTS"] << [" --require", "#{File.dirname(__FILE__)}/rspec_loader.rb",
"--format", "CI::Reporter::RSpec"].join(" ")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ci/reporter/rake/test_unit.rb
Expand Up @@ -7,7 +7,7 @@
task :testunit do
rm_rf ENV["CI_REPORTS"] || "test/reports"
ENV["TESTOPTS"] ||= ""
ENV["TESTOPTS"] += " #{File.dirname(__FILE__)}/test_unit_loader.rb"
ENV["TESTOPTS"] << " #{File.dirname(__FILE__)}/test_unit_loader.rb"
end
end
end
78 changes: 64 additions & 14 deletions lib/ci/reporter/rspec.rb
Expand Up @@ -6,7 +6,7 @@
begin
gem 'rspec'
rescue Gem::LoadError
# Needed for non-gem RSpec (e.g., reporting on RSpec's own specs);
# Needed for non-gem RSpec (e.g., reporting on RSpec's own specs);
# if spec isn't found, the next require will blow up
end
require 'spec'
Expand Down Expand Up @@ -35,7 +35,13 @@ def location() @failure.exception.backtrace.join("\n") end
# Custom +RSpec+ formatter used to hook into the spec runs and capture results.
class RSpec < Spec::Runner::Formatter::ProgressBarFormatter
def initialize(output, dry_run=false, colour=false, report_mgr=nil)
super(output, dry_run, colour)
if respond_to? :dry_run=
super(output)
self.dry_run=dry_run
self.colour=colour
else
super(output, dry_run, colour)
end
@report_manager = report_mgr || ReportManager.new("spec")
@suite = nil
end
Expand All @@ -44,31 +50,52 @@ def start(spec_count)
super
end

# Pre-0.9 hook
def add_context(name, first)
super
write_report if @suite
@suite = TestSuite.new name
@suite.start
new_suite(name)
end

# Post-0.9 hook
def add_behaviour(name)
super
new_suite(name)
end

# Pre-0.9 hook
def spec_started(name)
super
spec = TestCase.new name
@suite.testcases << spec
spec.start
case_started(name)
end

# Post-0.9 hook
def example_started(name)
super
case_started(name)
end

# Pre-0.9 hook
def spec_failed(name, counter, failure)
super
spec = @suite.testcases.last
spec.finish
spec.failure = RSpecFailure.new(failure)
case_failed(name, counter, failure)
end

# Post-0.9 hook
def example_failed(name, counter, failure)
super
case_failed(name, counter, failure)
end

# Pre-0.9 hook
def spec_passed(name)
super
spec = @suite.testcases.last
spec.finish
case_passed(name)
end

# Post-0.9 hook
def example_passed(name)
super
case_passed(name)
end

def start_dump
Expand All @@ -79,7 +106,7 @@ def dump_failure(counter, failure)
super
end

def dump_summary(duration, spec_count, failure_count)
def dump_summary(duration, example_count, failure_count)
super
write_report
end
Expand All @@ -89,6 +116,29 @@ def write_report
@suite.finish
@report_manager.write_report(@suite)
end

def new_suite(name)
write_report if @suite
@suite = TestSuite.new name
@suite.start
end

def case_started(name)
spec = TestCase.new name
@suite.testcases << spec
spec.start
end

def case_failed(name, counter, failure)
spec = @suite.testcases.last
spec.finish
spec.failure = RSpecFailure.new(failure)
end

def case_passed(name)
spec = @suite.testcases.last
spec.finish
end
end
end
end
1 change: 1 addition & 0 deletions lib/ci/reporter/test_suite.rb
Expand Up @@ -141,6 +141,7 @@ def to_xml(builder)
builder.testcase(attrs) do
if failure
builder.failure(:type => builder.trunc!(failure.name), :message => builder.trunc!(failure.message)) do
builder.text!(failure.message + " (#{failure.name})\n")
builder.text!(failure.location)
end
end
Expand Down
24 changes: 23 additions & 1 deletion spec/ci/reporter/test_suite_spec.rb
Expand Up @@ -91,7 +91,29 @@
testcases = testsuite.elements.to_a("testcase")
testcases.length.should == 3
end


specify "should contain full exception type and message in location element" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
failure.stub!(:name).and_return "failure"
failure.stub!(:message).and_return "There was a failure"
failure.stub!(:location).and_return @exception.backtrace.join("\n")

@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
@suite.testcases.last.failure = failure
@suite.finish

xml = @suite.to_xml
doc = REXML::Document.new(xml)
elem = doc.root.elements.to_a("/testsuite/testcase[@name='failure test']/failure").first
location = elem.texts.join
location.should =~ Regexp.new(failure.message)
location.should =~ Regexp.new(failure.name)
end

specify "should filter attributes properly for invalid characters" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
Expand Down

0 comments on commit 68aca7c

Please sign in to comment.