On 17 Jan 2010, at 18:36, Stuart Watt wrote:
On 2010-01-16, at 10:31 PM, Tomas Doran wrote:
I tend to just use Moose directly to construct mock classes for me:
Things are improving, t0m. I tried
use Class::MOP;
use Class::MOP::Class;
my $meta_refreshes = Class::MOP::Class-
>create('ARMAdmin::Model::Refreshes');
$meta_refreshes->add_method('get_profiles' => sub { die("Failed to
get profiles"); });
Then I start the app in the test framework. I'm just after getting
the get_profiles mocked method called here, later I want it to
return values I can test in the generated page.
However, Catalyst then calls:
Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded =>
1 } );
Right, hang on.. Why are you mocking things and then loading the
entire application?
Usually you either run the full app for system testing (with test
config that points at a test DB or whatever), or you mock _lots of
stuff_ (like the context class, the request and response) and unit
test one component..
Trying to mangle methods then load the full app won't work..
If you reaaaaalllly need to do this - use Catalyst::Test 'MyApp', then
manipulate the class after catalyst has loaded it (e.g my $meta =
MyApp::Model::Foo->meta; $meta->remove_method('bar'); $meta-
>add_method('bar' => sub { die("New bar") }); )
but I'd not recommend it..
Cheers
t0m
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/