Permalink
Browse files

- Upgrade to RSpec 1.0

- Add examples for Rake tasks


git-svn-id: http://svn.caldersphere.net/svn/main/rubyforge/ci_reporter/trunk@97 b03c2d0b-2f10-0410-a2f9-fc8001506dfa
  • Loading branch information...
1 parent c49ef10 commit 259fe8a4fc85f932069119a03cb043e4380b6205 @nicksieger nicksieger committed Jun 4, 2007
View
@@ -1,3 +1,7 @@
+== 1.3.2
+
+- Fix bug trying to modify frozen environment strings
+
== 1.3.1
- Fixed to be compatible with RSpec 1.0.x (added fourth parameter to Formatter#dump_summary)
@@ -7,7 +7,7 @@
task :rspec do
rm_rf ENV["CI_REPORTS"] || "spec/reports"
ENV["RSPECOPTS"] ||= ""
- ENV["RSPECOPTS"] << [" --require", "#{File.dirname(__FILE__)}/rspec_loader.rb",
+ ENV["RSPECOPTS"] += [" --require", "#{File.dirname(__FILE__)}/rspec_loader.rb",
"--format", "CI::Reporter::RSpec"].join(" ")
end
end
@@ -7,7 +7,7 @@
task :testunit do
rm_rf ENV["CI_REPORTS"] || "test/reports"
ENV["TESTOPTS"] ||= ""
- ENV["TESTOPTS"] << " #{File.dirname(__FILE__)}/test_unit_loader.rb"
+ ENV["TESTOPTS"] += " #{File.dirname(__FILE__)}/test_unit_loader.rb"
end
end
end
View
@@ -106,7 +106,7 @@ def dump_failure(counter, failure)
super
end
- def dump_summary(duration, example_count, failure_count, not_implemented_count = nil)
+ def dump_summary(duration, example_count, failure_count, not_implemented_count = 0)
begin
super
rescue ArgumentError
@@ -5,12 +5,12 @@
require File.dirname(__FILE__) + "/../../spec_helper.rb"
require 'rexml/document'
-context "Output capture" do
- setup do
+describe "Output capture" do
+ before(:each) do
@suite = CI::Reporter::TestSuite.new "test"
end
- specify "should save stdout and stderr messages written during the test run" do
+ it "should save stdout and stderr messages written during the test run" do
@suite.start
puts "Hello"
$stderr.print "Hi"
@@ -19,7 +19,7 @@
@suite.stderr.should == "Hi"
end
- specify "should include system-out and system-err elements in the xml output" do
+ it "should include system-out and system-err elements in the xml output" do
@suite.start
puts "Hello"
$stderr.print "Hi"
@@ -32,7 +32,7 @@
root.elements.to_a('//system-err').first.cdatas.first.to_s.should == "Hi"
end
- specify "should return $stdout and $stderr to original value after finish" do
+ it "should return $stdout and $stderr to original value after finish" do
out, err = $stdout, $stderr
@suite.start
$stdout.object_id.should_not == out.object_id
@@ -42,7 +42,7 @@
$stderr.object_id.should == err.object_id
end
- specify "should capture only during run of owner test suite" do
+ it "should capture only during run of owner test suite" do
$stdout.print "A"
$stderr.print "A"
@suite.start
@@ -0,0 +1,68 @@
+# (c) Copyright 2006-2007 Nick Sieger <nicksieger@gmail.com>
+# See the file LICENSE.txt included with the distribution for
+# software license details.
+
+require File.dirname(__FILE__) + "/../../../spec_helper.rb"
+require 'rake'
+
+def save_env(v)
+ ENV["PREV_#{v}"] = ENV[v]
+end
+def restore_env(v)
+ ENV[v] = ENV["PREV_#{v}"]
+ ENV.delete("PREV_#{v}")
+end
+
+describe "ci_reporter ci:setup:testunit task" do
+ before(:each) do
+ @rake = Rake::Application.new
+ Rake.application = @rake
+ load CI_REPORTER_LIB + '/ci/reporter/rake/test_unit.rb'
+ save_env "CI_REPORTS"
+ save_env "TESTOPTS"
+ ENV["CI_REPORTS"] = "some-bogus-nonexistent-directory-that-wont-fail-rm_rf"
+ end
+ after(:each) do
+ restore_env "TESTOPTS"
+ restore_env "CI_REPORTS"
+ Rake.application = nil
+ end
+
+ it "should set ENV['TESTOPTS'] to include test/unit setup file" do
+ @rake["ci:setup:testunit"].invoke
+ ENV["TESTOPTS"].should =~ /test_unit_loader/
+ end
+
+ it "should append to ENV['TESTOPTS'] if it already contains a value" do
+ ENV["TESTOPTS"] = "somevalue".freeze
+ @rake["ci:setup:testunit"].invoke
+ ENV["TESTOPTS"].should =~ /somevalue.*test_unit_loader/
+ end
+end
+
+describe "ci_reporter ci:setup:rspec task" do
+ before(:each) do
+ @rake = Rake::Application.new
+ Rake.application = @rake
+ load CI_REPORTER_LIB + '/ci/reporter/rake/rspec.rb'
+ save_env "CI_REPORTS"
+ save_env "RSPECOPTS"
+ ENV["CI_REPORTS"] = "some-bogus-nonexistent-directory-that-wont-fail-rm_rf"
+ end
+ after(:each) do
+ restore_env "RSPECOPTS"
+ restore_env "CI_REPORTS"
+ Rake.application = nil
+ end
+
+ it "should set ENV['RSPECOPTS'] to include rspec formatter args" do
+ @rake["ci:setup:rspec"].invoke
+ ENV["RSPECOPTS"].should =~ /--require.*rspec_loader.*--format.*CI::Reporter::RSpec/
+ end
+
+ it "should append to ENV['RSPECOPTS'] if it already contains a value" do
+ ENV["RSPECOPTS"] = "somevalue".freeze
+ @rake["ci:setup:rspec"].invoke
+ ENV["RSPECOPTS"].should =~ /somevalue.*--require.*rspec_loader.*--format.*CI::Reporter::RSpec/
+ end
+end
@@ -4,36 +4,36 @@
require File.dirname(__FILE__) + "/../../spec_helper.rb"
-context "The ReportManager" do
- setup do
+describe "The ReportManager" do
+ before(:each) do
@reports_dir = REPORTS_DIR
end
- teardown do
+ after(:each) do
FileUtils.rm_rf @reports_dir
ENV["CI_REPORTS"] = nil
end
- specify "should create the report directory according to the given prefix" do
+ it "should create the report directory according to the given prefix" do
CI::Reporter::ReportManager.new("spec")
- File.directory?(@reports_dir).should_be true
+ File.directory?(@reports_dir).should be_true
end
- specify "should create the report directory based on CI_REPORTS environment variable if set" do
+ it "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
+ File.directory?(@reports_dir).should be_true
end
- specify "should write reports based on name and xml content of a test suite" do
+ it "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.exist?(filename).should be_true
File.open(filename) {|f| f.read.should == "<xml></xml>"}
end
end
@@ -5,8 +5,8 @@
require File.dirname(__FILE__) + "/../../spec_helper.rb"
require 'stringio'
-context "The RSpec reporter" do
- setup do
+describe "The RSpec reporter" do
+ before(:each) do
@error = mock("error")
@error.stub!(:exception).and_return do
begin
@@ -20,20 +20,20 @@
@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
+ it "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
+ 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.add_behaviour("A context")
+ @fmt.example_started("should pass")
+ @fmt.example_passed("should pass")
+ @fmt.example_started("should fail")
+ @fmt.example_failed("should fail", 1, @error)
@fmt.dump_summary(0.1, 2, 1)
end
end
@@ -5,25 +5,25 @@
require File.dirname(__FILE__) + "/../../spec_helper.rb"
require 'rexml/document'
-context "A TestSuite" do
- setup do
+describe "A TestSuite" do
+ before(:each) do
@suite = CI::Reporter::TestSuite.new("example suite")
end
- specify "should collect timings when start and finish are invoked in sequence" do
+ it "should collect timings when start and finish are invoked in sequence" do
@suite.start
@suite.finish
- @suite.time.should_be > 0
+ @suite.time.should > 0
end
- specify "should aggregate tests" do
+ it "should aggregate tests" do
@suite.start
@suite.testcases << CI::Reporter::TestCase.new("example test")
@suite.finish
@suite.tests.should == 1
end
- specify "should indicate number of failures and errors" do
+ it "should indicate number of failures and errors" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
@@ -43,11 +43,10 @@
@suite.failures.should == 1
@suite.errors.should == 1
end
-
end
-context "TestSuite xml" do
- setup do
+describe "TestSuite xml" do
+ before(:each) do
@suite = CI::Reporter::TestSuite.new("example suite")
@suite.assertions = 11
begin
@@ -57,7 +56,7 @@
end
end
- specify "should contain Ant/JUnit-formatted description of entire suite" do
+ it "should contain Ant/JUnit-formatted description of entire suite" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
@@ -92,7 +91,7 @@
testcases.length.should == 3
end
- specify "should contain full exception type and message in location element" do
+ it "should contain full exception type and message in location element" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
@@ -114,7 +113,7 @@
location.should =~ Regexp.new(failure.name)
end
- specify "should filter attributes properly for invalid characters" do
+ it "should filter attributes properly for invalid characters" do
failure = mock("failure")
failure.stub!(:failure?).and_return true
failure.stub!(:error?).and_return false
@@ -128,18 +127,18 @@
@suite.finish
xml = @suite.to_xml
- xml.should_match %r/message="There was a &lt;failure&gt;\.\.\."/
+ xml.should =~ %r/message="There was a &lt;failure&gt;\.\.\."/
end
end
-context "A TestCase" do
- setup do
+describe "A TestCase" do
+ before(:each) do
@tc = CI::Reporter::TestCase.new("example test")
end
- specify "should collect timings when start and finish are invoked in sequence" do
+ it "should collect timings when start and finish are invoked in sequence" do
@tc.start
@tc.finish
- @tc.time.should_be > 0
+ @tc.time.should > 0
end
end
Oops, something went wrong.

0 comments on commit 259fe8a

Please sign in to comment.