Skip to content

Instantly share code, notes, and snippets.

@virtix
Created July 14, 2010 21:07
Show Gist options
  • Save virtix/476072 to your computer and use it in GitHub Desktop.
Save virtix/476072 to your computer and use it in GitHub Desktop.
<cfcomponent extends="mxunit.framework.TestCase">
<cfscript>
/**
* Assume cut has two methods: calculate() and getDataFromDatabase().
* getDataFromDatabase() goes to a Db, which we want to control, and
* calculate() calls getDataFromDatabase(). We want to stub only getDataFromDatabase().
*
* This "partial" mocking allows one to run tests on a component and mock specific methods
* in that component.
*/
function partialMockingSyntax(){
cut = mock( 'com.foo.bar' );
cut.when().getDataFromDatabase().returns( someQueryObject );
assertEquals( expected, cut.calculate() );
}
</cfscript>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment