Test::MockObject: What am I missing?

2006-10-05 Thread Christopher H. Laco
I'm having a idiot moment...

I'm trying to mock out some config reading tests for reading from
MP1/MP2 even though I don't have either installed. so I thought
Test::MockObjext is the answer!.

The following code goes boom with a 'Can't locate object method request
via package Apache':

 use strict;
 use warnings;
 use Test::MockObject;
 
 my $mock = Test::MockObject-new;
 $mock-fake_module('Apache');
 $mock-set_series(undef, $mockrequest);
 
 warn Apache-request;

If I change the fake_module call to
Test::MockObject-fake_module('Apache'), the code gets happt, but it
appears I can then install subs into that Apache using any of the set_
helpers.

Or am I just missing something?

The pod mentions that fake_module is a class and object method, but
doesn't really extol the virtues on when to use one over the other.

Someone cluestick me please.

-=Chris



signature.asc
Description: OpenPGP digital signature


Re: Test::MockObject: What am I missing?

2006-10-05 Thread chromatic
On Thursday 05 October 2006 12:25, Christopher H. Laco wrote:

 I'm having a idiot moment...

 I'm trying to mock out some config reading tests for reading from
 MP1/MP2 even though I don't have either installed. so I thought
 Test::MockObjext is the answer!.

 The following code goes boom with a 'Can't locate object method request

 via package Apache':
  use strict;
  use warnings;
  use Test::MockObject;
 
  my $mock = Test::MockObject-new;
  $mock-fake_module('Apache');
  $mock-set_series(undef, $mockrequest);
 
  warn Apache-request;

 If I change the fake_module call to
 Test::MockObject-fake_module('Apache'), the code gets happt, but it
 appears I can then install subs into that Apache using any of the set_
 helpers.

 Or am I just missing something?

 The pod mentions that fake_module is a class and object method, but
 doesn't really extol the virtues on when to use one over the other.

 Someone cluestick me please.

Test::MockObject primarily returns you an object on which you can mock and 
call mocked methods.  fake_module() lets you install new methods into the 
mocked class by passing name and subref pairs, but that's really not the 
point of the module.

-- c


Re: Test::MockObject: What am I missing?

2006-10-05 Thread Christopher H. Laco
chromatic wrote:
 On Thursday 05 October 2006 12:25, Christopher H. Laco wrote:
 
 I'm having a idiot moment...

 I'm trying to mock out some config reading tests for reading from
 MP1/MP2 even though I don't have either installed. so I thought
 Test::MockObjext is the answer!.

 The following code goes boom with a 'Can't locate object method request

 via package Apache':
 use strict;
 use warnings;
 use Test::MockObject;

 my $mock = Test::MockObject-new;
 $mock-fake_module('Apache');
 $mock-set_series(undef, $mockrequest);

 warn Apache-request;
 If I change the fake_module call to
 Test::MockObject-fake_module('Apache'), the code gets happt, but it
 appears I can then install subs into that Apache using any of the set_
 helpers.

 Or am I just missing something?

 The pod mentions that fake_module is a class and object method, but
 doesn't really extol the virtues on when to use one over the other.
 
 Someone cluestick me please.
 
 Test::MockObject primarily returns you an object on which you can mock and 
 call mocked methods.  fake_module() lets you install new methods into the 
 mocked class by passing name and subref pairs, but that's really not the 
 point of the module.
 
 -- c
 
 

I won't pretend not be be confused at the moment then, because I have
other tests that do:

T::MO-new-fake_module('Foo'), and classes that 'use Foo' and do
'Foo-new' just work with the mocked verson. At least, I thought they
did, and they don't throw the same error.

So, all of that aside, what is everyone else using in this type of
scenario of mocking classes used by all rather than passing mocked
object around?

Test::MockModule/MockClass looks like it will do.

-=Chris




signature.asc
Description: OpenPGP digital signature


Re: Test::MockObject: What am I missing?

2006-10-05 Thread Christopher H. Laco
chromatic wrote:
 On Thursday 05 October 2006 12:25, Christopher H. Laco wrote:
 
 I'm having a idiot moment...

 I'm trying to mock out some config reading tests for reading from
 MP1/MP2 even though I don't have either installed. so I thought
 Test::MockObjext is the answer!.

 The following code goes boom with a 'Can't locate object method request

 via package Apache':
 use strict;
 use warnings;
 use Test::MockObject;

 my $mock = Test::MockObject-new;
 $mock-fake_module('Apache');
 $mock-set_series(undef, $mockrequest);

 warn Apache-request;
 If I change the fake_module call to
 Test::MockObject-fake_module('Apache'), the code gets happt, but it
 appears I can then install subs into that Apache using any of the set_
 helpers.

 Or am I just missing something?

 The pod mentions that fake_module is a class and object method, but
 doesn't really extol the virtues on when to use one over the other.
 
 Someone cluestick me please.
 
 Test::MockObject primarily returns you an object on which you can mock and 
 call mocked methods.  fake_module() lets you install new methods into the 
 mocked class by passing name and subref pairs, but that's really not the 
 point of the module.
 
 -- c
 
 

How is above any different than this: s/GEO::IP/Apache/ ?

http://www.perl.com/pub/a/2005/04/07/mockobject_kata.html?page=2

Obviously, my brain is not working right today.





signature.asc
Description: OpenPGP digital signature


Re: Test::MockObject: What am I missing?

2006-10-05 Thread chromatic
On Thursday 05 October 2006 12:48, Christopher H. Laco wrote:

 I won't pretend not be be confused at the moment then, because I have
 other tests that do:

 T::MO-new-fake_module('Foo'), and classes that 'use Foo' and do
 'Foo-new' just work with the mocked verson. At least, I thought they
 did, and they don't throw the same error.

They'd better not, because there's no code in T::MO that gives you a default 
constructor.  Perhaps you're using fake_new() instead?

 How is above any different than this: s/GEO::IP/Apache/ ?

 http://www.perl.com/pub/a/2005/04/07/mockobject_kata.html?page=2

 Obviously, my brain is not working right today.

Let me put it another way.  In the absence of you explicitly saying Pretend 
that you've loaded this module and pretend that these subroutine references 
correspond to these method names, how is it possible that T::MO can provide 
all of the appropriate methods that your code wants to use later in the test 
file, perform the appropriate behavior, and return the appropriate values?

It doesn't do that.  What in the documentation leads you to believe it does?  
If I can clarify the behavior, I will.

-- c