in reply to Previewing message hangs

Works for me. I originally previewed and posted the below (cut'n'pasted from your link) without this prelude. I had no problems. After my node appeared with no problems I edited it to add this prelude.

                - tye

If you're enforcing the object type you have to draft in Test::MockObject, which is great, but is also substantially more complex.

You can still use the self-shunt unit testing pattern with enforced object types and Test::Class if you take advantage of perl's run-time method dispatch.

For example, consider a class that takes an optional logging object to allow custom logging on an object by object basis.

package Object; use Params::Validate qw(:all); sub new { my $class = shift; my %self = validate(@_, {logger => { isa => 'Logger' } } ); return( bless \%self, $class ); }; # ... more code ... sub log { my ($self, @messages) = @_; $self->{logger}->log($self, @messages); };

One way to test Object's log method would be to create a mock Logger object with Test::MockObject and pass this to Object->new. Instead, we will make the Test::Class pretend to be a Logger object.

package Object::Test; use base qw(Test::Class); use Test::More; # run $code while pretending that __PACKAGE__ ISA $class sub _do_as(&$) { my ($code, $class) = @_; { # we have to make sure the package hash exists # for the method dispatch to work no strict 'refs'; *{"$class\::"}{HASH} }; local @Object::Test::ISA = ($class, @Object::Test::ISA); $code->(); }; sub setup : Test(setup) { my $self = shift; _do_as { $self->{object} = Object->new(logger => $self) } 'Logger' +; }; sub test_show_answer : Test(3) { my $self = shift; _do_as { $self->{object}->log("hello", "there") } 'Logger'; }; sub log { my $self = shift; is($_[0], $self->{object}, 'passed object to logger'); is($_[1], "hello", 'passed arg1'); is($_[2], "there", 'passed arg2'); };

Sneaky - eh?

Replies are listed 'Best First'.
Re^2: Previewing message hangs (not my text)
by adrianh (Chancellor) on Jan 13, 2003 at 01:07 UTC

    Freaky. It's still happening to me. I just tried it on a Mac OS X box with Chimera, also with Safari & Mac MSIE on the same box. Browser just sits there and spins.


    Update: Just tried it using a different ISP and it worked. I presume a proxy must have got itself in a twist. My apologies for the duff bug report.