PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/jruby-1.1.6RC1/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/interop/test/unit/testcase.rb

https://bitbucket.org/nicksieger/advent-jruby
Ruby | 71 lines | 39 code | 11 blank | 21 comment | 5 complexity | 90c17347abfdfc69b926c29ff98f41de MD5 | raw file
Possible License(s): CPL-1.0, AGPL-1.0, LGPL-2.1, JSON
  1. require 'test/unit/testcase'
  2. module Test
  3. module Unit
  4. # This extension of the standard Test::Unit::TestCase makes RSpec
  5. # available from within, so that you can do things like:
  6. #
  7. # require 'test/unit'
  8. # require 'spec'
  9. #
  10. # class MyTest < Test::Unit::TestCase
  11. # it "should work with Test::Unit assertions" do
  12. # assert_equal 4, 2+1
  13. # end
  14. #
  15. # def test_should_work_with_rspec_expectations
  16. # (3+1).should == 5
  17. # end
  18. # end
  19. #
  20. # See also Spec::Example::ExampleGroup
  21. class TestCase
  22. extend Spec::Example::ExampleGroupMethods
  23. include Spec::Example::ExampleMethods
  24. before(:each) {setup}
  25. after(:each) {teardown}
  26. class << self
  27. def suite
  28. Test::Unit::TestSuiteAdapter.new(self)
  29. end
  30. def example_method?(method_name)
  31. should_method?(method_name) || test_method?(method_name)
  32. end
  33. def test_method?(method_name)
  34. method_name =~ /^test[_A-Z]./ && (
  35. instance_method(method_name).arity == 0 ||
  36. instance_method(method_name).arity == -1
  37. )
  38. end
  39. end
  40. def initialize(defined_description, options={}, &implementation)
  41. @_defined_description = defined_description
  42. # TODO - examples fail in rspec-rails if we remove "|| pending_implementation"
  43. # - find a way to fail without it in rspec's code examples
  44. @_implementation = implementation || pending_implementation
  45. @_result = ::Test::Unit::TestResult.new
  46. # @method_name is important to set here because it "complies" with Test::Unit's interface.
  47. # Some Test::Unit extensions depend on @method_name being present.
  48. @method_name = @_defined_description
  49. end
  50. def run(ignore_this_argument=nil)
  51. super()
  52. end
  53. private
  54. def pending_implementation
  55. error = Spec::Example::NotYetImplementedError.new(caller)
  56. lambda { raise(error) }
  57. end
  58. end
  59. end
  60. end