Skip to content

Commit

Permalink
cleaned out .by for #333
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpolis committed Jan 2, 2015
1 parent 581cf83 commit 051fd95
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 36 deletions.
29 changes: 2 additions & 27 deletions lib/chai/core/assertions.js
Expand Up @@ -1429,15 +1429,10 @@ module.exports = function (chai, _) {
var fn = flag(this, 'object');
new Assertion(object, msg).to.have.property(prop);
new Assertion(fn).is.a('function');
flag(this, 'property', prop);

var initial = object[prop];
fn();

if ('number' == typeof initial) {
flag(this, 'delta', object[prop] - initial);
}

this.assert(
initial !== object[prop]
, 'expected .' + prop + ' to change'
Expand Down Expand Up @@ -1475,12 +1470,9 @@ module.exports = function (chai, _) {

var initial = object[prop];
fn();
var delta = object[prop] - initial;
flag(this, 'delta', delta);
flag(this, 'property', prop);

this.assert(
delta > 0
object[prop] - initial > 0
, 'expected .' + prop + ' to increase'
, 'expected .' + prop + ' to not increase'
);
Expand Down Expand Up @@ -1516,12 +1508,9 @@ module.exports = function (chai, _) {

var initial = object[prop];
fn();
var delta = object[prop] - initial;
flag(this, 'delta', -delta);
flag(this, 'property', prop);

this.assert(
delta < 0
object[prop] - initial < 0
, 'expected .' + prop + ' to decrease'
, 'expected .' + prop + ' to not decrease'
);
Expand All @@ -1530,18 +1519,4 @@ module.exports = function (chai, _) {
Assertion.addChainableMethod('decrease', assertDecreases);
Assertion.addChainableMethod('decreases', assertDecreases);

function assertChangesBy (expected, msg) {
if (msg) flag(this, 'message', msg);
var obj = flag(this, 'object'),
prop = flag(this, 'property'),
delta = flag(this, 'delta');

this.assert(
delta === expected
, 'expected .' + prop + ' to change by ' + expected
, 'expected .' + prop + ' to not change by ' + expected
);
}

Assertion.addMethod('by', assertChangesBy);
};
2 changes: 0 additions & 2 deletions test/assert.js
Expand Up @@ -707,11 +707,9 @@ describe('assert', function () {
smFn = function() { obj.value += 0 };

assert.decreases(decFn, obj, 'value');
assert.decreasesBy(decFn, obj, 'value', 3);
assert.doesNotDecrease(smFn, obj, 'value');

assert.increases(incFn, obj, 'value');
assert.increasesBy(incFn, obj, 'value', 2);
assert.doesNotIncrease(smFn, obj, 'value');
});

Expand Down
3 changes: 0 additions & 3 deletions test/expect.js
Expand Up @@ -907,7 +907,6 @@ describe('expect', function () {
bangFn = function() { obj.str += '!' };

expect(fn).to.change(obj, 'value');
expect(fn).to.change(obj, 'value').by(5);
expect(sameFn).to.not.change(obj, 'value');
expect(sameFn).to.not.change(obj, 'str');
expect(bangFn).to.change(obj, 'str');
Expand All @@ -922,12 +921,10 @@ describe('expect', function () {
expect(smFn).to.not.increase(obj, 'value');
expect(decFn).to.not.increase(obj, 'value');
expect(incFn).to.increase(obj, 'value');
expect(incFn).to.increase(obj, 'value').by(2);

expect(smFn).to.not.decrease(obj, 'value');
expect(incFn).to.not.decrease(obj, 'value');
expect(decFn).to.decrease(obj, 'value');
expect(decFn).to.decrease(obj, 'value').by(3);
});


Expand Down
4 changes: 0 additions & 4 deletions test/should.js
Expand Up @@ -787,8 +787,6 @@ describe('should', function() {
bangFn = function() { obj.str += '!' };

fn.should.change(obj, 'value');
fn.should.change(obj, 'value').by(5);
decFn.should.change(obj, 'value').by(-3);
sameFn.should.not.change(obj, 'value');
sameFn.should.not.change(obj, 'str');
bangFn.should.change(obj, 'str');
Expand All @@ -803,11 +801,9 @@ describe('should', function() {
smFn.should.not.increase(obj, 'value');
decFn.should.not.increase(obj, 'value');
incFn.should.increase(obj, 'value');
incFn.should.increase(obj, 'value').by(2);

smFn.should.not.decrease(obj, 'value');
incFn.should.not.decrease(obj, 'value');
decFn.should.decrease(obj, 'value');
decFn.should.decrease(obj, 'value').by(3);
});
});

0 comments on commit 051fd95

Please sign in to comment.