Class: Test::Unit::TestCase

Inherits:
Object show all
Extended by:
Spec::Example::ExampleGroupMethods
Includes:
FlexMock::ArgumentTypes, FlexMock::MockContainer, Spec::Example::ExampleMethods
Defined in:
lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb,
lib/gems/flexmock-0.8.3/lib/flexmock/test_unit.rb

Overview

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

Instance Attribute Summary

Attributes included from Spec::Example::ExampleGroupMethods

#description_options, #spec_path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Spec::Example::ExampleGroupMethods

all_before_each_parts, backtrace, create_example_group_subclass, create_shared_example_group, describe, described_type, description, description_args, description_parts, description_text, example, example_group_backtrace, example_group_creation_listeners, examples, inherited, it_should_behave_like, number_of_examples, predicate_matchers, register_example_group, reset, run_after_each, run_before_each, set_description, subject, subject_block, xexample

Methods included from Spec::Example::BeforeAndAfterHooks

#after_all_parts, #after_each_parts, after_suite_parts, #after_suite_parts, #append_after, #append_before, #before_all_parts, #before_each_parts, before_suite_parts, #before_suite_parts, #prepend_after, #prepend_before, #remove_after, #setup

Methods included from Spec::Example::ExampleMethods

#backtrace, #description, #eval_block, #eval_each_fail_fast, #eval_each_fail_slow, #execute, #full_description, #implementation_backtrace, #instance_variable_hash, #options, #set_instance_variables_from_hash, #should, #should_not, #subject, #violated

Methods included from Spec::Example::ModuleReopeningFix

#child_modules, #include, #included

Methods included from Spec::Example::Pending

#pending

Methods included from Spec::Matchers

#__original_match, #be, #be_a, #be_close, #change, clear_generated_description, #eql, #equal, #exist, generated_description, #has, #have, #have_at_least, #have_at_most, #include, last_matcher, last_matcher=, last_should, last_should=, #match, #method_missing, #raise_error, #respond_to, #satisfy, #simple_matcher, #throw_symbol, #wrap_expectation

Methods included from Mack::Testing::Helpers

#assigns, #clear_session, #cookies, #delete, #file_for_upload, #get, #in_session, #post, #put, #remote_test, #remove_cookie, #request, #response, #responses, #session, #set_cookie, #temp_app_config

Methods included from Mack::Routes::Urls

create_method, #redirect_html, #url_for_pattern

Methods included from FlexMock::MockContainer

#flexmock, #flexmock_close, #flexmock_remember, #flexmock_teardown, #flexmock_verify, #rails_version, #should_render_view

Methods included from FlexMock::Ordering

#flexmock_allocate_order, #flexmock_current_order, #flexmock_current_order=, #flexmock_groups, #flexmock_validate_order

Methods included from FlexMock::ArgumentTypes

#any, #eq, #on

Constructor Details

#initialize(defined_description, options = {}, &implementation) ⇒ TestCase

Returns a new instance of TestCase.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb', line 44

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

  # TODO - this is necessary to run single examples in rspec-rails, but I haven't
  # found a good way to write a failing example just within rspec core
  @_backtrace = caller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spec::Matchers

Class Method Details

.example_method?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb', line 30

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

.suiteObject



26
27
28
# File 'lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb', line 26

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

.test_method?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb', line 34

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

Instance Method Details

#flexmock_original_teardownObject

Alias the original teardown behavior for later use.



21
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/test_unit.rb', line 21

alias :flexmock_original_teardown :teardown

#run(ignore_this_argument = nil) ⇒ Object



61
62
63
# File 'lib/gems/rspec-1.1.12/lib/spec/interop/test/unit/testcase.rb', line 61

def run(ignore_this_argument=nil)
  super()
end

#teardownObject

Teardown the test case, verifying any mocks that might have been defined in this test case.



25
26
27
28
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/test_unit.rb', line 25

def teardown
  flexmock_teardown
  flexmock_original_teardown
end