/*global describe, it, before*/
/*
 * Test the loader
 */

var expect = require('unexpected'),
    oconf = require('../lib/index'),
    path = require('path');

// Helper - resolve files relative to this dir, not vows's CWD.
function resolve(filename) {
    return path.resolve(__dirname, filename);
}

// The tests!
describe('Basic tests', function () {

    describe('base.cjson', function () {
        var data;

        before(function () {
            data = oconf.load(resolve('./files/base.cjson'));
        });

        it('Has foo = "overwrite this"', function () {
            expect(data, 'to have property', 'foo', 'overwrite this');
        });

        it('Has what = "this is from default.cjson."', function () {
            expect(data, 'to have property', 'what', 'this is from default.cjson.');
        });

        it('Only has "foo" and "what"-keys', function () {
            expect(data, 'to only have keys', ['foo', 'what']);
        });

    });

    describe('extend-base.cjson', function () {
        var data;

        before(function () {
            data = oconf.load(resolve('./files/extend-base.cjson'));
        });

        it('Has foo = "bar" (i.e. overwritten)', function () {
            expect(data, 'to have property', 'foo', 'bar');
        });

        it('Has what = "this is from default.cjson."', function () {
            expect(data, 'to have property', 'what', 'this is from default.cjson.');
        });

        it('Only has "foo" and "what"-keys', function () {
            expect(data, 'to only have keys', ['foo', 'what']);
        });

    });

    /*
}).addBatch({
    'extend-in-subobject.cjson': {
        'subobject = `contents of extend-base.cjson`': function (res) {
            assert.deepEqual(
                res.subobject,
                {
                    foo: "bar",
                    what: "this is from default.cjson."
                }
            );
        }
    }
     */

    describe('extend-in-subobject.cjson', function () {
        var data;

        before(function () {
            data = oconf.load(resolve('./files/extend-in-subobject.cjson'));
        });

        it('Has subobject = contents of extend-base.cjson', function () {
            expect(data, 'to equal', {
                'subobject': {
                    'foo': 'bar',
                    'what': 'this is from default.cjson.'
                }
            });
        });
    });

    describe('loop1.cjson / loop2.cjson', function () {

        it('Loading loop1.cjson throws error', function () {
            expect(function () {
                oconf.load(resolve('./files/loop1.cjson'));
            }, 'to throw', /^Loop in loaded files: /);
        });

        it('Loading loop2.cjson throws error', function () {
            expect(function () {
                oconf.load(resolve('./files/loop2.cjson'));
            }, 'to throw', /^Loop in loaded files:/);
        });
    });

    describe('includeNonExistentFile.cjson', function () {
        it('should throw an error when nonExistentFile.cjson is not ignored', function () {
            expect(function () {
                oconf.load(resolve('./files/includeNonExistentFile.cjson'));
            }, 'to throw', /^ENOENT, no such file or directory/);
        });

        it('should not throw an error when nonExistentFile.cjson is ignored', function () {
            expect(function () {
                oconf.load(resolve('./files/includeNonExistentFile.cjson'), {ignore: resolve('./files/nonExistentFile.cjson')});
            }, 'not to throw');
        });
    });
});

@@ -29,35 +29,8 @@
 e*/%0A
-/*%0A * Test the loader%0A */%0A%0A
 var 
@@ -131,72 +131,8 @@
 );%0A%0A
-// Helper - resolve files relative to this dir, not vows's CWD.%0A
 func
@@ -209,22 +209,8 @@
 %0A%7D%0A%0A
-// The tests!%0A
 desc
@@ -239,25 +239,24 @@
 nction () %7B%0A
-%0A
     describe
@@ -294,33 +294,32 @@
       var data;%0A
-%0A
         before(f
@@ -397,33 +397,32 @@
 ));%0A        %7D);%0A
-%0A
         it('Has 
@@ -535,33 +535,32 @@
 ');%0A        %7D);%0A
-%0A
         it('Has 
@@ -701,33 +701,32 @@
 ');%0A        %7D);%0A
-%0A
         it('Only
@@ -840,33 +840,32 @@
         %7D);%0A
-%0A
     %7D);%0A
 %0A    describ
@@ -844,33 +844,32 @@
     %7D);%0A    %7D);%0A
-%0A
     describe('ex
@@ -910,33 +910,32 @@
       var data;%0A
-%0A
         before(f
@@ -1020,33 +1020,32 @@
 ));%0A        %7D);%0A
-%0A
         it('Has 
@@ -1155,33 +1155,32 @@
 ');%0A        %7D);%0A
-%0A
         it('Has 
@@ -1321,33 +1321,32 @@
 ');%0A        %7D);%0A
-%0A
         it('Only
@@ -1464,25 +1464,24 @@
     %7D);%0A
-%0A
     %7D);%0A
 %0A    /*%0A
@@ -1476,362 +1476,8 @@
 %7D);%0A
-%0A    /*%0A%7D).addBatch(%7B%0A    'extend-in-subobject.cjson': %7B%0A        'subobject = %60contents of extend-base.cjson%60': function (res) %7B%0A            assert.deepEqual(%0A                res.subobject,%0A                %7B%0A                    foo: %22bar%22,%0A                    what: %22this is from default.cjson.%22%0A                %7D%0A            );%0A        %7D%0A    %7D%0A     */%0A%0A
     
@@ -1546,17 +1546,16 @@
 r data;%0A
-%0A
         
@@ -1656,33 +1656,32 @@
 ));%0A        %7D);%0A
-%0A
         it('Has 
@@ -1946,33 +1946,32 @@
     %7D);%0A    %7D);%0A
-%0A
     describe('lo
@@ -2010,17 +2010,16 @@
 on () %7B%0A
-%0A
         
@@ -2223,33 +2223,32 @@
 /);%0A        %7D);%0A
-%0A
         it('Load
@@ -2455,25 +2455,24 @@
 %7D);%0A    %7D);%0A
-%0A
     describe
@@ -2782,24 +2782,24 @@
 irectory/);%0A
+
         %7D);%0A
@@ -2798,17 +2798,16 @@
     %7D);%0A
-%0A
         

trim the test file