[Catalyst] using Plugin::Singleton and testing

Daniel McBrearty danielmcbrearty at gmail.com
Wed Nov 15 10:25:14 GMT 2006


I have a method in a model that goes like this:

sub do_something {
    my ($self, $my_var) = @_;

    $my_var = MyApp->context->stash->{my_var} unless defined $my_var;
    die "my_var not defined" unless defined $my_var;

.
.
.

}

so my_var gets it's value by the arg, the stash or gives up and causes
an error. This seems to work fine.

Now in my test script, I use the app ...

use MyApp;

and I want to set the stash in test code. I don't want to mock the
whole of MyApp, because that is being used to get the database via the
model elsewhere

my $schema = MyApp->model('Db')->schema;

and I'd rather leave that in place.

How can I just mock the context/stash but leave the rest of MyApp in place?

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131



More information about the Catalyst mailing list