The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::YAFT::Test::Exception - Test::YAFT - Test::Exception comparison

DESCRIPTION

Test::YAFT doesn't provide dedicated asserts like Test::Exception.

Instead it uses it and got { } block to achieve same result.

dies_ok

Behaviour of dies_ok is achieved by expecting any exception

        # Test::Exception
        dies_ok { $foo->method } "should die";

        # Test::YAFT
        it "should die"
                => got { $foo->method }
                => throws => ignore
                ;

lives_ok

Behaviour of lives_ok is achieved by expecting anything

        # Test::Exception
        lives_ok { $foo->method } "should not die";

        # Test::YAFT
        it "should not die"
                => got { $foo->method }
                => expect => ignore
                ;

lives_and

Behaviour of lives_and implicit behaviour when got { } block is used.

        # 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
                ;

throws_ok

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

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 })
                ;

AUTHOR

Branislav Zahradník <barney@cpan.org>

COPYRIGHT AND LICENCE

This file is part of Test::YAFT distribution.