var through = require("through");
var path = require("path");

console.warn("Injecting Rewireify into modules");

module.exports = function rewireify(file, options) {
  options = {
    ignore: options.ignore || ""
  };

  var ignore = ["__get__", "__set__", "rewire"].concat(options.ignore.split(","));

  if (/\.json$/.test(file) || ignore.indexOf(path.basename(file, ".js")) > -1) {
    return through();
  }

  var data = "";
  var fore = "";
  var post = "";

  function write(buffer) {
    data += buffer;
  }

  function end() {

    fore += "/* This code was injected by Rewireify */\n";
    fore += "var __getter = require(\"" + path.join(__dirname, "__get__") + "\").toString();\n";
    fore += "var __setter = require(\"" + path.join(__dirname, "__set__") + "\").toString();\n";

    post += "\n";
    post += "eval(__getter);\n"
    post += "eval(__setter);\n"
    post += "module.exports.__get__ = __get__;\n";
    post += "module.exports.__set__ = __set__;\n";

    this.queue(fore);
    this.queue(data);
    this.queue(post);
    this.queue(null);
  }

  return through(write, end);
};

@@ -426,25 +426,8 @@
 %22%22;%0A
-  var fore = %22%22;%0A
   va
@@ -439,16 +439,16 @@
 t = %22%22;%0A
+
 %0A  funct
@@ -512,28 +512,28 @@
 nd() %7B%0A%0A    
-fore
+post
  += %22/* This
@@ -567,36 +567,36 @@
 eify */%5Cn%22;%0A    
-fore
+post
  += %22var __gette
@@ -672,20 +672,20 @@
 n%22;%0A    
-fore
+post
  += %22var
@@ -761,25 +761,24 @@
 ring();%5Cn%22;%0A
-%0A
     post += 
@@ -954,30 +954,8 @@
 %22;%0A%0A
-    this.queue(fore);%0A
     

Move getter and setter require statements to post so that test error line numbers are not skewed