You could
further test to ensure that each horse has a unique name:
use Test::More "no_plan";
use Horse;
my $trigger = Horse->named("Trigger");
isa_ok($trigger, "Horse");
my $tv_horse = Horse->named("Mr. Ed");
isa_ok($tv_horse, "Horse");
# Did making a second horse affect the name of the first horse?
is($trigger->name, "Trigger", "Trigger's name is correct");
is($tv_horse->name, "Mr. Ed", "Mr. Ed's name is correct");
is(Horse->name, "a generic Horse");
The output of this is:
ok 1 - The object isa Horse
ok 2 - The object isa Horse
ok 3 - Trigger's name is correct
ok 4 - Mr. Ed's name is correct
not ok 5
# Failed test (1.t at line 13)
# got: 'an unnamed Horse'
# expected: 'a generic Horse'
1..5
# Looks like you failed 1 tests of 5.
Oops! Look at that. You wrote a
generic Horse, but the string
really is an unnamed Horse.
That's an error in the test, not in the module, so
you should correct that test error and retry. Unless, of course, the
module's spec actually called for
'a generic Horse'.
Again, don't be afraid to just write the tests and
test the module. If you get either one wrong, the other will
generally catch it.