RIAForge Forums Home | Search | RSS
New Topic Reply   Previous Page  Page: 1   Previous Page

Thread: Creation of hybrid real/mocked objects
Created on: 05/15/09 01:54 PM Replies: 1

Joined: 06/02/08
Posts: 5
Creation of hybrid real/mocked objects
05/15/09 1:54 PM

There are cases where you may 90% of the behavior of a class as is but want to mock just a few methods. Currently ColdMock clears all the methods. With just a few simple changes you can have the methods be cleared only when you call mockMethod. To do this, add a clearMethods argument to the createMock method in MockFactory with a default of true. Around line 68 where the StructClear(mock) line is, replace with:

<cfif arguments.clearMethods>
<cfset StructClear(mock) />
<cfset StructDelete(this,"onMissingMethod")>

Finally, in the mockMethod call around line 152 add:

<cfset StructDelete(this,arguments.methodName)>

this allows the onMissingMethod handler to call the mocked method instead of the one that was there.

That's it.
Link | Top | Bottom

Joined: 06/21/11
Posts: 2
[url=http://bathroomtv.org]Hello,Everybody ![/url]
07/24/11 11:46 PM

Wow,Fantastic article,it's so helpful to me,and your blog is very good,I've learned a lot from your blog here,Keep on going,my friend,I will keep an eye on it,One more thing,thanks for your post! welcome to <a href=http://bathroomtv.org>bathroom tv</a>.
Link | Top | Bottom

New Post
Please login to post a response.