stopdropandrew_ci_reporter 1.7.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,152 @@
1
+ # Copyright (c) 2006-2012 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 'stringio'
7
+
8
+ describe "The RSpec reporter" do
9
+ before(:each) do
10
+ @error = mock("error")
11
+ @error.stub!(:expectation_not_met?).and_return(false)
12
+ @error.stub!(:pending_fixed?).and_return(false)
13
+ @error.stub!(:exception).and_return(StandardError.new)
14
+ @report_mgr = mock("report manager")
15
+ @options = mock("options")
16
+ @args = [@options, StringIO.new("")]
17
+ @args.shift unless defined?(::Spec) && ::Spec::VERSION::MAJOR == 1 && ::Spec::VERSION::MINOR >= 1
18
+ @fmt = CI::Reporter::RSpec.new *@args
19
+ @fmt.report_manager = @report_mgr
20
+ @formatter = mock("formatter")
21
+ @fmt.formatter = @formatter
22
+ end
23
+
24
+ it "should use a progress bar formatter by default" do
25
+ fmt = CI::Reporter::RSpec.new *@args
26
+ fmt.formatter.should be_instance_of(CI::Reporter::RSpecFormatters::ProgressFormatter)
27
+ end
28
+
29
+ it "should use a specdoc formatter for RSpecDoc" do
30
+ fmt = CI::Reporter::RSpecDoc.new *@args
31
+ fmt.formatter.should be_instance_of(CI::Reporter::RSpecFormatters::DocFormatter)
32
+ end
33
+
34
+ it "should create a test suite with one success, one failure, and one pending" do
35
+ @report_mgr.should_receive(:write_report).and_return do |suite|
36
+ suite.testcases.length.should == 3
37
+ suite.testcases[0].should_not be_failure
38
+ suite.testcases[0].should_not be_error
39
+ suite.testcases[1].should be_error
40
+ suite.testcases[2].name.should =~ /\(PENDING\)/
41
+ end
42
+
43
+ example_group = mock "example group"
44
+ example_group.stub!(:description).and_return "A context"
45
+
46
+ @formatter.should_receive(:start).with(3)
47
+ @formatter.should_receive(:example_group_started).with(example_group)
48
+ @formatter.should_receive(:example_started).exactly(3).times
49
+ @formatter.should_receive(:example_passed).once
50
+ @formatter.should_receive(:example_failed).once
51
+ @formatter.should_receive(:example_pending).once
52
+ @formatter.should_receive(:start_dump).once
53
+ @formatter.should_receive(:dump_failure).once
54
+ @formatter.should_receive(:dump_summary).once
55
+ @formatter.should_receive(:dump_pending).once
56
+ @formatter.should_receive(:dump_failures).once
57
+ @formatter.should_receive(:close).once
58
+
59
+ @fmt.start(3)
60
+ @fmt.example_group_started(example_group)
61
+ @fmt.example_started("should pass")
62
+ @fmt.example_passed("should pass")
63
+ @fmt.example_started("should fail")
64
+ @fmt.example_failed("should fail", 1, @error)
65
+ @fmt.example_started("should be pending")
66
+ @fmt.example_pending("A context", "should be pending", "Not Yet Implemented")
67
+ @fmt.start_dump
68
+ @fmt.dump_failure(1, mock("failure"))
69
+ @fmt.dump_summary(0.1, 3, 1, 1)
70
+ @fmt.dump_pending
71
+ @fmt.close
72
+ end
73
+
74
+ it "should support RSpec 1.0.8 #add_behavior" do
75
+ @formatter.should_receive(:start)
76
+ @formatter.should_receive(:add_behaviour).with("A context")
77
+ @formatter.should_receive(:example_started).once
78
+ @formatter.should_receive(:example_passed).once
79
+ @formatter.should_receive(:dump_summary)
80
+ @formatter.should_receive(:dump_failures).once
81
+ @report_mgr.should_receive(:write_report)
82
+
83
+ @fmt.start(2)
84
+ @fmt.add_behaviour("A context")
85
+ @fmt.example_started("should pass")
86
+ @fmt.example_passed("should pass")
87
+ @fmt.dump_summary(0.1, 1, 0, 0)
88
+ end
89
+
90
+ it "should use the example #description method when available" do
91
+ group = mock "example group"
92
+ group.stub!(:description).and_return "group description"
93
+ example = mock "example"
94
+ example.stub!(:description).and_return "should do something"
95
+
96
+ @formatter.should_receive(:start)
97
+ @formatter.should_receive(:example_group_started).with(group)
98
+ @formatter.should_receive(:example_started).with(example).once
99
+ @formatter.should_receive(:example_passed).once
100
+ @formatter.should_receive(:dump_summary)
101
+ @formatter.should_receive(:dump_failures).once
102
+ @report_mgr.should_receive(:write_report).and_return do |suite|
103
+ suite.testcases.last.name.should == "should do something"
104
+ end
105
+
106
+ @fmt.start(2)
107
+ @fmt.example_group_started(group)
108
+ @fmt.example_started(example)
109
+ @fmt.example_passed(example)
110
+ @fmt.dump_summary(0.1, 1, 0, 0)
111
+ end
112
+
113
+ it "should create a test suite with failure in before(:all)" do
114
+ example_group = mock "example group"
115
+ example_group.stub!(:description).and_return "A context"
116
+
117
+ @formatter.should_receive(:start)
118
+ @formatter.should_receive(:example_group_started).with(example_group)
119
+ @formatter.should_receive(:example_started).once
120
+ @formatter.should_receive(:example_failed).once
121
+ @formatter.should_receive(:dump_summary)
122
+ @formatter.should_receive(:dump_failures).once
123
+ @report_mgr.should_receive(:write_report)
124
+
125
+ @fmt.start(2)
126
+ @fmt.example_group_started(example_group)
127
+ @fmt.example_failed("should fail", 1, @error)
128
+ @fmt.dump_summary(0.1, 1, 0, 0)
129
+ end
130
+
131
+ describe 'RSpec2Failure' do
132
+ before(:each) do
133
+ @formatter = mock "formatter"
134
+ @formatter.should_receive(:format_backtrace).and_return("backtrace")
135
+ @rspec20_example = mock('RSpec2.0 Example', :execution_result => {:exception_encountered => StandardError.new('rspec2.0 ftw')})
136
+ @rspec22_example = mock('RSpec2.2 Example', :execution_result => {:exception => StandardError.new('rspec2.2 ftw')})
137
+ end
138
+
139
+ it 'should handle rspec (< 2.2) execution results' do
140
+ failure = CI::Reporter::RSpec2Failure.new(@rspec20_example, @formatter)
141
+ failure.name.should_not be_nil
142
+ failure.message.should == 'rspec2.0 ftw'
143
+ failure.location.should_not be_nil
144
+ end
145
+ it 'should handle rspec (>= 2.2) execution results' do
146
+ failure = CI::Reporter::RSpec2Failure.new(@rspec22_example, @formatter)
147
+ failure.name.should_not be_nil
148
+ failure.message.should == 'rspec2.2 ftw'
149
+ failure.location.should_not be_nil
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,160 @@
1
+ # Copyright (c) 2006-2012 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
+ ENV['CI_CAPTURE'] = nil
57
+ @suite = CI::Reporter::TestSuite.new("example suite")
58
+ @suite.assertions = 11
59
+ begin
60
+ raise StandardError, "an exception occurred"
61
+ rescue => e
62
+ @exception = e
63
+ end
64
+ end
65
+
66
+ it "should render successfully with CI_CAPTURE off" do
67
+ ENV['CI_CAPTURE'] = 'off'
68
+ @suite.start
69
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
70
+ @suite.finish
71
+ xml = @suite.to_xml
72
+ end
73
+
74
+ it "should contain Ant/JUnit-formatted description of entire suite" do
75
+ failure = mock("failure")
76
+ failure.stub!(:failure?).and_return true
77
+ failure.stub!(:error?).and_return false
78
+ failure.stub!(:name).and_return "failure"
79
+ failure.stub!(:message).and_return "There was a failure"
80
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
81
+
82
+ error = mock("error")
83
+ error.stub!(:failure?).and_return false
84
+ error.stub!(:error?).and_return true
85
+ error.stub!(:name).and_return "error"
86
+ error.stub!(:message).and_return "There was a error"
87
+ error.stub!(:location).and_return @exception.backtrace.join("\n")
88
+
89
+ @suite.start
90
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
91
+ @suite.testcases << CI::Reporter::TestCase.new("skipped test").tap {|tc| tc.skipped = true }
92
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
93
+ @suite.testcases.last.failures << failure
94
+ @suite.testcases << CI::Reporter::TestCase.new("error test")
95
+ @suite.testcases.last.failures << error
96
+ @suite.finish
97
+
98
+ xml = @suite.to_xml
99
+ doc = REXML::Document.new(xml)
100
+ testsuite = doc.root.elements.to_a("/testsuite")
101
+ testsuite.length.should == 1
102
+ testsuite = testsuite.first
103
+ testsuite.attributes["name"].should == "example suite"
104
+ testsuite.attributes["assertions"].should == "11"
105
+
106
+ testcases = testsuite.elements.to_a("testcase")
107
+ testcases.length.should == 4
108
+ end
109
+
110
+ it "should contain full exception type and message in location element" do
111
+ failure = mock("failure")
112
+ failure.stub!(:failure?).and_return true
113
+ failure.stub!(:error?).and_return false
114
+ failure.stub!(:name).and_return "failure"
115
+ failure.stub!(:message).and_return "There was a failure"
116
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
117
+
118
+ @suite.start
119
+ @suite.testcases << CI::Reporter::TestCase.new("example test")
120
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
121
+ @suite.testcases.last.failures << failure
122
+ @suite.finish
123
+
124
+ xml = @suite.to_xml
125
+ doc = REXML::Document.new(xml)
126
+ elem = doc.root.elements.to_a("/testsuite/testcase[@name='failure test']/failure").first
127
+ location = elem.texts.join
128
+ location.should =~ Regexp.new(failure.message)
129
+ location.should =~ Regexp.new(failure.name)
130
+ end
131
+
132
+ it "should filter attributes properly for invalid characters" do
133
+ failure = mock("failure")
134
+ failure.stub!(:failure?).and_return true
135
+ failure.stub!(:error?).and_return false
136
+ failure.stub!(:name).and_return "failure"
137
+ failure.stub!(:message).and_return "There was a <failure>\nReason: blah"
138
+ failure.stub!(:location).and_return @exception.backtrace.join("\n")
139
+
140
+ @suite.start
141
+ @suite.testcases << CI::Reporter::TestCase.new("failure test")
142
+ @suite.testcases.last.failures << failure
143
+ @suite.finish
144
+
145
+ xml = @suite.to_xml
146
+ xml.should =~ %r/message="There was a &lt;failure&gt;\.\.\."/
147
+ end
148
+ end
149
+
150
+ describe "A TestCase" do
151
+ before(:each) do
152
+ @tc = CI::Reporter::TestCase.new("example test")
153
+ end
154
+
155
+ it "should collect timings when start and finish are invoked in sequence" do
156
+ @tc.start
157
+ @tc.finish
158
+ @tc.time.should >= 0
159
+ end
160
+ end
@@ -0,0 +1,152 @@
1
+ # Copyright (c) 2006-2012 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