incorrect text for test #339

Closed
KES777 opened this Issue Oct 10, 2012 · 2 comments

Projects

None yet

2 participants

@KES777
KES777 commented Oct 10, 2012

I get next messages:
ok 1 - use SRS::Zone::RR;
ok 2 - The object isa SRS::Zone::RR::A
ok 3 - SRS::Zone::RR::A isa SRS::Zone::RR

while running test:
$obj = SRS::Zone::RR->new( %a );
isa_ok( $obj, 'SRS::Zone::RR::A' );
new_ok( 'SRS::Zone::RR' => [ %a ], 'SRS::Zone::RR::A' );

as you mention in doc that:
new_ok is basically equivalent to:

my $obj = $class->new(@args);
isa_ok $obj, $class, $object_name;

you must print out same messages.

Expected:
ok 1 - use SRS::Zone::RR;
ok 2 - The object isa SRS::Zone::RR::A
ok 3 - The object isa SRS::Zone::RR::A

@schwern
Member
schwern commented Oct 12, 2012

It does say they're basically equivalent, so there's no requirement they be
exactly the same. Let's proceed without that requirement and see if there's
a benefit here to making them match.

First problem is that these are not equivalent:

isa_ok( $obj, 'SRS::Zone::RR::A' );
new_ok( 'SRS::Zone::RR' => [ %a ], 'SRS::Zone::RR::A' );

Your new_ok() is really doing this:

my $obj = SRS::Zone::RR->new(%a);
isa_ok $obj, "SRS::Zone::RR", "SRS::Zone::RR::A";

Which is to say...

Check that SRS::Zone::RR->new(%a) isa SRS::Zone::RR object...
***but then refer to that object as SRS::Zone::RR::A***

What you meant was...

my $obj = SRS::Zone::RR->new(%a);
isa_ok $obj, "SRS::Zone::RR::A";

Which is...

Check that SRS::Zone::RR->new(%a) isa SRS::Zone::RR::A object.

See the difference? The 3rd argument to new_ok is not the class to do the isa
check on, but the name of the object. Same as the third argument to isa_ok().
There is no option to change the isa class to new_ok, you have to write it
out longhand. This is by design, new_ok is only meant as a convenience
wrapper for a few lines of code.

If there's a problem here it's that difference in behavior between new_ok and
isa_ok leads to a trap that you fell into. Took me a while to notice it, too.

Thoughts?

@schwern
Member
schwern commented Apr 22, 2013

Not a bug and no response from the reporter for six months. Closing. Please reopen if you feel there's still an issue here.

@schwern schwern closed this Apr 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment