1
0
mirror of https://github.com/danog/gift.git synced 2024-11-26 20:04:47 +01:00
gift/test/blob.test.coffee

79 lines
2.1 KiB
CoffeeScript
Raw Normal View History

2012-02-15 15:51:45 +01:00
should = require 'should'
fixtures = require './fixtures'
git = require '../src'
Blob = require '../src/blob'
describe "Blob", ->
describe "constructor", ->
repo = fixtures.branched
blob = new Blob repo, {name: "X", mode: "Y", id: "abc"}
it "assigns @name", ->
blob.name.should.eql "X"
it "assigns @mode", ->
blob.mode.should.eql "Y"
it "assigns @id", ->
blob.id.should.eql "abc"
2012-02-15 15:51:45 +01:00
describe "#data", ->
describe "of a file off the root", ->
repo = git "#{__dirname}/fixtures/branched"
data = null
before (done) ->
repo.tree().blobs (err, blobs) ->
blobs[0].data (err, _data) ->
data = _data
done err
2012-02-15 15:51:45 +01:00
it "is a string", ->
data.should.be.type "string"
2014-06-19 21:53:13 +02:00
data.should.containEql "Bla"
2012-02-15 15:51:45 +01:00
describe "of a file in a subdir", ->
repo = git "#{__dirname}/fixtures/branched"
data = null
before (done) ->
repo.tree().trees (err, trees) ->
trees[0].blobs (err, blobs) ->
blobs[0].data (err, _data) ->
data = _data
done err
2012-02-15 15:51:45 +01:00
it "is a string", ->
data.should.be.type "string"
2014-06-19 21:53:13 +02:00
data.should.containEql "!!!"
2012-02-15 15:51:45 +01:00
2014-03-06 03:25:47 +01:00
describe "#dataStream", ->
describe "of a file off the root", ->
repo = git "#{__dirname}/fixtures/branched"
data = ""
before (done) ->
repo.tree().blobs (err, blobs) ->
[dataStream, _] = blobs[0].dataStream()
dataStream.on 'data', (buf) ->
data += buf.toString()
.on 'end', ->
done()
it "is a string", ->
data.should.be.type "string"
2014-06-19 21:53:13 +02:00
data.should.containEql "Bla"
2014-03-06 03:25:47 +01:00
describe "of a file in a subdir", ->
repo = git "#{__dirname}/fixtures/branched"
data = ""
before (done) ->
repo.tree().trees (err, trees) ->
trees[0].blobs (err, blobs) ->
[dataStream, _] = blobs[0].dataStream()
dataStream.on 'data', (buf) ->
data += buf.toString()
.on 'end', ->
done()
it "is a string", ->
data.should.be.type "string"
2014-06-19 21:53:13 +02:00
data.should.containEql "!!!"
2014-03-06 03:25:47 +01:00