/**
* Diffing tool instance
* @const
*/
var DEFAULT_DIFFER = require('./adaptors/looks-same.js');

/**
* Module for file system interaction
* @const
*/
var DEFAULT_FS = require('./adaptors/fs.js');

/**
* Root directory of the screenshots
* @type {String}
* @const
* @default
*/
var DEFAULT_ROOT_DIRECTORY = 'visual-tests';

/**
* File extension for images
*
* @type {String}
* @const
* @default
*/
var IMAGE_EXTENSION = '.png';

/**
* Name extension for screenshot
*
* @type {String}
* @const
* @default
*/
var SCREENSHOT_NAME = '.new';

/**
* Name extension for diff image
*
* @type {String}
* @const
* @default
*/
var DIFF_NAME = '.diff';


/**
* @param {Browser} browser - Instance of some browser
* @param {Object} [options]
* @param {Differ} [options.differ] - A diffing tool instance
* @param {FS} [options.fs] - A module to interact with the file system
* @param {String} [options.rootDirectory='visual-tests'] - The directory
*     where the screenshots will be saved
* @constructor
*/
function Mugshot(browser, options) {
  if (browser === undefined) {
    throw new Error('No browser instance was provided');
  }

  this._browser = browser;

  if (arguments.length >= 2 &&
      (typeof options !== 'object' || options instanceof Array)) {
    throw new Error('options is not an obejct');
  }

  options = options || {};
  this._options = {};

  this._options.differ = options.differ || DEFAULT_DIFFER;
  this._options.fs = options.fs || DEFAULT_FS;
  this._options.rootDirectory = options.rootDirectory || DEFAULT_ROOT_DIRECTORY;
}

/**
* @param {Object} captureItem - Details about what will be captured
* @param {String} [captureItem.selector] - A html or css selector
* @param {String} captureItem.name - A name for the screenshot without extension
*/
Mugshot.prototype.test = function(captureItem) {
  var fs = this._options.fs,
      browser = this._browser,
      differ = this._options.differ;

  browser.takeScreenshot(function(error, screenshot) {

    fs.exists(captureItem.name, function(exists) {
      if (!exists) {
        fs.writeFile(captureItem.name, screenshot, function(error) {

        });
      }
      else {
        fs.readFile(captureItem.name, function(error, baseline) {

          differ.isEqual(baseline, screenshot, function(error, equal) {
            if (!equal) {
              differ.createDiff(baseline, screenshot, function(error, diff) {
                var diffName = captureItem.name + '.diff.png';
                fs.writeFile(diffName, diff, function(error) {

                });

                var screenshotName = captureItem.name + '.new.png';
                fs.writeFile(screenshotName, screenshot, function(error) {

                });
              });
            }
          });
        });
      }
    });
  });
};

module.exports = Mugshot;

@@ -1,12 +1,41 @@
+var path = require('path');%0A%0A
 /**%0A* Diffin
@@ -1933,16 +1933,97 @@
 s.differ
+,%0A      getPath = composeImagePath(this._options.rootDirectory, captureItem.name)
 ;%0A%0A  bro
@@ -2157,37 +2157,73 @@
     
-fs.writeFile(captureItem.name
+var baselinePath = getPath('');%0A        fs.writeFile(baselinePath
 , sc
@@ -2555,45 +2555,33 @@
 diff
-Name = captureItem.name + '.diff.png'
+Path = getPath(DIFF_NAME)
 ;%0A  
@@ -2611,20 +2611,20 @@
 ile(diff
-Name
+Path
 , diff, 
@@ -2697,44 +2697,39 @@
 shot
-Name = captureItem.name + '.new.png'
+Path = getPath(SCREENSHOT_NAME)
 ;%0A  
@@ -2765,20 +2765,20 @@
 reenshot
-Name
+Path
 , screen
@@ -2906,16 +2906,546 @@
 %7D);%0A%7D;%0A%0A
+/**%0A* Builds the path of an image on disk%0A*%0A* @param %7BString%7D rootDirectory - Root directory of the screenshots%0A* @param %7BString%7D baseName - A name for the screenshot without extension%0A* @returns %7BFunction%7D%0A*/%0Afunction composeImagePath(rootDirectory, baseName) %7B%0A  /**%0A  * @param %7BString%7D - An extension to give more info about the image%0A  * @returns %7BString%7D The path on the disk%0A  */%0A  return function(extensionName) %7B%0A    var name = baseName + extensionName + IMAGE_EXTENSION;%0A    return path.join(rootDirectory, name);%0A  %7D%0A%7D%0A%0A
 module.e

use the new path, included the rootDirectory