Sha256: 2b463dcb68250bbe1e6da9681bcd95bfba788f9a31076743b552b8069899ee56

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

require 'test/unit/testcase'

module Test
  module Unit
    # This extension of the standard Test::Unit::TestCase makes RSpec
    # available from within, so that you can do things like:
    #
    # require 'test/unit'
    # require 'spec'
    #
    # class MyTest < Test::Unit::TestCase
    #   it "should work with Test::Unit assertions" do
    #     assert_equal 4, 2+1
    #   end
    #
    #   def test_should_work_with_rspec_expectations
    #     (3+1).should == 5
    #   end
    # end
    #
    # See also Spec::Example::ExampleGroup
    class TestCase
      extend Spec::Example::ExampleGroupMethods
      include Spec::Example::ExampleMethods

      before(:each) {setup}
      after(:each) {teardown}

      class << self
        def suite
          Test::Unit::TestSuiteAdapter.new(self)
        end

        def example_method?(method_name)
          should_method?(method_name) || test_method?(method_name)
        end

        def test_method?(method_name)
          method_name =~ /^test[_A-Z]./ && (
            instance_method(method_name).arity == 0 ||
            instance_method(method_name).arity == -1
          )
        end
      end

      def initialize(defined_description, options={}, &implementation)
        @_defined_description = defined_description
        
        # TODO - examples fail in rspec-rails if we remove "|| pending_implementation"
        #      - find a way to fail without it in rspec's code examples
        @_implementation = implementation || pending_implementation

        @_result = ::Test::Unit::TestResult.new
        # @method_name is important to set here because it "complies" with Test::Unit's interface.
        # Some Test::Unit extensions depend on @method_name being present.
        @method_name = @_defined_description
      end

      def run(ignore_this_argument=nil)
        super()
      end

    private

      def pending_implementation
        error = Spec::Example::NotYetImplementedError.new(caller)
        lambda { raise(error) }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/interop/test/unit/testcase.rb
dchelimsky-rspec-1.1.11 lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb
rspec-1.1.10 lib/spec/interop/test/unit/testcase.rb
rspec-1.1.11 lib/spec/interop/test/unit/testcase.rb
rspec-1.1.9 lib/spec/interop/test/unit/testcase.rb
typo-5.1.98 vendor/plugins/rspec/lib/spec/interop/test/unit/testcase.rb
typo-5.2 vendor/plugins/rspec/lib/spec/interop/test/unit/testcase.rb