timfel-ci_reporter 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,151 @@
1
+ # Copyright (c) 2006-2010 Nick Sieger <nicksieger@gmail.com>
2
+ # See the file LICENSE.txt included with the distribution for
3
+ # software license details.
4
+
5
+ require File.dirname(__FILE__) + "/../../spec_helper.rb"
6
+ require 'rexml/document'
7
+
8
+ describe "A TestSuite" do
9
+ before(:each) do
10
+ @suite = CI::Reporter::TestSuite.new("example suite")
11
+ end
12
+
13
+ it "should collect timings when start and finish are invoked in sequence" do
14
+ @suite.start
15
+ @suite.finish
16
+ @suite.time.should >= 0
17
+ end
18
+
19
+ it "should aggregate tests" do
20
+ @suite.start
21
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
22
+ @suite.finish
23
+ @suite.tests.should == 1
24
+ end
25
+
26
+ it "should stringify the name for cases when the object passed in is not a string" do
27
+ name = Object.new
28
+ def name.to_s; "object name"; end
29
+ CI::Reporter::TestSuite.new(name).name.should == "object name"
30
+ end
31
+
32
+ it "should indicate number of failures and errors" do
33
+ failure = mock("failure")
34
+ failure.stub!(:failure?).and_return true
35
+ failure.stub!(:error?).and_return false
36
+
37
+ error = mock("error")
38
+ error.stub!(:failure?).and_return false
39
+ error.stub!(:error?).and_return true
40
+
41
+ @suite.start
42
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
43
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
44
+ @suite.testcases.last.failures << failure
45
+ @suite.testcases << CI::Reporter::TestCase.new("error test")
46
+ @suite.testcases.last.failures << error
47
+ @suite.finish
48
+ @suite.tests.should == 3
49
+ @suite.failures.should == 1
50
+ @suite.errors.should == 1
51
+ end
52
+ end
53
+
54
+ describe "TestSuite xml" do
55
+ before(:each) do
56
+ @suite = CI::Reporter::TestSuite.new("example suite")
57
+ @suite.assertions = 11
58
+ begin
59
+ raise StandardError, "an exception occurred"
60
+ rescue => e
61
+ @exception = e
62
+ end
63
+ end
64
+
65
+ it "should contain Ant/JUnit-formatted description of entire suite" do
66
+ failure = mock("failure")
67
+ failure.stub!(:failure?).and_return true
68
+ failure.stub!(:error?).and_return false
69
+ failure.stub!(:name).and_return "failure"
70
+ failure.stub!(:message).and_return "There was a failure"
71
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
72
+
73
+ error = mock("error")
74
+ error.stub!(:failure?).and_return false
75
+ error.stub!(:error?).and_return true
76
+ error.stub!(:name).and_return "error"
77
+ error.stub!(:message).and_return "There was a error"
78
+ error.stub!(:location).and_return @exception.backtrace.join("\n")
79
+
80
+ @suite.start
81
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
82
+ @suite.testcases << CI::Reporter::TestCase.new("skipped test").tap {|tc| tc.skipped = true }
83
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
84
+ @suite.testcases.last.failures << failure
85
+ @suite.testcases << CI::Reporter::TestCase.new("error test")
86
+ @suite.testcases.last.failures << error
87
+ @suite.finish
88
+
89
+ xml = @suite.to_xml
90
+ doc = REXML::Document.new(xml)
91
+ testsuite = doc.root.elements.to_a("/testsuite")
92
+ testsuite.length.should == 1
93
+ testsuite = testsuite.first
94
+ testsuite.attributes["name"].should == "example suite"
95
+ testsuite.attributes["assertions"].should == "11"
96
+
97
+ testcases = testsuite.elements.to_a("testcase")
98
+ testcases.length.should == 4
99
+ end
100
+
101
+ it "should contain full exception type and message in location element" do
102
+ failure = mock("failure")
103
+ failure.stub!(:failure?).and_return true
104
+ failure.stub!(:error?).and_return false
105
+ failure.stub!(:name).and_return "failure"
106
+ failure.stub!(:message).and_return "There was a failure"
107
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
108
+
109
+ @suite.start
110
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
111
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
112
+ @suite.testcases.last.failures << failure
113
+ @suite.finish
114
+
115
+ xml = @suite.to_xml
116
+ doc = REXML::Document.new(xml)
117
+ elem = doc.root.elements.to_a("/testsuite/testcase[@name='failure test']/failure").first
118
+ location = elem.texts.join
119
+ location.should =~ Regexp.new(failure.message)
120
+ location.should =~ Regexp.new(failure.name)
121
+ end
122
+
123
+ it "should filter attributes properly for invalid characters" do
124
+ failure = mock("failure")
125
+ failure.stub!(:failure?).and_return true
126
+ failure.stub!(:error?).and_return false
127
+ failure.stub!(:name).and_return "failure"
128
+ failure.stub!(:message).and_return "There was a <failure>\nReason: blah"
129
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
130
+
131
+ @suite.start
132
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
133
+ @suite.testcases.last.failures << failure
134
+ @suite.finish
135
+
136
+ xml = @suite.to_xml
137
+ xml.should =~ %r/message="There was a &lt;failure&gt;\.\.\."/
138
+ end
139
+ end
140
+
141
+ describe "A TestCase" do
142
+ before(:each) do
143
+ @tc = CI::Reporter::TestCase.new("example test")
144
+ end
145
+
146
+ it "should collect timings when start and finish are invoked in sequence" do
147
+ @tc.start
148
+ @tc.finish
149
+ @tc.time.should >= 0
150
+ end
151
+ end
@@ -0,0 +1,152 @@
1
+ # Copyright (c) 2006-2010 Nick Sieger <nicksieger@gmail.com>
2
+ # See the file LICENSE.txt included with the distribution for
3
+ # software license details.
4
+
5
+ require File.dirname(__FILE__) + "/../../spec_helper.rb"
6
+
7
+ describe "The TestUnit reporter" do
8
+ before(:each) do
9
+ @report_mgr = mock("report manager")
10
+ @testunit = CI::Reporter::TestUnit.new(nil, @report_mgr)
11
+ @result = mock("result")
12
+ @result.stub!(:assertion_count).and_return(7)
13
+ end
14
+
15
+ it "should build suites based on adjacent tests with the same class name" do
16
+ @suite = nil
17
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
18
+
19
+ @testunit.started(@result)
20
+ @testunit.test_started("test_one(TestCaseClass)")
21
+ @testunit.test_finished("test_one(TestCaseClass)")
22
+ @testunit.test_started("test_two(TestCaseClass)")
23
+ @testunit.test_finished("test_two(TestCaseClass)")
24
+ @testunit.finished(10)
25
+
26
+ @suite.name.should == "TestCaseClass"
27
+ @suite.testcases.length.should == 2
28
+ @suite.testcases.first.name.should == "test_one"
29
+ @suite.testcases.first.should_not be_failure
30
+ @suite.testcases.first.should_not be_error
31
+ @suite.testcases.last.name.should == "test_two"
32
+ @suite.testcases.last.should_not be_failure
33
+ @suite.testcases.last.should_not be_error
34
+ end
35
+
36
+ it "should build two suites when encountering different class names" do
37
+ @suites = []
38
+ @report_mgr.should_receive(:write_report).twice.and_return {|suite| @suites << suite }
39
+
40
+ @testunit.started(@result)
41
+ @testunit.test_started("test_one(TestCaseClass)")
42
+ @testunit.test_finished("test_one(TestCaseClass)")
43
+ @testunit.test_started("test_two(AnotherTestCaseClass)")
44
+ @testunit.test_finished("test_two(AnotherTestCaseClass)")
45
+ @testunit.finished(10)
46
+
47
+ @suites.first.name.should == "TestCaseClass"
48
+ @suites.first.testcases.length.should == 1
49
+ @suites.first.testcases.first.name.should == "test_one"
50
+ @suites.first.testcases.first.assertions.should == 7
51
+
52
+ @suites.last.name.should == "AnotherTestCaseClass"
53
+ @suites.last.testcases.length.should == 1
54
+ @suites.last.testcases.first.name.should == "test_two"
55
+ @suites.last.testcases.first.assertions.should == 0
56
+ end
57
+
58
+ it "should record assertion counts during test run" do
59
+ @suite = nil
60
+ @report_mgr.should_receive(:write_report).and_return {|suite| @suite = suite }
61
+
62
+ @testunit.started(@result)
63
+ @testunit.test_started("test_one(TestCaseClass)")
64
+ @testunit.test_finished("test_one(TestCaseClass)")
65
+ @testunit.finished(10)
66
+
67
+ @suite.assertions.should == 7
68
+ @suite.testcases.last.assertions.should == 7
69
+ end
70
+
71
+ it "should add failures to testcases when encountering a fault" do
72
+ @failure = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:10", "it failed")
73
+
74
+ @suite = nil
75
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
76
+
77
+ @testunit.started(@result)
78
+ @testunit.test_started("test_one(TestCaseClass)")
79
+ @testunit.fault(@failure)
80
+ @testunit.test_finished("test_one(TestCaseClass)")
81
+ @testunit.finished(10)
82
+
83
+ @suite.name.should == "TestCaseClass"
84
+ @suite.testcases.length.should == 1
85
+ @suite.testcases.first.name.should == "test_one"
86
+ @suite.testcases.first.should be_failure
87
+ end
88
+
89
+ it "should add errors to testcases when encountering a fault" do
90
+ begin
91
+ raise StandardError, "error"
92
+ rescue => e
93
+ @error = Test::Unit::Error.new("test_two(TestCaseClass)", e)
94
+ end
95
+
96
+ @suite = nil
97
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
98
+
99
+ @testunit.started(@result)
100
+ @testunit.test_started("test_one(TestCaseClass)")
101
+ @testunit.test_finished("test_one(TestCaseClass)")
102
+ @testunit.test_started("test_two(TestCaseClass)")
103
+ @testunit.fault(@error)
104
+ @testunit.test_finished("test_two(TestCaseClass)")
105
+ @testunit.finished(10)
106
+
107
+ @suite.name.should == "TestCaseClass"
108
+ @suite.testcases.length.should == 2
109
+ @suite.testcases.first.name.should == "test_one"
110
+ @suite.testcases.first.should_not be_failure
111
+ @suite.testcases.first.should_not be_error
112
+ @suite.testcases.last.name.should == "test_two"
113
+ @suite.testcases.last.should_not be_failure
114
+ @suite.testcases.last.should be_error
115
+ end
116
+
117
+ it "should add multiple failures to a testcase" do
118
+ @failure1 = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:10", "it failed")
119
+ @failure2 = Test::Unit::Failure.new("test_one(TestCaseClass)", "somewhere:12", "it failed again in teardown")
120
+
121
+ @suite = nil
122
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
123
+
124
+ @testunit.started(@result)
125
+ @testunit.test_started("test_one(TestCaseClass)")
126
+ @testunit.fault(@failure1)
127
+ @testunit.fault(@failure2)
128
+ @testunit.test_finished("test_one(TestCaseClass)")
129
+ @testunit.finished(10)
130
+
131
+ @suite.name.should == "TestCaseClass"
132
+ @suite.testcases.length.should == 1
133
+ @suite.testcases.first.name.should == "test_one"
134
+ @suite.testcases.first.should be_failure
135
+ @suite.testcases.first.failures.size.should == 2
136
+ @suite.failures.should == 2
137
+ end
138
+
139
+ it "should count test case names that don't conform to the standard pattern" do
140
+ @suite = nil
141
+ @report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
142
+
143
+ @testunit.started(@result)
144
+ @testunit.test_started("some unknown test")
145
+ @testunit.test_finished("some unknown test")
146
+ @testunit.finished(10)
147
+
148
+ @suite.name.should == "unknown-1"
149
+ @suite.testcases.length.should == 1
150
+ @suite.testcases.first.name.should == "some unknown test"
151
+ end
152
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2006-2010 Nick Sieger <nicksieger@gmail.com>
2
+ # See the file LICENSE.txt included with the distribution for
3
+ # software license details.
4
+
5
+ require 'rubygems'
6
+ gem 'rspec'
7
+ require 'spec'
8
+
9
+ unless defined?(CI_REPORTER_LIB)
10
+ CI_REPORTER_LIB = File.expand_path(File.dirname(__FILE__) + "/../lib")
11
+ $: << CI_REPORTER_LIB
12
+ end
13
+
14
+ require 'ci/reporter/core'
15
+ require 'ci/reporter/test_unit'
16
+ require 'ci/reporter/rspec'
17
+
18
+ REPORTS_DIR = File.dirname(__FILE__) + "/reports" unless defined?(REPORTS_DIR)
data/stub.rake ADDED
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2006-2010 Nick Sieger <nicksieger@gmail.com>
2
+ # See the file LICENSE.txt included with the distribution for
3
+ # software license details.
4
+ #
5
+ # Use this stub rakefile as a wrapper around a regular Rakefile. Run in the
6
+ # same directory as the real Rakefile.
7
+ #
8
+ # rake -f /path/to/ci_reporter/lib/ci/reporter/rake/stub.rake ci:setup:rspec default
9
+ #
10
+
11
+ load File.dirname(__FILE__) + '/lib/ci/reporter/rake/rspec.rb'
12
+ load File.dirname(__FILE__) + '/lib/ci/reporter/rake/cucumber.rb'
13
+ load File.dirname(__FILE__) + '/lib/ci/reporter/rake/test_unit.rb'
14
+ load 'Rakefile'
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2006-2010 Nick Sieger <nicksieger@gmail.com>
2
+ # See the file LICENSE.txt included with the distribution for
3
+ # software license details.
4
+
5
+ begin
6
+ gem 'ci_reporter'
7
+ rescue Gem::LoadError
8
+ $: << File.dirname(__FILE__) + "/../lib"
9
+ end
10
+ require 'ci/reporter/rake/rspec'
11
+ require 'ci/reporter/rake/cucumber'
12
+ require 'ci/reporter/rake/test_unit'
13
+
14
+ namespace :ci do
15
+ task :setup_rspec => "ci:setup:rspec"
16
+ task :setup_cucumber => "ci:setup:cucumber"
17
+ task :setup_testunit => "ci:setup:testunit"
18
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timfel-ci_reporter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 6
9
+ - 2
10
+ version: 1.6.2
11
+ platform: ruby
12
+ authors:
13
+ - Nick Sieger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-22 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: builder
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 2
34
+ version: 2.1.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubyforge
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 4
50
+ version: 2.0.4
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: CI::Reporter is an add-on to Test::Unit, RSpec and Cucumber that allows you to generate XML reports of your test, spec and/or feature runs. The resulting files can be read by a continuous integration system that understands Ant's JUnit report XML format, thus allowing your CI system to track test/spec successes and failures.
54
+ email: nick@nicksieger.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.txt
63
+ - LICENSE.txt
64
+ files:
65
+ - History.txt
66
+ - Manifest.txt
67
+ - README.txt
68
+ - LICENSE.txt
69
+ - Rakefile
70
+ - stub.rake
71
+ - lib/ci/reporter/core.rb
72
+ - lib/ci/reporter/cucumber.rb
73
+ - lib/ci/reporter/rake/cucumber.rb
74
+ - lib/ci/reporter/rake/cucumber_loader.rb
75
+ - lib/ci/reporter/rake/rspec.rb
76
+ - lib/ci/reporter/rake/rspec_loader.rb
77
+ - lib/ci/reporter/rake/test_unit.rb
78
+ - lib/ci/reporter/rake/test_unit_loader.rb
79
+ - lib/ci/reporter/report_manager.rb
80
+ - lib/ci/reporter/rspec.rb
81
+ - lib/ci/reporter/test_suite.rb
82
+ - lib/ci/reporter/test_unit.rb
83
+ - lib/ci/reporter/version.rb
84
+ - spec/ci/reporter/cucumber_spec.rb
85
+ - spec/ci/reporter/output_capture_spec.rb
86
+ - spec/ci/reporter/rake/rake_tasks_spec.rb
87
+ - spec/ci/reporter/report_manager_spec.rb
88
+ - spec/ci/reporter/rspec_spec.rb
89
+ - spec/ci/reporter/test_suite_spec.rb
90
+ - spec/ci/reporter/test_unit_spec.rb
91
+ - spec/spec_helper.rb
92
+ - tasks/ci_reporter.rake
93
+ has_rdoc: true
94
+ homepage: http://caldersphere.rubyforge.org/ci_reporter
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --main
100
+ - README.txt
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: caldersphere
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: CI::Reporter allows you to generate reams of XML for use with continuous integration systems.
128
+ test_files:
129
+ - spec/ci/reporter/cucumber_spec.rb
130
+ - spec/ci/reporter/output_capture_spec.rb
131
+ - spec/ci/reporter/rake/rake_tasks_spec.rb
132
+ - spec/ci/reporter/report_manager_spec.rb
133
+ - spec/ci/reporter/rspec_spec.rb
134
+ - spec/ci/reporter/test_suite_spec.rb
135
+ - spec/ci/reporter/test_unit_spec.rb