Test::YAFT::Test::Exception - Test::YAFT - Test::Exception comparison
Test::YAFT doesn't provide dedicated asserts like Test::Exception.
Instead it uses it and got { } block to achieve same result.
it
got { }
Behaviour of dies_ok is achieved by expecting any exception
dies_ok
# Test::Exception dies_ok { $foo->method } "should die"; # Test::YAFT it "should die" => got { $foo->method } => throws => ignore ;
Behaviour of lives_ok is achieved by expecting anything
lives_ok
# Test::Exception lives_ok { $foo->method } "should not die"; # Test::YAFT it "should not die" => got { $foo->method } => expect => ignore ;
Behaviour of lives_and implicit behaviour when got { } block is used.
lives_and
# Test::Exception lives_and { is $foo->method, 42 } "should not die and result is 42"; # Test::YAFT it "should not die and result is 42" => got { $foo->method } => expect => 42 ;
Behaviour of throws_ok is achieved by providing exception expectations. Unline Test::Exception this library uses Test::Deep base expectations so instead of REGEX and CLASS one have to use expect_re and expect_obj_isa
throws_ok
REGEX
CLASS
expect_re
expect_obj_isa
Stringy exceptions
# Test::Exception throws_ok { $foo->method } qr/division by zero/, "should test string exception"; # Test::YAFT it "should test string exception" => got { $foo->method } => throws => expect_re (qr/division by zero/) ;
OOP exceptions
# Test::Exception throws_ok { $foo->method } My::X::Division::By::Zero::, "should test OOP exception"; # Test::YAFT it "should test OOP exception" => got { $foo->method } => throws => & expect_obj_isa (My::X::Division::By::Zero::) & expect_methods (http_status => HTTP::Status::BAD_REQUEST) & expect_methods (json_content => +{ error => ignore }) ;
Branislav Zahradník <barney@cpan.org>
This file is part of Test::YAFT distribution.
To install Test::YAFT, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::YAFT
CPAN shell
perl -MCPAN -e shell install Test::YAFT
For more information on module installation, please visit the detailed CPAN module installation guide.