[Catalyst-commits] r9920 - in Catalyst-Runtime/5.80/trunk: . t
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Tue Apr 28 19:30:39 GMT 2009
Author: t0m
Date: 2009-04-28 20:30:39 +0100 (Tue, 28 Apr 2009)
New Revision: 9920
Added:
Catalyst-Runtime/5.80/trunk/t/unit_core_setup_stats.t
Modified:
Catalyst-Runtime/5.80/trunk/Changes
Catalyst-Runtime/5.80/trunk/TODO
Log:
Tests for setup_stats, its all good..
Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes 2009-04-28 18:19:08 UTC (rev 9919)
+++ Catalyst-Runtime/5.80/trunk/Changes 2009-04-28 19:30:39 UTC (rev 9920)
@@ -15,6 +15,7 @@
disabling functionality from base controllers. (t0m)
- Bump Moose dependency to latest version to fix metaclass
incompatibility issues in some cases. (t0m)
+ - Additional tests for setup_stats method. (t0m)
5.80002 2009-04-22 01:28:36
- Fix CATALYST_DEBUG and MYAPP_DEBUG environment variables
Modified: Catalyst-Runtime/5.80/trunk/TODO
===================================================================
--- Catalyst-Runtime/5.80/trunk/TODO 2009-04-28 18:19:08 UTC (rev 9919)
+++ Catalyst-Runtime/5.80/trunk/TODO 2009-04-28 19:30:39 UTC (rev 9920)
@@ -1,7 +1,5 @@
Bugs:
- Make logging levels properly additive.
- - Stats bugs?
- - Moose tests failing - new MX::MethodAttributes helps with this somewhat.
- Chained bugs in http://github.com/bobtfish/catalyst-app-bug-go_chain/tree/master
Added: Catalyst-Runtime/5.80/trunk/t/unit_core_setup_stats.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_core_setup_stats.t (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/unit_core_setup_stats.t 2009-04-28 19:30:39 UTC (rev 9920)
@@ -0,0 +1,59 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Test::MockObject;
+
+use Catalyst ();
+
+my %log_messages; # TODO - Test log messages as expected.
+my $mock_log = Test::MockObject->new;
+foreach my $level (qw/debug info warn error fatal/) {
+ $mock_log->mock($level, sub {
+ $log_messages{$level} ||= [];
+ push(@{ $log_messages{$level} }, $_[1]);
+ });
+}
+
+sub mock_app {
+ my $name = shift;
+ %log_messages = (); # Flatten log messages.
+ print "Setting up mock application: $name\n";
+ my $meta = Moose->init_meta( for_class => $name );
+ $meta->superclasses('Catalyst');
+ $meta->add_method('log', sub { $mock_log });
+ return $meta->name;
+}
+
+local %ENV; # Ensure blank or someone, somewhere will fail..
+
+{
+ my $app = mock_app('TestNoStats');
+ $app->setup_stats();
+ ok !$app->use_stats, 'stats off by default';
+}
+{
+ my $app = mock_app('TestStats');
+ $app->setup_stats(1);
+ ok $app->use_stats, 'stats on if you say >setup_stats(1)';
+}
+{
+ my $app = mock_app('TestStatsDebugTurnsStatsOn');
+ $app->meta->add_method('debug' => sub { 1 });
+ $app->setup_stats();
+ ok $app->use_stats, 'debug on turns stats on';
+}
+{
+ local %ENV = ( CATALYST_STATS => 1 );
+ my $app = mock_app('TestStatsAppStatsEnvSet');
+ $app->setup_stats();
+ ok $app->use_stats, 'ENV turns stats on';
+}
+{
+ local %ENV = ( CATALYST_STATS => 0 );
+ my $app = mock_app('TestStatsAppStatsEnvUnset');
+ $app->meta->add_method('debug' => sub { 1 });
+ $app->setup_stats(1);
+ ok !$app->use_stats, 'ENV turns stats off, even when debug on and ->setup_stats(1)';
+}
+
More information about the Catalyst-commits
mailing list