Skip to content

Commit

Permalink
moved more Repository tests over to Mocha.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Day committed May 23, 2012
1 parent 05abff8 commit 8a9a6d4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 53 deletions.
32 changes: 0 additions & 32 deletions oldtest/repository.test.js
Expand Up @@ -35,18 +35,6 @@ var existingBareRepoVows = function(topic) {
/*"Commits are not redundant": function(repo) {
assert.isTrue(repo.getCommit(fixtureValues.FIRST_COMMIT.id) === repo.getCommit(fixtureValues.FIRST_COMMIT.id));
},*/
"Exists() *asynchronously*": {
topic: function(repo) {
repo.exists(fixtureValues.FIRST_COMMIT.id, this.callback);
},

"works correctly": function(result) {
assert.isTrue(result);
}
},
"Exists() *synchronously*": function(repo) {
assert.isTrue(repo.exists(fixtureValues.FIRST_COMMIT.id));
}
}
}

Expand Down Expand Up @@ -78,24 +66,4 @@ var existingBareRepoVows = function(topic) {
assert.equal(repo.path, fixtureValues.WORKING_DIR.gitDirectory);
}
}*/

// TODO: probably nice to clean these up afterwards even though they're temp
"Initializing a new bare repository *asynchronously*": {
topic: function() {
var path = this.context.path = temp.path() + "/";
gitteh.initRepository(path, true, this.callback);
},

"gives us a Repository": function(repo) {
assert.instanceOf(repo, gitteh.Repository);
},

"is bare": function(repo) {
assert.isTrue(repo.bare);
},

"has the correct path": function(repo) {
assert.equal(repo.path, this.context.path);
}
}
}).export(module);
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -13,7 +13,8 @@
"async": ">= 0.1.8",
"temp": "~0.4.0",
"should": "~0.6.3",
"mocha": "~1.0.3"
"mocha": "~1.0.3",
"wrench": "~1.3.9"
},
"repository": {
"type": "git",
Expand Down
75 changes: 55 additions & 20 deletions test/test.repository.coffee
@@ -1,35 +1,70 @@
path = require "path"
should = require "should"
temp = require "temp"
wrench = require "wrench"
gitteh = require "../lib/gitteh"

selfRepo = path.join __dirname, ".."
selfRepoGitPath = path.join selfRepo, ".git/"

describe "Gitteh", ->
describe "#openRepository", ->
describe "#openRepository()", ->
describe "on an invalid path", ->
it "should fail with an Exception", (done) ->
gitteh.openRepository "/i/shouldnt/exist", (err) ->
err.should.be.an.instanceof Error
done()
describe "on project repo", ->
repo = null
it "should open correctly", (done) ->
gitteh.openRepository selfRepo, done
it "should not be bare", (done) ->
gitteh.openRepository selfRepo, (err, repo) ->
repo.bare.should.be.false
done()
it "should have immutable bare property", (done) ->
gitteh.openRepository selfRepo, (err, repo) ->
repo.bare = 123
repo.bare.should.be.false
done()
it "should have correct path to git dir", (done) ->
gitteh.openRepository selfRepo, (err, repo) ->
repo.path.should.equal path.join selfRepo, ".git/"
done()
it "should have an immutable git path", (done) ->
gitteh.openRepository selfRepo, (err, repo) ->
repo.path = "foo"
repo.path.should.equal path.join selfRepo, ".git/"
gitteh.openRepository selfRepo, (err, _repo) ->
repo = _repo
repo.should.be.an.instanceof gitteh.Repository
done()
describe "#initRepository()", ->
describe "on an invalid path", ->
it "should fail with an Exception", (done) ->
gitteh.openRepository "/i/shouldnt/exist", (err) ->
gitteh.initRepository "/i/shouldnt/exist", (err) ->
err.should.be.an.instanceof Error
done()
describe "initializing a bare repository", ->
tempPath = "#{temp.path()}/"
repo = null
describe "to temp location #{tempPath}", ->
after ->
wrench.rmdirSyncRecursive tempPath, true
it "should initialize correctly", (done) ->
gitteh.initRepository tempPath, true, (err, _repo) ->
repo = _repo
repo.should.be.an.instanceof gitteh.Repository
done()
it "should definitely be bare", ->
repo.bare.should.be.true
it "should be in the right place", ->
repo.path.should.be.equal tempPath

describe "Repository", ->
describe "Using the project repo...", ->
repo = null
it "opens correctly", (done) ->
gitteh.openRepository selfRepo, (err, _repo) ->
repo = _repo
repo.should.be.an.instanceof gitteh.Repository
done()
describe "#bare", ->
it "should be false for this repo", ->
repo.bare.should.be.false
it "should be immutable", ->
repo.bare = 123
repo.bare.should.be.false
describe "#path", ->
it "should point to #{selfRepoGitPath}", ->
repo.path.should.equal selfRepoGitPath
it "should be immutable", ->
repo.path = "foo"
repo.path.should.equal selfRepoGitPath
describe "#exists()", ->
it "should return true for first commit in repo :)", (done) ->
repo.exists "1f4425ce2a14f21b96b9c8dde5bcfd3733467b14", (err, exists) ->
exists.should.be.true
done()

0 comments on commit 8a9a6d4

Please sign in to comment.