[Catalyst] Mocking for Catalyst testing
Stuart Watt
swatt at infobal.com
Sun Jan 17 18:36:53 GMT 2010
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 } );
The ignore_loaded seems to bypass everything and overwrite my newly mocked class just when I need it. I get the method redefined, and a warning about it. The comment in the code here says this is needed for some Schema::Loader functionality dependent on loading even when the class exists. Doesn't this make mocking impossible?
The ignore_loaded => 1 setting seems a somewhat heavy assumption to make for all components.
Can anyone offer a way around this that doesn't involve too much patching?
All the best
Stuart
More information about the Catalyst
mailing list