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.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TestCaseExtensions

#_context, #_should, #_test, #add_factorybot_support, #install_basic_assertions, #install_test_mode, #install_verbosity

Class Method Details

.fwt_install_mock_safe_assert_blockObject



6
7
8
# File 'lib/fun_with/testing/assertions_test_case.rb', line 6

def self.fwt_install_mock_safe_assert_block
  include AssertionTestMocker
end

Instance Method Details

#extended_test_case(&block) ⇒ Object

After @case_class is created, you can include the methods you want to test



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fun_with/testing/assertions_test_case.rb', line 12

def extended_test_case( &block )
  @case_class = Class.new( FunWith::Testing::AssertionsTestCase )
  
  # Unhook from some of the test harness stuff to
  # make it possible to run the assertion methods 
  # without causing the test suite to topple over.
  @case_class.fwt_install_mock_safe_assert_block
  
  @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



29
30
31
32
33
34
35
# File 'lib/fun_with/testing/assertions_test_case.rb', line 29

def must_flunk( &block )
  assert_raises( Minitest::Assertion ) do
    if block_given?
      yield
    end
  end
end

#nope(*args, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/fun_with/testing/assertions_test_case.rb', line 41

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



51
52
53
54
55
56
57
58
# File 'lib/fun_with/testing/assertions_test_case.rb', line 51

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

#testing_method(m, &block) ⇒ Object



60
61
62
63
# File 'lib/fun_with/testing/assertions_test_case.rb', line 60

def testing_method( m, &block )
  @current_method_sym = m
  yield
end

#yep(*args, &block) ⇒ Object



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

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