Class: FunWith::Testing::AssertionsTestCase
- Inherits:
-
TestCase
- Object
- Minitest::Test
- TestCase
- FunWith::Testing::AssertionsTestCase
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
#_context, #_should, #_test, #add_factorybot_support, #install_basic_assertions, #install_test_mode, #install_verbosity
Class Method Details
.fwt_install_mock_safe_assert_block ⇒ Object
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 )
@case_class.fwt_install_mock_safe_assert_block
@case = @case_class.new( "MockUnitTest" )
assert @case_class.methods.include?( :_should )
assert @case_class.methods.include?( :_context )
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 )
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 )
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
|