NAME

Moonshine::Test - Test!

VERSION

Version 0.17

SYNOPSIS

use Moonshine::Test qw/:all/;

moon_test_one(
    test      => 'scalar',
    meth      => \&Moonshine::Util::append_str,
    args      => [
        'first', 'second'
    ],
    args_list => 1,
    expected  => 'first second',
);

sunrise(1);

EXPORT

all

moon_test
moon_test_one
render_me
done_testing

element

render_me
done_testing

SUBROUTINES/METHODS

moon_test_one

moon_test_one(
    test      => 'render_me',
    instance  => Moonshine::Component->new(),
    func      => 'button',
    args      => {
        data  => '...'
    },
    expected  => '<button>...</button>',
);

Instructions

Valid instructions moon_test_one accepts

test/expected

test     => 'like'
expected => 'a horrible death'
....
like($test_outcome, qr/$expected/, "function: $func is like - $expected");

moon_test_one can currently run the following tests.

ok - ok - a true value
ref - is_deeply - expected [] or {}
scalar - is - expected '',
hash - is_deeply - expected {},
array - is_deeply - expected [],
obj - isa_ok - expected '',
like - like - '',
true - is - 1,
false - is - 0,
undef - is - undef
ref_key_scalar - is - '' (requires key)
ref_key_ref - is_deeply - [] or {} (requires key)
ref_key_like - like - ''
ref_index_scalar - is - '' (requires index)
ref_index_ref - is_deeply - [] or {} (required index)
ref_index_like - like - ''
ref_index_obj - isa_ok - ''
list_key_scalar - is - '' (requires key)
list_key_ref - is_deeply - [] or {} (requires key)
list_key_like - like - ''
list_index_scalar - is - '' (requires index)
list_index_ref - is_deeply - [] or {} (required index)
list_index_obj - isa_ok - ''
list_index_like - like - ''
count - is - ''
count_ref - is - ''
skip - ok(1)

catch

when you want to catch exceptions....

catch => 1,

defaults the instruction{test} to like.

instance

my $instance = Moonshine::Element->new();
instance => $instance,

func

call a function from the instance

instance => $instance,
func     => 'render'

meth

meth => \&Moonshine::Element::render,

args

{} or []

args_list

args      => [qw/one, two/],
args_list => 1,

index

index - required when testing - ref_index_*

key

key - required when testing - ref_key_*

moon_test

moon_test(
    name => 'Checking Many Things'
    build => {
        class => 'Moonshine::Element', 
        args => {
            tag => 'p',
            text => 'hello'
        }
    },
    instructions => [
        {
            test => 'scalar',
            func => 'tag',
            expected => 'p',
        },
        {
            test => 'scalar',
            action => 'text',
            expected => 'hello',
        },
        { 
            test => 'render'
            expected => '<p>hello</p>'
        },
    ],
);

name

The tests name

name => 'I rule the world',

instance

my $instance = My::Object->new();
instance => $instance,

build

Build an instance

build => {
    class => 'My::Object',
    args  => { },
},

instructions

instructions => [
    {
        test => 'scalar',
        func => 'tag',
        expected => 'hello',
    },
    {
        test => 'scalar',
        action => 'text',
        expected => 'hello',
    },
    { 
        test => 'render'
        expected => '<p>hello</p>'
    },
],

subtest

instructions => [
    {
        test => 'obj',
        func => 'glyphicon',
        args => { switch => 'search' },
        subtest => [
            {
               test => 'scalar',
               func => 'class',
               expected => 'glyphicon glyphicon-search',
            },
            ...
        ]
    }
]

render_me

Test render directly on a Moonshine::Element.

render_me(
    instance => $element,
    expected => '<div>echo</div>'
);

Or test a function..

render_me(
    instance => $instance,
    func => 'div',
    args     => { data => 'echo' },
    expected => '<div>echo</div>',
);

sunrise

sunrise(); # done_testing();

AUTHOR

LNATION, <thisusedtobeanemail at gmail.com>

BUGS

Please report any bugs or feature requests to bug-moonshine-test at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Moonshine-Test. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Moonshine::Test

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2017 Robert Acock.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.