App-autotest

 view release on metacpan or  search on metacpan

t/unit/autotest.t  view on Meta::CPAN

use Test::Spec;
use Test::Mock::Guard qw(mock_guard);

use App::autotest;
use App::autotest::Test::Runner::Result::History;

use Test::Differences;
use Cwd;
use constant TEST_PROGRAMS_DIRECTORY => 'data/t';

use constant A_TEST_PROGRAM       => 'data/t/1.t';
use constant ANOTHER_TEST_PROGRAM => 'data/t/2.t';
use constant SOME_TEST_PROGRAMS   => [ A_TEST_PROGRAM, ANOTHER_TEST_PROGRAM ];

use constant AN_AFTER_CHANGE_OR_NEW_HOOK_THAT_EXISTS_IMMEDIATELY => sub { 1 };

describe 'an autotest' => sub {
  it 'should have a default directory of test programs' => sub {
    ok an_autotest()->test_directory;
  };

  it 'prints message if things just got better' => sub {

    my $history = App::autotest::Test::Runner::Result::History->new();
    $history->stubs( things_just_got_better => 1 );

    my $autotest = App::autotest->new( history => $history );

    $autotest->expects('print')->with("Things just got better.\n");
    $autotest->run_tests(ANOTHER_TEST_PROGRAM);
  };

  describe 'calling run_tests_upon_startup' => sub {
    it 'calls all_test_programs to know what test programs to run' => sub {
      my $autotest = an_autotest();
      $autotest->expects('all_test_programs');
      $autotest->run_tests_upon_startup;
    };

    it 'calls run_tests to run them' => sub {
      my $autotest = an_autotest();
      $autotest->expects('run_tests');

      $autotest->run_tests_upon_startup;
    };
  };

  describe 'all_test_programs' => sub {
    it 'should use the accessor function for the test directory' => sub {
      my $autotest = an_autotest();
      $autotest->expects('test_directory')->returns(TEST_PROGRAMS_DIRECTORY);
      ok $autotest->all_test_programs();
    };

    it 'returns the same if called multiple times' => sub {
      my $autotest = an_autotest();
      my $a        = $autotest->all_test_programs( $autotest->test_directory );
      my $b        = $autotest->all_test_programs( $autotest->test_directory );
      eq_or_diff $a, $b;
    };

    it 'should collect all files ending in .t from a directory' => sub {
      my $autotest = an_autotest();
      $autotest->test_directory(TEST_PROGRAMS_DIRECTORY);

      my $cwd = getcwd();
      my @list =



( run in 0.534 second using v1.01-cache-2.11-cpan-0b5f733616e )