Permalink
Browse files

- Make builder dependency explicit

- Allow multiple failures per testcase


git-svn-id: http://svn.caldersphere.net/svn/main/rubyforge/ci_reporter/trunk@174 b03c2d0b-2f10-0410-a2f9-fc8001506dfa
  • Loading branch information...
1 parent 138c9b9 commit 1f39c76294c9520d933b5b16b2eb5fc7ccd0c643 @nicksieger nicksieger committed Nov 22, 2007
View
@@ -1,3 +1,8 @@
+== 1.3.6
+
+- Explicit dependency requirement on Builder
+- Test::Unit tests that fail in multiple places (setup, test method, and teardown) are now tracked
+
== 1.3.5
- Change way we append to environment variables to appease windows (Tracker #13998, Adam Anderson)
View
@@ -1,12 +1,13 @@
require 'spec/rake/spectask'
+require 'spec/rake/verify_rcov'
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "LICENSE.txt", "Rakefile",
"*.rake", "lib/**/*.rb", "spec/**/*.rb", "tasks/**/*.rake"]
-require File.dirname(__FILE__) + '/lib/ci/reporter/version'
begin
- touch("Manifest.txt") unless File.exist?("Manifest.txt")
+ File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
require 'hoe'
+ require File.dirname(__FILE__) + '/lib/ci/reporter/version'
hoe = Hoe.new("ci_reporter", CI::Reporter::VERSION) do |p|
p.rubyforge_name = "caldersphere"
p.url = "http://caldersphere.rubyforge.org/ci_reporter"
@@ -17,6 +18,7 @@ begin
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
p.extra_deps.reject!{|d| d.first == "hoe"}
p.test_globs = ["spec/**/*_spec.rb"]
+ p.extra_deps << ['builder', ">= 2.1.2"]
end
hoe.spec.files = MANIFEST
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
@@ -28,16 +30,24 @@ end
# !@#$ no easy way to empty the default list of prerequisites
Rake::Task['default'].send :instance_variable_set, "@prerequisites", FileList[]
-task :default => :spec
+task :default => :rcov
Spec::Rake::SpecTask.new do |t|
t.spec_opts ||= []
t.spec_opts << "--diff" << "unified"
end
-# Automated manifest
-task :manifest do
- File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
+Spec::Rake::SpecTask.new("spec:rcov") do |t|
+ t.rcov = true
end
-
-task :package => :manifest
+# so we don't confuse autotest
+RCov::VerifyTask.new(:rcov) do |t|
+ # Can't get threshold up to 100 until the RSpec < 1.0 compatibility
+ # code is dropped
+ t.threshold = 97
+ t.require_exact_threshold = false
+end
+task "spec:rcov" do
+ rm_f "Manifest.txt"
+end
+task :rcov => "spec:rcov"
@@ -136,7 +136,7 @@ def case_started(name)
def case_failed(name, counter, failure)
spec = @suite.testcases.last
spec.finish
- spec.failure = RSpecFailure.new(failure)
+ spec.failures << RSpecFailure.new(failure)
end
def case_passed(name)
@@ -57,25 +57,17 @@ def start
def finish
self.tests = testcases.size
self.time = Time.now - @start
- self.failures = testcases.select {|tc| tc.failure? }.size
- self.errors = testcases.select {|tc| tc.error? }.size
+ self.failures = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.failure? }.size }
+ self.errors = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.error? }.size }
self.stdout = @capture_out.finish if @capture_out
self.stderr = @capture_err.finish if @capture_err
end
# Creates the xml builder instance used to create the report xml document.
def create_builder
- begin
- gem 'builder'
- require 'builder'
- rescue
- begin
- gem 'activesupport'
- require 'active_support'
- rescue
- raise LoadError, "XML Builder is required by CI::Reporter"
- end
- end unless defined?(Builder::XmlMarkup)
+ require 'rubygems'
+ gem 'builder'
+ require 'builder'
# :escape_attrs is obsolete in a newer version, but should do no harm
Builder::XmlMarkup.new(:indent => 2, :escape_attrs => true)
end
@@ -84,14 +76,8 @@ def create_builder
def to_xml
builder = create_builder
# more recent version of Builder doesn't need the escaping
- if Builder::XmlMarkup.private_instance_methods.include?("_attr_value")
- def builder.trunc!(txt)
- txt.sub(/\n.*/m, '...')
- end
- else
- def builder.trunc!(txt)
- _escape(txt.sub(/\n.*/m, '...'))
- end
+ def builder.trunc!(txt)
+ txt.sub(/\n.*/m, '...')
end
builder.instruct!
attrs = {}
@@ -112,7 +98,12 @@ def builder.trunc!(txt)
# Structure used to represent an individual test case. Used to time the test and store the result.
class TestCase < Struct.new(:name, :time, :assertions)
- attr_accessor :failure
+ attr_accessor :failures
+
+ def initialize(*args)
+ super
+ @failures = []
+ end
# Starts timing the test.
def start
@@ -126,20 +117,20 @@ def finish
# Returns non-nil if the test failed.
def failure?
- failure && failure.failure?
+ !failures.empty? && failures.detect {|f| f.failure? }
end
# Returns non-nil if the test had an error.
def error?
- failure && failure.error?
+ !failures.empty? && failures.detect {|f| f.error? }
end
# Writes xml representing the test result to the provided builder.
def to_xml(builder)
attrs = {}
each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty?}
builder.testcase(attrs) do
- if failure
+ failures.each do |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)
@@ -74,7 +74,8 @@ def test_finished(name)
end
def fault(fault)
- finish_test(fault)
+ tc = @current_suite.testcases.last
+ tc.failures << Failure.new(fault)
end
def finished(elapsed_time)
@@ -112,10 +113,9 @@ def start_test(test_name)
@current_suite.testcases << tc
end
- def finish_test(failure = nil)
+ def finish_test
tc = @current_suite.testcases.last
tc.finish
- tc.failure = Failure.new(failure) if failure
tc.assertions = @suite_result.assertion_count - @result_assertion_count
@result_assertion_count = @suite_result.assertion_count
end
@@ -1,5 +1,5 @@
module CI
module Reporter
- VERSION = "1.3.5"
+ VERSION = "1.3.6"
end
end
@@ -8,13 +8,6 @@
describe "The RSpec reporter" do
before(:each) do
@error = mock("error")
- @error.stub!(:exception).and_return do
- begin
- raise StandardError, "error message"
- rescue => e
- e
- end
- end
@error.stub!(:expectation_not_met?).and_return(false)
@error.stub!(:pending_fixed?).and_return(false)
@report_mgr = mock("report manager")
@@ -41,9 +41,9 @@ def name.to_s; "object name"; end
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
- @suite.testcases.last.failure = failure
+ @suite.testcases.last.failures << failure
@suite.testcases << CI::Reporter::TestCase.new("error test")
- @suite.testcases.last.failure = error
+ @suite.testcases.last.failures << error
@suite.finish
@suite.tests.should == 3
@suite.failures.should == 1
@@ -80,9 +80,9 @@ def name.to_s; "object name"; end
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
- @suite.testcases.last.failure = failure
+ @suite.testcases.last.failures << failure
@suite.testcases << CI::Reporter::TestCase.new("error test")
- @suite.testcases.last.failure = error
+ @suite.testcases.last.failures << error
@suite.finish
xml = @suite.to_xml
@@ -108,7 +108,7 @@ def name.to_s; "object name"; end
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.testcases << CI::Reporter::TestCase.new("failure test")
- @suite.testcases.last.failure = failure
+ @suite.testcases.last.failures << failure
@suite.finish
xml = @suite.to_xml
@@ -129,7 +129,7 @@ def name.to_s; "object name"; end
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("failure test")
- @suite.testcases.last.failure = failure
+ @suite.testcases.last.failures << failure
@suite.finish
xml = @suite.to_xml
@@ -69,6 +69,24 @@
end
it "should add failures to testcases when encountering a fault" do
+ @failure = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:10", "it failed")
+
+ @suite = nil
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
+
+ @testunit.started(@result)
+ @testunit.test_started("test_one(TestCaseClass)")
+ @testunit.fault(@failure)
+ @testunit.test_finished("test_one(TestCaseClass)")
+ @testunit.finished(10)
+
+ @suite.name.should == "TestCaseClass"
+ @suite.testcases.length.should == 1
+ @suite.testcases.first.name.should == "test_one"
+ @suite.testcases.first.should be_failure
+ end
+
+ it "should add errors to testcases when encountering a fault" do
begin
raise StandardError, "error"
rescue => e
@@ -83,6 +101,7 @@
@testunit.test_finished("test_one(TestCaseClass)")
@testunit.test_started("test_two(TestCaseClass)")
@testunit.fault(@error)
+ @testunit.test_finished("test_two(TestCaseClass)")
@testunit.finished(10)
@suite.name.should == "TestCaseClass"
@@ -94,4 +113,40 @@
@suite.testcases.last.should_not be_failure
@suite.testcases.last.should be_error
end
+
+ it "should add multiple failures to a testcase" do
+ @failure1 = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:10", "it failed")
+ @failure2 = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:12", "it failed again in teardown")
+
+ @suite = nil
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
+
+ @testunit.started(@result)
+ @testunit.test_started("test_one(TestCaseClass)")
+ @testunit.fault(@failure1)
+ @testunit.fault(@failure2)
+ @testunit.test_finished("test_one(TestCaseClass)")
+ @testunit.finished(10)
+
+ @suite.name.should == "TestCaseClass"
+ @suite.testcases.length.should == 1
+ @suite.testcases.first.name.should == "test_one"
+ @suite.testcases.first.should be_failure
+ @suite.testcases.first.failures.size.should == 2
+ @suite.failures.should == 2
+ end
+
+ it "should count test case names that don't conform to the standard pattern" do
+ @suite = nil
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
+
+ @testunit.started(@result)
+ @testunit.test_started("some unknown test")
+ @testunit.test_finished("some unknown test")
+ @testunit.finished(10)
+
+ @suite.name.should == "unknown-1"
+ @suite.testcases.length.should == 1
+ @suite.testcases.first.name.should == "some unknown test"
+ end
end

0 comments on commit 1f39c76

Please sign in to comment.