[Rspec-devel] RSpec Extension Patch

Brian Takita brian.takita at gmail.com
Fri Jul 7 02:27:16 EDT 2006


Hello,

Based off of the great feedback from the Test::Unit Integration thread, I
came up with a new patch that I think will be more useful.
I added the following methods, with tests!!!

   - inherit
   - include

With inherit, you now get most of the "power" of the superclass. You can use
the class methods

Now this is possible...
----------------------------------------
require File.dirname(__FILE__) + '/../lib/spec'
require 'test/unit'

class RspecIntegrationTest < Test::Unit::TestCase
  def self.a_class_method
    puts "a_class_method called"
  end

  def self.fixtures(*args)
    puts "we can do fixtures too..."
  end

  def setup
    @test_case_setup_called = true
  end

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

  def run(result)
  end

  def helper_method
    @helper_method_called = true
  end
end

module RandomHelperModule
  def random_task
    @random_task_called = true
  end
end

context "Rspec should integrate with Test::Unit::TestCase" do
  inherit RspecIntegrationTest
  a_class_method
  fixtures :some_table
  include RandomHelperModule

  setup do
    @rspec_setup_called = true
  end
  specify "TestCase#setup should be called." do
    @test_case_setup_called.should_be true
    @rspec_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

  specify "Rspec should be able to accept included modules" do
    random_task
    @random_task_called.should_be true
  end
end

-----------------------------------------------

I havn't tried it, but adding integration tests should be as easy as...
------------------------------------
context "Rspec should play with Integration Tests" do
  inherit ActionController::IntegrationTest
end
------------------------------------
If this doesn't work right now, it doesn't seem like too much more effort to
implement.

Thanks,
Brian Takita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20060706/34c15c04/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extension.patch
Type: text/x-patch
Size: 12849 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/rspec-devel/attachments/20060706/34c15c04/attachment-0001.bin 


More information about the Rspec-devel mailing list