[Catalyst] Catalyst testing

Kieren Diment diment at gmail.com
Mon Jul 31 04:23:23 CEST 2006


Ah, the other filesystem blog thingy author :)

Here's how I did it:

in each test file that needs the config I have:
require 't/lib/util.pl'; # contains change_config sub below
use PodCMS;
my $mech = Test::WWW::Mechanize::Catalyst->new;
change_config (PodCMS->config);

then in t/util.pl:

sub change_config {
    my $config = shift;
    my $root =  dir($config->{root_dir});
    my $newroot = $root->parent;
    $newroot = $newroot->subdir('t')->subdir('root');
    $config->{root_dir} = $newroot;
}

of course you can use YAML qw/LoadFile/ and use that to instantiate your
current config rather than overriding specific values which is what I did.



On 31/07/06, Jonathan Rockway <jon at jrock.us> wrote:
>
> Here's something that's been bugging me for a while.  With
> Catalyst::Test, you don't have any chance to change MyApp->config before
> your various models and views are instantiated.  In my foo.t, I want to:
>
> 1. Load the Catalyst module (has to happen eventually).
> 2. Before my models get instantiated, dynamically generate the
> configuration.  Basically this consists of creating a temporary
> directory somewhere, and setting MyApp->config->{base} to point to it.
> (In case you missed my YAPC talk, my blog software stores everything in
> the filesystem.  I want a clean slate to start with, then my test adds
> articles and comments and makes sure everything works as expected.)
> 3. Let Catalyst startup.
>
> If Catalyst starts before the config is changed, it will die during
> Model instantiation because config->{base} is invalid.  So as you can
> see, I'm having a hard time writing good tests :)   (I could use the
> default, hard-coded {base}, but I'm against touching the user's
> filesystem during tests.  Autocreated tempdirs are fine, but using their
> actual config file and messing around with things is unacceptable. :)
>
> Any ideas / suggestions would be appreciated.  Thanks!
>
> Oh, and here's the software in question:
> L<http://www.jrock.us/trac/blog_software/>.  (Still pre-alpha, though,
> so don't flame me too much :)
>
> Regards,
> Jonathan Rockway
>
>
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060731/7d528703/attachment-0001.htm 


More information about the Catalyst mailing list