]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/interop/test/unit/testcase.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / interop / test / unit / testcase.rb
1 require 'test/unit/testcase'
2
3 module Test
4   module Unit
5     # This extension of the standard Test::Unit::TestCase makes RSpec
6     # available from within, so that you can do things like:
7     #
8     # require 'test/unit'
9     # require 'spec'
10     #
11     # class MyTest < Test::Unit::TestCase
12     #   it "should work with Test::Unit assertions" do
13     #     assert_equal 4, 2+1
14     #   end
15     #
16     #   def test_should_work_with_rspec_expectations
17     #     (3+1).should == 5
18     #   end
19     # end
20     #
21     # See also Spec::Example::ExampleGroup
22     class TestCase
23       extend Spec::Example::ExampleGroupMethods
24       include Spec::Example::ExampleMethods
25
26       before(:each) {setup}
27       after(:each) {teardown}
28
29       class << self
30         def suite
31           Test::Unit::TestSuiteAdapter.new(self)
32         end
33
34         def example_method?(method_name)
35           should_method?(method_name) || test_method?(method_name)
36         end
37
38         def test_method?(method_name)
39           method_name =~ /^test[_A-Z]./ && (
40             instance_method(method_name).arity == 0 ||
41             instance_method(method_name).arity == -1
42           )
43         end
44       end
45
46       def initialize(defined_description, &implementation)
47         @_defined_description = defined_description
48         @_implementation = implementation
49
50         @_result = ::Test::Unit::TestResult.new
51         # @method_name is important to set here because it "complies" with Test::Unit's interface.
52         # Some Test::Unit extensions depend on @method_name being present.
53         @method_name = @_defined_description
54       end
55
56       def run(ignore_this_argument=nil)
57         super()
58       end
59     end
60   end
61 end