Class: FunWith::Testing::AssertionsTestCase

Inherits:
TestCase
  • Object
show all
Defined in:
lib/fun_with/testing/assertions_test_case.rb

Overview

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

Instance Method Summary collapse

Methods inherited from TestCase

_context, _should, install_basic_assertions, install_test_mode, install_verbosity

Instance Method Details

#extended_test_case(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# 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(&block) ⇒ Object



28
29
30
31
32
33
34
# 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) ⇒ Object



40
41
42
43
44
45
46
47
# 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) ⇒ Object



49
50
51
52
53
54
55
56
# 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, &block) ⇒ Object

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.



12
13
14
# File 'lib/fun_with/testing/assertions_test_case.rb', line 12

def safe_assert_block( *args, &block )
  yield
end

#testing_method(m, &block) ⇒ Object



58
59
60
61
# 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) ⇒ Object



36
37
38
# File 'lib/fun_with/testing/assertions_test_case.rb', line 36

def yep( *args, &block )
  assert @case.send( @current_method_sym, *args, &block )
end