Skip to content
Browse files

cleanup, preparing for gem release

  • Loading branch information...
1 parent 1b15513 commit cc7897cd007657a0bd5970e40051691878f85773 @glv committed Sep 10, 2010
Showing with 51 additions and 41 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +31 −24 README.md
  4. +13 −12 Rakefile
  5. +4 −5 lib/rspec/unit/test_case.rb
View
1 Gemfile
@@ -5,6 +5,7 @@ gem 'rspec', '= 2.0.0.beta.20'
group :test do
gem 'rake', '>= 0.8.7'
+ gem 'rcov'
end
group :release do
View
2 Gemfile.lock
@@ -10,6 +10,7 @@ GEM
rubyforge (>= 2.0.0)
json_pure (1.4.6)
rake (0.8.7)
+ rcov (0.9.8)
rspec (2.0.0.beta.20)
rspec-core (= 2.0.0.beta.20)
rspec-expectations (= 2.0.0.beta.20)
@@ -27,4 +28,5 @@ PLATFORMS
DEPENDENCIES
jeweler (>= 1.4.0)
rake (>= 0.8.7)
+ rcov
rspec (= 2.0.0.beta.20)
View
55 README.md
@@ -1,14 +1,21 @@
# rspec-unit
-Test::Unit compatibility for Rspec 2.
+test/unit compatibility for RSpec 2.
+
+## Summary
+
+rspec-unit adds support for test/unit-style assertions and test
+cases to RSpec 2. This is useful for piecemeal conversions of your
+test suite (in either direction), mixing styles, or if you simply
+want to use test/unit-style assertions occasionally in your specs.
Just add this to your code:
require 'rspec/unit'
and then you can write test classes like this:
- class FooTest < Rspec::Unit::TestCase
+ class FooTest < RSpec::Unit::TestCase
def test_foo
assert_equal 3, Foo::major_version
end
@@ -26,79 +33,79 @@ attaches a description string to the next defined task):
You can also attach metadata to the entire class with the
`test_case_info` method:
- class BarTest < Rspec::Unit::TestCase
+ class BarTest < RSpec::Unit::TestCase
test_case_info :integration => true
# ...
end
Each instance of `Rspec::Unit::TestCase` is equivalent to an
-Rspec `describe` block, so it can also include `example` blocks,
+RSpec `describe` block, so it can also include `example` blocks,
`before` and `after` blocks, and nested `describe` blocks. Test
methods and `example` blocks can contain either assertions or `should`
expressions. `test` blocks (as found in Rails 2.x) also work.
-Additionally, assertions can be used inside ordinary Rspec
+Additionally, assertions can be used inside ordinary RSpec
examples.
## Rationale
-This gem is the rough equivalent, for Rspec 2, of the test/unit
-compatibility that was a part of the core Rspec gem in Rspec 1.
-The new Rspec runner design makes it quite easy to implement this
+This gem is the rough equivalent, for RSpec 2, of the test/unit
+compatibility that was a part of the core RSpec gem in RSpec 1.
+The new RSpec runner design makes it quite easy to implement this
functionality as a separate gem, which seems like a better choice
in many ways.
Currently, test/unit compatibility is much more limited than in
-Rspec 1. The goal is not to make Rspec 2 a drop-in replacement for
+RSpec 1. The goal is not to make RSpec 2 a drop-in replacement for
test/unit; rather, we have two more limited goals:
-1. to allow Rspec 2 examples to easily make use of test/unit assertions
+1. to allow RSpec 2 examples to easily make use of test/unit assertions
in cases where those assertions are valuable, or where assertions
might be the best way to express particular expectations.
2. to make it *easy* for a project to switch an existing test/unit
- suite over to run under Rspec, as the start of a gradual, piecemeal
- conversion to Rspec.
+ suite over to run under RSpec, as the start of a gradual, piecemeal
+ conversion to RSpec.
As such, there are some things we don''t support:
* The top-level module name is different. For example, one requires
- `rspec/unit` rather than `test/unit`, and extends `Rspec::Unit::TestCase`
+ `rspec/unit` rather than `test/unit`, and extends `RSpec::Unit::TestCase`
rather than `Test::Unit::TestCase`.
-* TestSuite is not supported. The Rspec 2 metadata features are
+* TestSuite is not supported. The RSpec 2 metadata features are
far more flexible than test/unit-style suites.
* Because of the very different implementation, many test/unit extensions
will not run properly.
-* All test output and summaries are in Rspec style; test/unit-compatible
+* All test output and summaries are in RSpec style; test/unit-compatible
output is not supported.
We will certainly consider supporting those things if there is demand.
I originally wrote this test/unit compatibility gem for Micronaut, a
-lightweight Rspec clone by Chad Humphries. Micronaut has been rolled
-into Rspec as the core of Rspec 2, and I was able to move the test/unit
+lightweight RSpec clone by Chad Humphries. Micronaut has been rolled
+into RSpec as the core of RSpec 2, and I was able to move the test/unit
compatibility over with minimal changes.
The point of this gem is not that I think test/unit is a better way
-to write tests than the Rspec style. I admit that I'm a TDD oldtimer
-who sees Rspec as mostly a cosmetic (rather than fundamental) change,
+to write tests than the RSpec style. I admit that I'm a TDD oldtimer
+who sees RSpec as mostly a cosmetic (rather than fundamental) change,
but that doesn't mean it's not an important change. My curmudgeonly
nature has its limits, and I do find specs a big improvement.
So why rspec-unit? Three reasons:
-1. I wanted to show off the generality of Micronaut's (and now Rspec's)
+1. I wanted to show off the generality of Micronaut's (and now RSpec's)
architecture. I hope rspec-unit can serve as an example for anyone
who wants to experiment with new ways of expressing tests and specs
- on top of Rspec.
+ on top of RSpec.
2. Many projects with existing test/unit test suites might want to
- benefit from the [metadata goodness][metadata] in Rspec 2, or begin
- a gradual, piecemeal change to an Rspec style. That's pretty
+ benefit from the [metadata goodness][metadata] in RSpec 2, or begin
+ a gradual, piecemeal change to an RSpec style. That's pretty
easy to do with rspec-unit.
3. Even when writing specs and examples, I frequently encounter
cases where an assertion is more expressive than a `should`
expression. It's nice just to have assertions supported within
- Rspec examples.
+ RSpec examples.
[uth]: http://blog.thinkrelevance.com/2009/4/1/micronaut-innovation-under-the-hood
[metadata]: http://blog.thinkrelevance.com/2009/3/26/introducing-micronaut-a-lightweight-bdd-framework
View
25 Rakefile
@@ -4,36 +4,37 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "rspec-unit"
- gem.summary = %Q{Adds test/unit compatibility to Rspec.}
+ gem.summary = %Q{test/unit compatibility for RSpec 2.}
+ gem.description = File.read('README.md').sub(/\A.*^## Summary\s*$\s*(.*?)\s*^#+\s.*\Z/m, '\1')
gem.email = "glv@vanderburg.org"
gem.homepage = "http://github.com/glv/rspec-unit"
gem.authors = ["Glenn Vanderburg"]
gem.rubyforge_project = "rspec-unit"
- gem.add_dependency('rspec', '>= 2.0.0.beta.5')
+ gem.add_dependency('rspec', '>= 2.0.0.beta.20')
gem.has_rdoc = false
- gem.files = FileList["[A-Z]*", "{bin,lib,examples}/**/*"]
+ gem.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
gem.rubyforge_project = 'glv'
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::RubyforgeTasks.new
rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new(:examples) do |examples|
- examples.pattern = 'spec/**/*_spec.rb'
- examples.ruby_opts = '-Ilib -Ispec'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.ruby_opts = '-Ilib -Ispec'
end
-RSpec::Core::RakeTask.new(:rcov) do |examples|
- examples.pattern = 'spec/**/*_spec.rb'
- examples.rcov_opts = '-Ilib -Ispec -x "/Library/Ruby/Gems,^spec/"'
- examples.rcov = true
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov_opts = '-Ilib -Ispec -x ' + "'#{Regexp.escape(Bundler.settings.path)},^spec/'"
+ spec.rcov = true
end
-task :default => :examples
+task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
View
9 lib/rspec/unit/test_case.rb
@@ -30,8 +30,7 @@ def self.inherited(klass)
install_setup_and_teardown(klass)
- name = test_case_name(klass)
- klass.set_it_up(name, {:caller => caller})
+ klass.set_it_up(test_case_name(klass), {:caller => caller})
klass.metadata[:example_group][:test_unit] = true
children << klass
world.example_groups << klass
@@ -47,8 +46,8 @@ def self.test_info(options)
def self.method_added(id)
name = id.to_s
- caller_lines[name] = caller
if test_method?(name)
+ caller_lines[name] = caller
test_method_metadata[name] = @_metadata_for_next
@_metadata_for_next = nil
end
@@ -63,7 +62,7 @@ def self.ancestors
end
def self.to_s
- self == RSpec::Unit::TestCase ? 'RSpec::Unit::TestCase' : super
+ self == ::RSpec::Unit::TestCase ? 'RSpec::Unit::TestCase' : super
end
def self.test_case_name(klass)
@@ -82,7 +81,7 @@ def self.test_method_metadata
def self.install_setup_and_teardown(klass)
# Only do this for direct descendants, because test/unit chains
# fixtures through explicit calls to super.
- if self == RSpec::Unit::TestCase
+ if self == ::RSpec::Unit::TestCase
klass.class_eval do
before {setup}
after {teardown}

0 comments on commit cc7897c

Please sign in to comment.
Something went wrong with that request. Please try again.