var should = require('chai').should()
var Metalsmith = require('metalsmith')
var metadata = require('..')

it('should error if the JSON file is malformed', function (done) {
  var metalsmith = Metalsmith('test/fixtures/json-malformed').use(metadata({ directory: 'test/fixtures/json-malformed/src/**/*.json' }))
  metalsmith.build(function(err) {
    errMessage = String(err);
    errMessage.should.equal('Error: Malformed data in example.json')
    done() // don't return the error to metalsmith
  })
})

it('should read JSON and put into metalsmith.metadata()', function (done) {
  var metalsmith = Metalsmith('test/fixtures/json').use(metadata({ directory: 'test/fixtures/json/src/**/*.json' }))
  metalsmith.build(function(err) {
    metalsmith.metadata().should.deep.equal({ example: { text: 'Text from a json file' } })

    if (err) {
      return done(err)
    }

    done()
  })
})

@@ -369,16 +369,46 @@
 g(err);%0A
+    err.should.be.an('error')%0A
     errM
@@ -468,16 +468,17 @@
 .json')%0A
+%0A
     done

check to see if err is an error