Capture-Replay Mocking with CaptureMock
Capturing environment variables
(and also current working directories)
Sometimes environment variables need to be provided for the programs being intercepted. As they are run directly from CaptureMock's server they don't automatically inherit any environment your program may have set up. These environment variables should be listed in the rc file, and then their values will also be sent to the CaptureMock server and will be part of the information recorded.
For example, if our system sets CVSROOT (which CVS uses to find its central repository) before calling CVS we will need to tell CaptureMock this. In this case we add this information in a comma-separated list in the rc file, either under the program's specific section or in the [command line] section. The following are both legal:
[command line]
intercepts = cvs

environment = CVSROOT
[command line]
intercepts = cvs
environment = CVSROOT
When we record, the mock file will now look like this:
<-CMD:env 'CVSROOT=/path/to/cvs' cvs update -dP /path/to/my/checkout
->OUT:U subdir/myfile.txt
->ERR:cvs update: Updating .
cvs update: Updating subdir
providing a means to make sure our program is providing it to the CVS call correctly. If environment variables were unset by the SUT this would also be recorded via "--unset" options to "env" on the first line.
(Note that this command isn't actually what CaptureMock executes, which of course would not work on Windows, it is just a representation of what it does which coincides with a legal UNIX command line. This mechanism is portable.)
The current working directory
In a similar way, if your program changes the current working directory for the program it calls, this will be captured and recorded by CaptureMock. In this case you don't need to do anything to configure it. For example your program might call CVS in a different but equivalent way to do the update, and the above call could equally end up looking like this:
<-CMD:cd /path/to/my/checkout; env 'CVSROOT=/path/to/cvs' cvs update -dP
Again this isn't what is executed internally: it is a representation only to allow easy comparison with future calls.

Last updated: 05 October 2012