forked from ci-reporter/ci_reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Major refactoring -- split out reporting core from RSpec
so we can write a JUnit reporter also git-svn-id: http://svn.caldersphere.net/svn/main/ci_reporter@53 b03c2d0b-2f10-0410-a2f9-fc8001506dfa
- Loading branch information
1 parent
63fb705
commit b8a4915
Showing
14 changed files
with
314 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'ci/reporter/test_suite' | ||
require 'ci/reporter/report_manager' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'fileutils' | ||
|
||
module CI | ||
module Reporter | ||
class ReportManager | ||
def initialize(prefix="test") | ||
@basedir = ENV['CI_REPORTS'] || File.expand_path("#{Dir.getwd}/#{prefix.downcase}/reports") | ||
@basename = "#{@basedir}/#{prefix.upcase}" | ||
FileUtils.mkdir_p(@basedir) | ||
end | ||
|
||
def write_report(suite) | ||
File.open("#{@basename}-#{suite.name.gsub(/[^a-zA-Z0-9]+/, '-')}.xml", "w") do |f| | ||
f << suite.to_xml | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'ci/reporter/core' | ||
|
||
module CI | ||
module Reporter | ||
class RSpecFailure | ||
def initialize(failure) | ||
@failure = failure | ||
end | ||
|
||
def failure? | ||
@failure.expectation_not_met? | ||
end | ||
|
||
def error? | ||
!@failure.expectation_not_met? | ||
end | ||
|
||
def exception | ||
@failure.exception | ||
end | ||
end | ||
|
||
class RSpec < Spec::Runner::Formatter::ProgressBarFormatter | ||
def initialize(output, dry_run=false, colour=false, report_mgr=nil) | ||
super(output, dry_run, colour) | ||
@report_manager = report_mgr || ReportManager.new("spec") | ||
@suite = nil | ||
end | ||
|
||
def start(spec_count) | ||
super | ||
end | ||
|
||
def add_context(name, first) | ||
super | ||
write_report if @suite | ||
@suite = TestSuite.new name | ||
@suite.start | ||
end | ||
|
||
def spec_started(name) | ||
super | ||
spec = TestCase.new name | ||
@suite.testcases << spec | ||
spec.start | ||
end | ||
|
||
def spec_failed(name, counter, failure) | ||
super | ||
spec = @suite.testcases.last | ||
spec.finish | ||
spec.failure = RSpecFailure.new(failure) | ||
end | ||
|
||
def spec_passed(name) | ||
super | ||
spec = @suite.testcases.last | ||
spec.finish | ||
end | ||
|
||
def start_dump | ||
super | ||
end | ||
|
||
def dump_failure(counter, failure) | ||
super | ||
end | ||
|
||
def dump_summary(duration, spec_count, failure_count) | ||
super | ||
write_report | ||
end | ||
|
||
private | ||
def write_report | ||
@suite.finish | ||
@report_manager.write_report(@suite) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module CI | ||
module Reporter | ||
class TestUnitFailure | ||
def failure? | ||
|
||
end | ||
|
||
def error? | ||
|
||
end | ||
|
||
def exception | ||
|
||
end | ||
end | ||
|
||
class TestUnit | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require File.dirname(__FILE__) + "/../../spec_helper.rb" | ||
|
||
context "The ReportManager" do | ||
setup do | ||
@reports_dir = REPORTS_DIR | ||
end | ||
|
||
teardown do | ||
FileUtils.rm_rf @reports_dir | ||
ENV["CI_REPORTS"] = nil | ||
end | ||
|
||
specify "should create the report directory according to the given prefix" do | ||
CI::Reporter::ReportManager.new("spec") | ||
File.directory?(@reports_dir).should_be true | ||
end | ||
|
||
specify "should create the report directory based on CI_REPORTS environment variable if set" do | ||
@reports_dir = "#{Dir.getwd}/dummy" | ||
ENV["CI_REPORTS"] = @reports_dir | ||
CI::Reporter::ReportManager.new("spec") | ||
File.directory?(@reports_dir).should_be true | ||
end | ||
|
||
specify "should write reports based on name and xml content of a test suite" do | ||
reporter = CI::Reporter::ReportManager.new("spec") | ||
suite = mock("test suite") | ||
suite.should_receive(:name).and_return("some test suite name") | ||
suite.should_receive(:to_xml).and_return("<xml></xml>") | ||
reporter.write_report(suite) | ||
filename = "#{REPORTS_DIR}/SPEC-some-test-suite-name.xml" | ||
File.exist?(filename).should_be true | ||
File.open(filename) {|f| f.read.should == "<xml></xml>"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require File.dirname(__FILE__) + "/../../spec_helper.rb" | ||
require 'stringio' | ||
|
||
context "The RSpec reporter" do | ||
setup 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) | ||
@report_mgr = mock("report manager") | ||
@fmt = CI::Reporter::RSpec.new(StringIO.new(""), false, false, @report_mgr) | ||
end | ||
|
||
specify "should create a test suite with one success and one failure" do | ||
@report_mgr.should_receive(:write_report).and_return do |suite| | ||
suite.testcases.length.should == 2 | ||
suite.testcases.first.should_not_be_failure | ||
suite.testcases.first.should_not_be_error | ||
suite.testcases.last.should_be_error | ||
end | ||
|
||
@fmt.start(2) | ||
@fmt.add_context("A context", true) | ||
@fmt.spec_started("should pass") | ||
@fmt.spec_passed("should pass") | ||
@fmt.spec_started("should fail") | ||
@fmt.spec_failed("should fail", 1, @error) | ||
@fmt.dump_summary(0.1, 2, 1) | ||
end | ||
end |
Oops, something went wrong.