NAME

Test::Arrow - Object-Oriented testing library

SYNOPSIS

use Test::Arrow;

my $arr = Test::Arrow->new;

$arr->ok(1);
$arr->got(1)->ok;

$arr->expect(uc 'foo')->to_be('FOO');

$arr->name('Test Name')
    ->expected('FOO')
    ->got(uc 'foo')
    ->is;

$arr->expected(6)
    ->got(2 * 3)
    ->is_num;

# `unlike` shows where a place could have matched if it's failed
$arr->name('Unlike Fail example')
    ->expected(qr/b/)
    ->got('abc')
    ->unlike;
#   Failed test 'Unlike Fail example'
#   at t/unlike.t line 12.
#                   'abc'
#           matches '(?^:b)'
#           matched at line: 1, offset: 2

DESCRIPTION

The opposite DSL.

MOTIVATION

Test::Arrow is a testing helper as object-oriented operation. Perl5 has a lot of testing libraries. These libraries have nice DSL ways. However, sometimes we hope the Object as similar to ORM. It may slightly sound strange. But it'd be better to clarify operations and it's easy to understand what/how it is. Although there are so many arrows.

METHODS

new

The constructor.

my $arr = Test::Arrow->new;

SETTERS

expected($expected)

The setter of expected value. $expected will be compared with $got

expect($expected)

The alias of expected method.

got($got)

The setter of got value. $got will be compared with $expected

name($test_name)

The setter of the test name. If you ommit to set the test name, then it's automatically set.

Note that the test name automatically set by Test::Name::FromLine.

If you write one test as multiple lines like below,

L5:  $arr->expected('FOO')
L6:      ->got(uc 'foo')
L7:      ->is;

then the output of test will be like below

ok 1 - L5: $arr->expected('FOO')

You might expect the test name like below, however, it's actually being like above.

ok 1 - L7:     ->is;

The test name is taken from the first line of each test.

TEST EXECUTERS

pass =head3 fail

Just pass or fail

ok

$arr->got($true);

is =head3 isnt

Similar to is and isnt compare values with eq and ne.

$arr->expect('FOO')->got(us 'foo')->is;

is_num =head3 isnt_num

Similar to is_num and isnt_num compare values with == and !=.

$arr->expect(6)->got( 2 * 3 )->is_num;

to_be($got)

The $got will be compare with expected value.

$arr->expect(us 'foo')->to_be('FOO');

like =head3 unlike

like matches $got value against the $expected regex.

$arr->expect(qr/b/)->got('abc')->like;

UTILITIES

You can call below utilities even without an instance.

diag

Output message to STDERR

$arr->diag('some messages');
Test::Arrow->diag('some message');

note

Output message to STDOUT

$arr->note('some messages');
Test::Arrow->note('some message');

explain

If you call explain method without args, then explain method outputs object info (expected, got and name) as hash.

$arr->name('foo')->expected('BAR')->got(uc 'bar')->explain->is;
# {
#   'expected' => 'BAR',
#   'got' => 'BAR',
#   'name' => 'foo'
# }
ok 1 - foo

If you call explain method with arg, then explain method dumps it.

$arr->expected('BAR')->got(uc 'bar')->explain({ baz => 123 })->is;
# {
#   'baz' => 123
# }
ok 1 - foo

done_testing

Declare of done testing.

$arr->done_testing($number_of_tests_run);
Test::Arrow->done_testing;

Note that you must never put done_testing inside an END { ... } block.

REPOSITORY

Test::Arrow is hosted on github: http://github.com/bayashi/Test-Arrow

I appreciate any feedback :D

AUTHOR

Dai Okabayashi <bayashi@cpan.org>

SEE ALSO

Test::More

Test::Kantan - A behavior-driven development framework

Test::Builder::Module

Test::Name::FromLine

LICENSE

Test::Arrow is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0, version 2.0 is GPL compatible by itself, hence there is no benefit to having an Artistic 2.0 / GPL disjunction.) See the file LICENSE for details.