Skip to content
Browse files

add .at(path) method

  • Loading branch information...
1 parent 755f4d9 commit 940db21421e52bd3ebb6a05fd4a520bd483bb1cf @eldargab committed Sep 2, 2012
Showing with 30 additions and 0 deletions.
  1. +19 −0 lib/fake-fs.js
  2. +11 −0 test/fake-fs.js
View
19 lib/fake-fs.js
@@ -1,5 +1,6 @@
var stat = require('./stat')
var normalize = require('path').normalize
+var join = require('path').join
function FsError (code) {
var err = new Error(code)
@@ -22,6 +23,24 @@ Fs.prototype.file = function (path, content, encoding) {
return this._add(path, new stat.File(content, encoding))
}
+Fs.prototype.at = function (path) {
+ return {
+ _fs: this,
+
+ dir: function (p) {
+ p = join(path, p).replace('\\', '/')
+ this._fs.dir.apply(this._fs, arguments)
+ return this
+ },
+
+ file: function (p) {
+ p = join(path, p).replace('\\', '/')
+ this._fs.file.apply(this._fs, arguments)
+ return this
+ }
+ }
+}
+
Fs.prototype._add = function (path, item) {
var segs = path.split('/')
var dir = this.root
View
11 test/fake-fs.js
@@ -85,6 +85,17 @@ describe('Fake FS', function () {
})
})
+ describe('.at(path)', function () {
+ it('Returns proxy for defining items prefixed with `path`', function () {
+ fs.at('home')
+ .file('.gitignore')
+ .dir('.local')
+ fs.statSync('home/.gitignore').isFile().should.be.true
+ fs.statSync('home/.local').isDirectory().should.be.true
+ })
+ })
+
+
describe('.stat()', function () {
it('Should return stats', function () {
fs.file('a/b/c', {ctime: 123}).stat('a/b/c', cb)

0 comments on commit 940db21

Please sign in to comment.
Something went wrong with that request. Please try again.