App-PRT
view release on metacpan or search on metacpan
t/App-PRT-Command-RenameClass.t view on Meta::CPAN
$command->register('My::Food' => 'My::Meal');
my $file = "$directory/t/001-my-food._t";
$command->execute($file);
is file($file)->slurp, <<'CODE', 'test replaced';
use Test::More tests => 5;
use_ok 'My::Meal';
require_ok 'My::Meal';
new_ok 'My::Meal';
isa_ok My::Meal->new, 'My::Meal';
subtest 'name' => sub {
my $pizza = My::Meal->new('Pizza');
is $pizza->name, 'Pizza';
};
CODE
}
sub execute_test_class_style_test_file: Tests {
my $directory = t::test::prepare_test_code('dinner');
my $food_file = "$directory/t/My-Food._t";
my $meal_file = "$directory/t/My-Meal._t";
my $command1 = App::PRT::Command::RenameClass->new;
$command1->register('t::My::Food' => 't::My::Meal');
$command1->execute($food_file);
ok ! -f $food_file, "Food._t doesn't exist";
ok -e $meal_file, "Meal._t exists";
is file($meal_file)->slurp, <<'CODE', 'package statement replaced';
package t::My::Meal;
use base qw(Test::Class);
use Test::More;
sub _load : Test(startup => 1) {
use_ok 'My::Food';
}
sub instantiate : Test(1) {
isa_ok My::Food->new('banana'), 'My::Food';
}
sub name : Test(1) {
my $food = My::Food->new('banana');
is $food->name, 'banana';
}
__PACKAGE__->runtests;
CODE
}
sub execute_for_not_perl_file: Tests {
my $directory = t::test::prepare_test_code('readme');
my $readme = "$directory/README.md";
my $command = App::PRT::Command::RenameClass->new;
$command->register('Alice' => 'Bob');
$command->execute($readme);
ok -f $readme, 'README exists';
}
sub execute_rename_to_deeper_directory : Tests {
my $directory = t::test::prepare_test_code('dinner');
my $command = App::PRT::Command::RenameClass->new;
$command->register('My::Food' => 'My::Special::Great::Food');
subtest 'target class' => sub {
my $food_file = "$directory/lib/My/Food.pm";
my $special_food_file = "$directory/lib/My/Special/Great/Food.pm";
is $command->execute($food_file), $special_food_file, 'success';
ok ! -f $food_file, "Food.pm doesn't exist";
ok -e $special_food_file, "Special::Great::Food.pm exists";
};
}
sub execute_rename_package_in_block_statement : Tests {
my $directory = t::test::prepare_test_code('package_in_block');
my $command = App::PRT::Command::RenameClass->new;
$command->register('Hello' => 'Greeting');
subtest '{ package } style' => sub {
my $script = "$directory/package_in_block.pl";
is $command->execute($script), $script, 'success';
ok -e $script, "script exists";
is file($script)->slurp, <<'CODE', 'package statement replaced';
use strict;
use warnings;
{
package Greeting;
sub hello { "hello!" }
};
print Greeting->hello;
CODE
};
subtest 'package { } style' => sub {
my $script = "$directory/package_block_statement.pl";
is $command->execute($script), $script, 'success';
( run in 1.008 second using v1.01-cache-2.11-cpan-39bf76dae61 )