[Catalyst] C::P::Email and testing
Jonathan Rockway
jon at jrock.us
Sat Dec 16 09:39:59 GMT 2006
On Saturday 16 December 2006 03:08, Sébastien Wagener wrote:
> On Sat, 2006-12-16 at 07:45 +0100, Daniel McBrearty wrote:
> > if you have an action that sends an email, how do you write tests for it?
> >
> > perhaps print the email to a temp file in test mode? what do you guys do?
>
> I am currently considering writing tests for my e-mails too.
> You could set __PACKAGE__->config->{email} to "Test" if some env
> variable is set, and dump Email::Send::Test->emails to a file in an end
> action. Or you could provide a testing action to display (and clear) the
> sent e-mails.
> I have a similar problem with the values of my captchas.
> Btw.: Are there any best practices to hide an action unless in testing
> mode? Protect it by an ACL rule if an environment variable is set?
I'm not aware of anything that does this now (but I don't look at the ACL
stuff very often), but you could implement this as an ActionClass:
package MyApp::Action::Testing;
use base 'Catalyst::Action';
sub execute {
my $self = shift;
die "You can't use this action!" unless $ENV{MYAPP_TESTING};
return $self->NEXT::execute( @_ );
}
1;
then
package MyApp::Controller::Whatever;
# ...
sub foo : Local : ActionClass('Testing') {
$c->response->body('All tests successful.');
}
Completely untested, but it should work. Assuming this is useful, I'll CPAN
it.
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061216/f8a93407/attachment.pgp
More information about the Catalyst
mailing list