Skip to content

Commit

Permalink
added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Aug 31, 2011
1 parent 882dd28 commit 34be99f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/bank/bank.js
Expand Up @@ -6,8 +6,8 @@ var Account = {
this.balance -= money;
},
transfer: function(ac, money) {
this.balance -= money;
ac.balance += money;
this.withdraw(money);
ac.deposit(money);
},
statement: function() {
return this.balance;
Expand Down
19 changes: 12 additions & 7 deletions examples/bank/contracts/bank.js
Expand Up @@ -4,18 +4,22 @@ var contract = require("../../../src/contract.js")(),
module.exports = function _bindContracts(object) {
var ac = object.Account;

ac.deposit = ac.deposit.pre(function(amount) {
var testAmount = function(amount) {
should.exist(amount);
amount.should.be.above(0);
};

ac.deposit = ac.deposit.pre(function(amount) {
testAmount.call(this, amount);
}).post(function (ret, amount) {
should.not.exist(ret);
}).invariant(function(before, amount) {
this.balance.should.equal(before.balance + amount);
});

ac.withdraw = ac.withdraw.pre(function(amount) {
should.exist(amount);
amount.should.be.above(0);
testAmount.call(this, amount);
amount.should.be.below(this.balance);
}).post(function(ret, amount) {
should.not.exist(ret);
}).invariant(function (before, amount) {
Expand All @@ -32,8 +36,9 @@ module.exports = function _bindContracts(object) {

ac.transfer = ac.transfer.pre(function(ac, amount) {
should.exist(ac);
ac.should.be.an.instanceof(object.Account);
should.exist(amount);
amount.should.be.above(0);
})
ac.should.have.property("deposit");
testAmount.call(this, amount);
}).post(function(ret) {
should.not.exist(ret);
});
};

0 comments on commit 34be99f

Please sign in to comment.