MockBox generation path in ColdBox integration tests

When using the MockBox ColdFusion Mocking Framework to generate mock objects dynamically, it requires that the ColdFusion server have write access to a filesystem location to save the CFC files. By default, this path is /[mockbox|coldbox]/system/testing/stubs, depending on whether MockBox is used standalone, or within ColdBox. When I was getting started with MockBox, I created that directory with mode 0777 on the disk, which always makes me feel uneasy. There's a better way to handle this situation: create a per-application mapping to a location in a in-memory filesystem. For example, consider the following chunk of an Application.cfc:

<cfset this.name = "MyApp"/> <cfset this.mappings = structNew()/> <cfset this.mappings["/coldbox/system/testing/stubs"] = "ram://MyApp/mockbox/stubs/"/> <cfif not directoryExists("ram://MyApp/mockbox/stubs/")> <cfset directoryCreate("ram://MyApp/mockbox/stubs/")/> </cfif>

When the MockGenerator now writes out files, it will be placing them in memory briefly. It works a treat. Of course, the in-memory filesystems are supported in relatively recent CFML engines. If I remember correctly, Railo had this feature first, and I don't know when it was added to Open BlueDragon. Adobe ColdFusion 9 has it, and can be toggled on/off in the ColdFusion Administrator interface.

I whipped up a little test application that can be used to verify that in-memory filesystem mappings are working correctly in your environment: in-memory-filesystem-mapping.zip