[Rspec-devel] Rspec/Test::Unit Integration

Brian Takita brian.takita at gmail.com
Tue Jul 4 18:01:27 EDT 2006


Hello,

I had a conversation with David at the Rails Conference about integrating
Rspec into Test::Unit.

I want to start using Rspec at my workplace. We have alot of code in
descendants of Test::Unit::TestCase as well as several libraries that extend
its behaviour.
An obstacle I ran into is the Rspec DSL is an evolutionary improvement over
Test::Unit (i.e. you can make the same assertions and format your tests to
look like "specs"). This being the case, I don't have a compelling reason to
go through the effort to port all of our tests into specs.

If Rspec where to user Test::Unit::TestCase to make its assertions, it would
be easier to transition into using Rspec from Test::Unit.

Anyways, I did a little proof of concept with the patch attached to this
email.
The example is at the bottom of this email. Rails fixtures would work in
this case.

Thanks,
Brian Takita

require File.dirname(__FILE__) + '/../lib/spec'
require 'test/unit'

class RspecIntegrationTest < Test::Unit::TestCase
  extend Spec::Runner::SpecTestCase

  def setup
    @test_case_setup_called = true
  end

  def teardown
    puts "Test::Unit::TestCase#teardown is called too"
  end

  def test_something
  end

  def helper_method
    @helper_method_called = true
  end

  context "Rspec should integrate with Test::Unit::TestCase" do
    setup do
      @rspec_setup_called = true
    end
    specify "TestCase#setup should be called." do
      @rspec_setup_called.should_be true
      @test_case_setup_called.should_be true
    end

    specify "Rspec should be able to access TestCase methods" do
      helper_method
      @helper_method_called.should_be true
    end
  end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20060704/071a3556/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_unit_integration.patch
Type: text/x-patch
Size: 9124 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/rspec-devel/attachments/20060704/071a3556/attachment-0001.bin 


More information about the Rspec-devel mailing list