amfranz-ci_reporter 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ module CI
2
+ module Reporter
3
+ VERSION = "1.6.2"
4
+ end
5
+ end
@@ -0,0 +1,204 @@
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 'ci/reporter/cucumber'
7
+
8
+ describe "The Cucumber reporter" do
9
+ describe CI::Reporter::CucumberFailure do
10
+ before(:each) do
11
+ @klass = mock("class")
12
+ @klass.stub!(:name).and_return("Exception name")
13
+
14
+ @exception = mock("exception")
15
+ @exception.stub!(:class).and_return(@klass)
16
+ @exception.stub!(:message).and_return("Exception message")
17
+ @exception.stub!(:backtrace).and_return(["First line", "Second line"])
18
+
19
+ @step = mock("step")
20
+ @step.stub!(:exception).and_return(@exception)
21
+
22
+ @cucumber_failure = CI::Reporter::CucumberFailure.new(@step)
23
+ end
24
+
25
+ it "should always return true for failure?" do
26
+ @cucumber_failure.should be_failure
27
+ end
28
+
29
+ it "should always return false for error?" do
30
+ @cucumber_failure.should_not be_error
31
+ end
32
+
33
+ it "should propagate the name as the underlying exception's class name" do
34
+ @step.should_receive(:exception)
35
+ @exception.should_receive(:class)
36
+ @klass.should_receive(:name)
37
+
38
+ @cucumber_failure.name.should == "Exception name"
39
+ end
40
+
41
+ it "should propagate the message as the underlying exception's message" do
42
+ @step.should_receive(:exception)
43
+ @exception.should_receive(:message)
44
+
45
+ @cucumber_failure.message.should == "Exception message"
46
+ end
47
+
48
+ it "should propagate and format the exception's backtrace" do
49
+ @step.should_receive(:exception)
50
+ @exception.should_receive(:backtrace)
51
+
52
+ @cucumber_failure.location.should == "First line\nSecond line"
53
+ end
54
+ end
55
+
56
+ describe CI::Reporter::Cucumber do
57
+ before(:each) do
58
+ @step_mother = mock("step_mother")
59
+ @io = mock("io")
60
+
61
+ @report_manager = mock("report_manager")
62
+ CI::Reporter::ReportManager.stub!(:new).and_return(@report_manager)
63
+ end
64
+
65
+ def new_instance
66
+ CI::Reporter::Cucumber.new(@step_mother, @io, {})
67
+ end
68
+
69
+ it "should create a new report manager to report on test success/failure" do
70
+ CI::Reporter::ReportManager.should_receive(:new)
71
+ new_instance
72
+ end
73
+
74
+ it "should record the feature name when a new feature is visited" do
75
+ cucumber = new_instance
76
+ cucumber.visit_feature_name("Some feature name")
77
+ cucumber.feature_name.should == "Some feature name"
78
+ end
79
+
80
+ it "should record only the first line of a feature name" do
81
+ cucumber = new_instance
82
+ cucumber.visit_feature_name("Some feature name\nLonger description")
83
+ cucumber.feature_name.should == "Some feature name"
84
+ end
85
+
86
+ describe "when visiting a new scenario" do
87
+ before(:each) do
88
+ @cucumber = new_instance
89
+ @cucumber.visit_feature_name("Demo feature")
90
+
91
+ @test_suite = mock("test_suite", :start => nil, :finish => nil)
92
+ CI::Reporter::TestSuite.stub!(:new).and_return(@test_suite)
93
+
94
+ @feature_element = mock("feature_element", :accept => true)
95
+
96
+ @report_manager.stub!(:write_report)
97
+ end
98
+
99
+ it "should create a new test suite" do
100
+ # FIXME: @name is feature_element purely as a by-product of the
101
+ # mocking framework implementation. But then again, using
102
+ # +instance_variable_get+ in the first place is a bit icky.
103
+ CI::Reporter::TestSuite.should_receive(:new).with("Demo feature feature_element")
104
+ @cucumber.visit_feature_element(@feature_element)
105
+ end
106
+
107
+ it "should indicate that the test suite has started" do
108
+ @test_suite.should_receive(:start)
109
+ @cucumber.visit_feature_element(@feature_element)
110
+ end
111
+
112
+ it "should indicate that the test suite has finished" do
113
+ @test_suite.should_receive(:finish)
114
+ @cucumber.visit_feature_element(@feature_element)
115
+ end
116
+
117
+ it "should ask the report manager to write a report" do
118
+ @report_manager.should_receive(:write_report).with(@test_suite)
119
+ @cucumber.visit_feature_element(@feature_element)
120
+ end
121
+ end
122
+
123
+ describe "when visiting a step inside a scenario" do
124
+ before(:each) do
125
+ @testcases = []
126
+
127
+ @test_suite = mock("test_suite", :testcases => @testcases)
128
+
129
+ @cucumber = new_instance
130
+ @cucumber.stub!(:test_suite).and_return(@test_suite)
131
+
132
+ @test_case = mock("test_case", :start => nil, :finish => nil, :name => "Step Name")
133
+ CI::Reporter::TestCase.stub!(:new).and_return(@test_case)
134
+
135
+ @step = mock("step", :accept => true, :status => :passed)
136
+ @step.stub!(:name).and_return("Step Name")
137
+ end
138
+
139
+ it "should create a new test case" do
140
+ CI::Reporter::TestCase.should_receive(:new).with("Step Name")
141
+ @cucumber.visit_step(@step)
142
+ end
143
+
144
+ it "should indicate that the test case has started" do
145
+ @test_case.should_receive(:start)
146
+ @cucumber.visit_step(@step)
147
+ end
148
+
149
+ it "should indicate that the test case has finished" do
150
+ @test_case.should_receive(:finish)
151
+ @cucumber.visit_step(@step)
152
+ end
153
+
154
+ it "should add the test case to the suite's list of cases" do
155
+ @testcases.should be_empty
156
+ @cucumber.visit_step(@step)
157
+ @testcases.should_not be_empty
158
+ @testcases.first.should == @test_case
159
+ end
160
+
161
+ it "should alter the name of a test case that is pending to include '(PENDING)'" do
162
+ @step.stub!(:status).and_return(:pending)
163
+ @test_case.should_receive(:name=).with("Step Name (PENDING)")
164
+ @cucumber.visit_step(@step)
165
+ end
166
+
167
+ it "should alter the name of a test case that is undefined to include '(PENDING)'" do
168
+ @step.stub!(:status).and_return(:undefined)
169
+ @test_case.should_receive(:name=).with("Step Name (PENDING)")
170
+ @cucumber.visit_step(@step)
171
+ end
172
+
173
+ it "should alter the name of a test case that was skipped to include '(SKIPPED)'" do
174
+ @step.stub!(:status).and_return(:skipped)
175
+ @test_case.should_receive(:name=).with("Step Name (SKIPPED)")
176
+ @cucumber.visit_step(@step)
177
+ end
178
+
179
+ describe "that fails" do
180
+ before(:each) do
181
+ @step.stub!(:status).and_return(:failed)
182
+
183
+ @failures = []
184
+ @test_case.stub!(:failures).and_return(@failures)
185
+
186
+ @cucumber_failure = mock("cucumber_failure")
187
+ CI::Reporter::CucumberFailure.stub!(:new).and_return(@cucumber_failure)
188
+ end
189
+
190
+ it "should create a new cucumber failure with that step" do
191
+ CI::Reporter::CucumberFailure.should_receive(:new).with(@step)
192
+ @cucumber.visit_step(@step)
193
+ end
194
+
195
+ it "should add the failure to the suite's list of failures" do
196
+ @failures.should be_empty
197
+ @cucumber.visit_step(@step)
198
+ @failures.should_not be_empty
199
+ @failures.first.should == @cucumber_failure
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,57 @@
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 "Output capture" do
9
+ before(:each) do
10
+ @suite = CI::Reporter::TestSuite.new "test"
11
+ end
12
+
13
+ it "should save stdout and stderr messages written during the test run" do
14
+ @suite.start
15
+ puts "Hello"
16
+ $stderr.print "Hi"
17
+ @suite.finish
18
+ @suite.stdout.should == "Hello\n"
19
+ @suite.stderr.should == "Hi"
20
+ end
21
+
22
+ it "should include system-out and system-err elements in the xml output" do
23
+ @suite.start
24
+ puts "Hello"
25
+ $stderr.print "Hi"
26
+ @suite.finish
27
+
28
+ root = REXML::Document.new(@suite.to_xml).root
29
+ root.elements.to_a('//system-out').length.should == 1
30
+ root.elements.to_a('//system-err').length.should == 1
31
+ root.elements.to_a('//system-out').first.texts.first.to_s.strip.should == "Hello"
32
+ root.elements.to_a('//system-err').first.texts.first.to_s.strip.should == "Hi"
33
+ end
34
+
35
+ it "should return $stdout and $stderr to original value after finish" do
36
+ out, err = $stdout, $stderr
37
+ @suite.start
38
+ $stdout.object_id.should_not == out.object_id
39
+ $stderr.object_id.should_not == err.object_id
40
+ @suite.finish
41
+ $stdout.object_id.should == out.object_id
42
+ $stderr.object_id.should == err.object_id
43
+ end
44
+
45
+ it "should capture only during run of owner test suite" do
46
+ $stdout.print "A"
47
+ $stderr.print "A"
48
+ @suite.start
49
+ $stdout.print "B"
50
+ $stderr.print "B"
51
+ @suite.finish
52
+ $stdout.print "C"
53
+ $stderr.print "C"
54
+ @suite.stdout.should == "B"
55
+ @suite.stderr.should == "B"
56
+ end
57
+ end
@@ -0,0 +1,100 @@
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 'rake'
7
+
8
+ def save_env(v)
9
+ ENV["PREV_#{v}"] = ENV[v]
10
+ end
11
+ def restore_env(v)
12
+ ENV[v] = ENV["PREV_#{v}"]
13
+ ENV.delete("PREV_#{v}")
14
+ end
15
+
16
+ describe "ci_reporter ci:setup:testunit task" do
17
+ before(:each) do
18
+ @rake = Rake::Application.new
19
+ Rake.application = @rake
20
+ load CI_REPORTER_LIB + '/ci/reporter/rake/test_unit.rb'
21
+ save_env "CI_REPORTS"
22
+ save_env "TESTOPTS"
23
+ ENV["CI_REPORTS"] = "some-bogus-nonexistent-directory-that-wont-fail-rm_rf"
24
+ end
25
+ after(:each) do
26
+ restore_env "TESTOPTS"
27
+ restore_env "CI_REPORTS"
28
+ Rake.application = nil
29
+ end
30
+
31
+ it "should set ENV['TESTOPTS'] to include test/unit setup file" do
32
+ @rake["ci:setup:testunit"].invoke
33
+ ENV["TESTOPTS"].should =~ /test_unit_loader/
34
+ end
35
+
36
+ it "should append to ENV['TESTOPTS'] if it already contains a value" do
37
+ ENV["TESTOPTS"] = "somevalue".freeze
38
+ @rake["ci:setup:testunit"].invoke
39
+ ENV["TESTOPTS"].should =~ /somevalue.*test_unit_loader/
40
+ end
41
+ end
42
+
43
+ describe "ci_reporter ci:setup:rspec task" do
44
+ before(:each) do
45
+ @rake = Rake::Application.new
46
+ Rake.application = @rake
47
+ load CI_REPORTER_LIB + '/ci/reporter/rake/rspec.rb'
48
+ save_env "CI_REPORTS"
49
+ save_env "SPEC_OPTS"
50
+ ENV["CI_REPORTS"] = "some-bogus-nonexistent-directory-that-wont-fail-rm_rf"
51
+ end
52
+ after(:each) do
53
+ restore_env "SPEC_OPTS"
54
+ restore_env "CI_REPORTS"
55
+ Rake.application = nil
56
+ end
57
+
58
+ it "should set ENV['SPEC_OPTS'] to include rspec formatter args" do
59
+ @rake["ci:setup:rspec"].invoke
60
+ ENV["SPEC_OPTS"].should =~ /--require.*rspec_loader.*--format.*CI::Reporter::RSpec/
61
+ end
62
+
63
+ it "should set ENV['SPEC_OPTS'] to include rspec doc formatter if task is ci:setup:rspecdoc" do
64
+ @rake["ci:setup:rspecdoc"].invoke
65
+ ENV["SPEC_OPTS"].should =~ /--require.*rspec_loader.*--format.*CI::Reporter::RSpecDoc/
66
+ end
67
+
68
+ it "should append to ENV['SPEC_OPTS'] if it already contains a value" do
69
+ ENV["SPEC_OPTS"] = "somevalue".freeze
70
+ @rake["ci:setup:rspec"].invoke
71
+ ENV["SPEC_OPTS"].should =~ /somevalue.*--require.*rspec_loader.*--format.*CI::Reporter::RSpec/
72
+ end
73
+ end
74
+
75
+ describe "ci_reporter ci:setup:cucumber task" do
76
+ before(:each) do
77
+ @rake = Rake::Application.new
78
+ Rake.application = @rake
79
+ load CI_REPORTER_LIB + '/ci/reporter/rake/cucumber.rb'
80
+ save_env "CI_REPORTS"
81
+ save_env "CUCUMBER_OPTS"
82
+ ENV["CI_REPORTS"] = "some-bogus-nonexistent-directory-that-wont-fail-rm_rf"
83
+ end
84
+ after(:each) do
85
+ restore_env "CUCUMBER_OPTS"
86
+ restore_env "CI_REPORTS"
87
+ Rake.application = nil
88
+ end
89
+
90
+ it "should set ENV['CUCUMBER_OPTS'] to include cucumber formatter args" do
91
+ @rake["ci:setup:cucumber"].invoke
92
+ ENV["CUCUMBER_OPTS"].should =~ /--require.*cucumber_loader.*--format.*CI::Reporter::Cucumber/
93
+ end
94
+
95
+ it "should append to ENV['CUCUMBER_OPTS'] if it already contains a value" do
96
+ ENV["CUCUMBER_OPTS"] = "somevalue".freeze
97
+ @rake["ci:setup:cucumber"].invoke
98
+ ENV["CUCUMBER_OPTS"].should =~ /somevalue.*--require.*cucumber_loader.*--format.*CI::Reporter::Cucumber/
99
+ end
100
+ end
@@ -0,0 +1,39 @@
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 ReportManager" do
8
+ before(:each) do
9
+ @reports_dir = REPORTS_DIR
10
+ end
11
+
12
+ after(:each) do
13
+ FileUtils.rm_rf @reports_dir
14
+ ENV["CI_REPORTS"] = nil
15
+ end
16
+
17
+ it "should create the report directory according to the given prefix" do
18
+ CI::Reporter::ReportManager.new("spec")
19
+ File.directory?(@reports_dir).should be_true
20
+ end
21
+
22
+ it "should create the report directory based on CI_REPORTS environment variable if set" do
23
+ @reports_dir = "#{Dir.getwd}/dummy"
24
+ ENV["CI_REPORTS"] = @reports_dir
25
+ CI::Reporter::ReportManager.new("spec")
26
+ File.directory?(@reports_dir).should be_true
27
+ end
28
+
29
+ it "should write reports based on name and xml content of a test suite" do
30
+ reporter = CI::Reporter::ReportManager.new("spec")
31
+ suite = mock("test suite")
32
+ suite.should_receive(:name).and_return("some test suite name")
33
+ suite.should_receive(:to_xml).and_return("<xml></xml>")
34
+ reporter.write_report(suite)
35
+ filename = "#{REPORTS_DIR}/SPEC-some-test-suite-name.xml"
36
+ File.exist?(filename).should be_true
37
+ File.open(filename) {|f| f.read.should == "<xml></xml>"}
38
+ end
39
+ end
@@ -0,0 +1,125 @@
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 '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
+ @report_mgr = mock("report manager")
14
+ @options = mock("options")
15
+ @args = [@options, StringIO.new("")]
16
+ @args.shift if Spec::VERSION::MAJOR == 1 && Spec::VERSION::MINOR < 1
17
+ @fmt = CI::Reporter::RSpec.new *@args
18
+ @fmt.report_manager = @report_mgr
19
+ @formatter = mock("formatter")
20
+ @fmt.formatter = @formatter
21
+ end
22
+
23
+ it "should use a progress bar formatter by default" do
24
+ fmt = CI::Reporter::RSpec.new *@args
25
+ fmt.formatter.should be_instance_of(Spec::Runner::Formatter::ProgressBarFormatter)
26
+ end
27
+
28
+ it "should use a specdoc formatter for RSpecDoc" do
29
+ fmt = CI::Reporter::RSpecDoc.new *@args
30
+ fmt.formatter.should be_instance_of(Spec::Runner::Formatter::SpecdocFormatter)
31
+ end
32
+
33
+ it "should create a test suite with one success, one failure, and one pending" do
34
+ @report_mgr.should_receive(:write_report).and_return do |suite|
35
+ suite.testcases.length.should == 3
36
+ suite.testcases[0].should_not be_failure
37
+ suite.testcases[0].should_not be_error
38
+ suite.testcases[1].should be_error
39
+ suite.testcases[2].name.should =~ /\(PENDING\)/
40
+ end
41
+
42
+ example_group = mock "example group"
43
+ example_group.stub!(:description).and_return "A context"
44
+
45
+ @formatter.should_receive(:start).with(3)
46
+ @formatter.should_receive(:example_group_started).with(example_group)
47
+ @formatter.should_receive(:example_started).exactly(3).times
48
+ @formatter.should_receive(:example_passed).once
49
+ @formatter.should_receive(:example_failed).once
50
+ @formatter.should_receive(:example_pending).once
51
+ @formatter.should_receive(:start_dump).once
52
+ @formatter.should_receive(:dump_failure).once
53
+ @formatter.should_receive(:dump_summary).once
54
+ @formatter.should_receive(:dump_pending).once
55
+ @formatter.should_receive(:close).once
56
+
57
+ @fmt.start(3)
58
+ @fmt.example_group_started(example_group)
59
+ @fmt.example_started("should pass")
60
+ @fmt.example_passed("should pass")
61
+ @fmt.example_started("should fail")
62
+ @fmt.example_failed("should fail", 1, @error)
63
+ @fmt.example_started("should be pending")
64
+ @fmt.example_pending("A context", "should be pending", "Not Yet Implemented")
65
+ @fmt.start_dump
66
+ @fmt.dump_failure(1, mock("failure"))
67
+ @fmt.dump_summary(0.1, 3, 1, 1)
68
+ @fmt.dump_pending
69
+ @fmt.close
70
+ end
71
+
72
+ it "should support RSpec 1.0.8 #add_behavior" do
73
+ @formatter.should_receive(:start)
74
+ @formatter.should_receive(:add_behaviour).with("A context")
75
+ @formatter.should_receive(:example_started).once
76
+ @formatter.should_receive(:example_passed).once
77
+ @formatter.should_receive(:dump_summary)
78
+ @report_mgr.should_receive(:write_report)
79
+
80
+ @fmt.start(2)
81
+ @fmt.add_behaviour("A context")
82
+ @fmt.example_started("should pass")
83
+ @fmt.example_passed("should pass")
84
+ @fmt.dump_summary(0.1, 1, 0, 0)
85
+ end
86
+
87
+ it "should use the example #description method when available" do
88
+ group = mock "example group"
89
+ group.stub!(:description).and_return "group description"
90
+ example = mock "example"
91
+ example.stub!(:description).and_return "should do something"
92
+
93
+ @formatter.should_receive(:start)
94
+ @formatter.should_receive(:example_group_started).with(group)
95
+ @formatter.should_receive(:example_started).with(example).once
96
+ @formatter.should_receive(:example_passed).once
97
+ @formatter.should_receive(:dump_summary)
98
+ @report_mgr.should_receive(:write_report).and_return do |suite|
99
+ suite.testcases.last.name.should == "should do something"
100
+ end
101
+
102
+ @fmt.start(2)
103
+ @fmt.example_group_started(group)
104
+ @fmt.example_started(example)
105
+ @fmt.example_passed(example)
106
+ @fmt.dump_summary(0.1, 1, 0, 0)
107
+ end
108
+
109
+ it "should create a test suite with failure in before(:all)" do
110
+ example_group = mock "example group"
111
+ example_group.stub!(:description).and_return "A context"
112
+
113
+ @formatter.should_receive(:start)
114
+ @formatter.should_receive(:example_group_started).with(example_group)
115
+ @formatter.should_receive(:example_started).once
116
+ @formatter.should_receive(:example_failed).once
117
+ @formatter.should_receive(:dump_summary)
118
+ @report_mgr.should_receive(:write_report)
119
+
120
+ @fmt.start(2)
121
+ @fmt.example_group_started(example_group)
122
+ @fmt.example_failed("should fail", 1, @error)
123
+ @fmt.dump_summary(0.1, 1, 0, 0)
124
+ end
125
+ end