class FunWith::Testing::AssertionsTestCase

Class is designed specifically for testing custom assertions. See test/test_assertions.rb for how it's supposed to work.

Public Instance Methods

extended_test_case( ) { || ... } click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 16
def extended_test_case( &block )
  @case_class = Class.new( FunWith::Testing::AssertionsTestCase )

  @case = @case_class.new( "MockUnitTest" )        # what does name arg do?
    
  assert @case_class.methods.include?( :_should )
  assert @case_class.methods.include?( :_context )
  # assert @case.methods.include?( :in_test_mode? )
    
  yield if block_given?
end
must_flunk( ) { || ... } click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 28
def must_flunk( &block )
  assert_raises( Minitest::Assertion ) do
    if block_given?
      yield
    end
  end
end
nope( *args, &block ) click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 40
def nope( *args, &block )
  must_flunk do
    @case.send( @current_method_sym, *args, &block )

    # shouldn't get here
    puts "should fail: #{@current_method_sym}( #{ args.map(&:inspect).join(", ")})"
  end
end
oops( *args ) click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 49
def oops( *args )
  assert_raises( StandardError ) do
    @case.send( @current_method_sym, *args, &block )

    # should not get here
    puts "should cause error: #{@current_method_sym}( #{ args.map(&:inspect).join(", ")})"
  end
end
safe_assert_block( *args ) { || ... } click to toggle source

Any subclass of Test::Unit::TestCase seems to automatically hook into the test suite. Therefore, calling a test to see if it returns false makes the suite fail. Including to this class instead prevents that.

I may need to more closely mimic Test::Unit::TestCase in order to test messages properly.

# File lib/fun_with/testing/assertions_test_case.rb, line 12
def safe_assert_block( *args, &block )
  yield
end
testing_method( m ) { || ... } click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 58
def testing_method( m, &block )
  @current_method_sym = m
  yield
end
yep( *args, &block ) click to toggle source
# File lib/fun_with/testing/assertions_test_case.rb, line 36
def yep( *args, &block )
  assert @case.send( @current_method_sym, *args, &block )
end