Skip to content

Commit

Permalink
Move all node tests to test/node and clean up the requires
Browse files Browse the repository at this point in the history
Now every test uses `__` instead of requiring the individual modules
  • Loading branch information
rluba committed Feb 23, 2016
1 parent d9fafa5 commit cbdff97
Show file tree
Hide file tree
Showing 62 changed files with 431 additions and 622 deletions.
296 changes: 148 additions & 148 deletions dist/hamjest.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/hamjest.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions gulpfile.js
Expand Up @@ -22,21 +22,23 @@ gulp.task('lint', function () {
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failAfterError())
.pipe($.jscs())
.pipe($.jscs.reporter())
.pipe($.jscs.reporter('fail'));
.pipe($.jscs())
.pipe($.jscs.reporter())
.pipe($.jscs.reporter('fail'));
});

gulp.task('test', function () {
return gulp.src('test/**/*Spec.js', {read: false})
gulp.task('test', ['test:node']);

gulp.task('test:node', function () {
return gulp.src('test/node/**/*Spec.js', {read: false})
.pipe($.mocha({
reporter: 'spec'
}));
});

gulp.task('build', ['lint', 'test'], function () {
var b = browserify({
entries: './hamjest.js',
entries: './index.js',
debug: true
});

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "hamjest",
"version": "3.0.0-1",
"main": "hamjest.js",
"main": "index.js",
"description": "A JavaScript implementation of Hamcrest",
"homepage": "https://github.com/rluba/hamjest",
"author": {
Expand Down
10 changes: 10 additions & 0 deletions test/browser/.eslintrc
@@ -0,0 +1,10 @@
{
env: {
node: false,
browser: true
},
rules: {
'strict': [2, 'function'],
'no-console': 2
}
}
10 changes: 4 additions & 6 deletions test/DescriptionSpec.js → test/node/DescriptionSpec.js
@@ -1,15 +1,13 @@
'use strict';

var _ = require('lodash');
var __ = require('../lib/hamjest');
var Description = require('../lib/Description');
var Matcher = require('../lib/matchers/Matcher');
var __ = require('../..');
var assertEquals = require('./asserts').assertEquals;

describe('Description', function () {
var sut;
beforeEach(function () {
sut = new Description();
sut = new __.Description();
});

it('should append texts', function () {
Expand Down Expand Up @@ -73,7 +71,7 @@ describe('Description', function () {
});

it('should describe matchers in arrays', function () {
var matcher = _.create(new Matcher(), {
var matcher = _.create(new __.Matcher(), {
describeTo: function (description) {
description.append('a matcher description');
}
Expand All @@ -86,7 +84,7 @@ describe('Description', function () {

describe('appendDescriptionOf(matcherOrValue)', function () {
it('should append matcher description', function () {
var matcher = _.create(new Matcher(), {
var matcher = _.create(new __.Matcher(), {
describeTo: function (description) {
description.append('a matcher description');
}
Expand Down
4 changes: 2 additions & 2 deletions test/TestMatcher.js → test/node/TestMatcher.js
@@ -1,11 +1,11 @@
'use strict';

var _ = require('lodash');
var Matcher = require('../lib/matchers/matcher');
var __ = require('../..');

var TestMatcher = function (matchesFn) {
matchesFn = matchesFn || function () { return true; };
return _.create(new Matcher(), {
return _.create(new __.Matcher(), {
matches: matchesFn,
describeTo: function (description) {
description.append('Matcher description');
Expand Down
14 changes: 7 additions & 7 deletions test/assertThatSpec.js → test/node/assertThatSpec.js
Expand Up @@ -2,23 +2,23 @@

var q = require('q');
var AssertionError = require('assertion-error');
var assertThat = require('../lib/assertThat');
var __ = require('../..');
var assertTrue = require('./asserts').assertTrue;
var assertEquals = require('./asserts').assertEquals;
var TestMatcher = require('./TestMatcher');

describe('assertThat', function () {
it('should do nothing on success', function () {

assertThat('truth', new TestMatcher());
__.assertThat('truth', new TestMatcher());

});

it('should pass value to matcher', function () {
var input = 'assertion value';
var passedValue;

assertThat(input, new TestMatcher(function (value) {
__.assertThat(input, new TestMatcher(function (value) {
passedValue = value;
return true;
}));
Expand All @@ -30,7 +30,7 @@ describe('assertThat', function () {
var thrown;

try {
assertThat('real value', new TestMatcher(function () {
__.assertThat('real value', new TestMatcher(function () {
return false;
}));
}
Expand All @@ -46,7 +46,7 @@ describe('assertThat', function () {
var thrown;

try {
assertThat('Assertion message', 'real value', new TestMatcher(function () {
__.assertThat('Assertion message', 'real value', new TestMatcher(function () {
return false;
}));
}
Expand All @@ -70,7 +70,7 @@ describe('assertThat', function () {
};

try {
assertThat('actual value', testMatcher);
__.assertThat('actual value', testMatcher);
}
catch (e) {
thrown = e;
Expand All @@ -84,7 +84,7 @@ describe('assertThat', function () {
var thrown;

try {
assertThat('a value', new TestMatcher(function () {
__.assertThat('a value', new TestMatcher(function () {
return q(true);
}));
}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/failSpec.js → test/node/failSpec.js
@@ -1,7 +1,7 @@
'use strict';

var AssertionError = require('assertion-error');
var __ = require('../lib/hamjest');
var __ = require('../..');

describe('fail', function () {
it('with a reason: should throw an AssertionError with the reason', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/hamjestSpec.js → test/node/hamjestSpec.js
@@ -1,7 +1,7 @@
'use strict';

var _ = require('lodash');
var hamjest = require('../lib/hamjest');
var hamjest = require('../..');
var assertFalse = require('./asserts').assertFalse;

describe('hamjest', function () {
Expand Down
17 changes: 6 additions & 11 deletions test/matchers/AllOfSpec.js → test/node/matchers/AllOfSpec.js
@@ -1,20 +1,17 @@
'use strict';

var q = require('q');
var AllOf = require('../../lib/matchers/AllOf');
var Description = require('../../lib/Description');
var __ = require('../../lib/hamjest');
var __ = require('../../../lib/hamjest');
var assertTrue = require('../asserts').assertTrue;
var assertFalse = require('../asserts').assertFalse;
var deferMatcher = require('../deferMatcher');

describe('AllOf', function () {

describe('allOf', function () {
var allOf = AllOf.allOf;
var sut;
beforeEach(function () {
sut = allOf(__.containsString('expected'), __.containsString('value'));
sut = __.allOf(__.containsString('expected'), __.containsString('value'));
});

it('should match if every matcher matches', function () {
Expand All @@ -29,9 +26,8 @@ describe('AllOf', function () {

describe('description', function () {
var description;

beforeEach(function () {
description = new Description();
description = new __.Description();
});

it('should contain each matcher', function () {
Expand All @@ -52,7 +48,7 @@ describe('AllOf', function () {

describe('with a promising matcher', function () {
beforeEach(function () {
sut = allOf(__.containsString('expected'), deferMatcher(__.containsString('value')));
sut = __.allOf(__.containsString('expected'), deferMatcher(__.containsString('value')));
});

it('should return a promise if any of the matchers returns a promise', function () {
Expand Down Expand Up @@ -83,13 +79,12 @@ describe('AllOf', function () {

describe('description', function () {
var description;

beforeEach(function () {
description = new Description();
description = new __.Description();
});

it('should return promise if one of the matchers returns a promise', function () {
var sut = allOf(__.containsString('expected'), deferMatcher(__.containsString('value')));
var sut = __.allOf(__.containsString('expected'), deferMatcher(__.containsString('value')));
var actual = 'another valu';

return sut.describeMismatch(actual, description).then(function () {
Expand Down
13 changes: 6 additions & 7 deletions test/matchers/AnyOfSpec.js → test/node/matchers/AnyOfSpec.js
@@ -1,16 +1,16 @@
'use strict';

var AnyOf = require('../../lib/matchers/AnyOf');
var Description = require('../../lib/Description');
var __ = require('../../lib/hamjest');
var __ = require('../../../lib/hamjest');
var assertTrue = require('../asserts').assertTrue;
var assertFalse = require('../asserts').assertFalse;

describe('AnyOf', function () {

describe('anyOf', function () {
var anyOf = AnyOf.anyOf;
var sut = anyOf('expected value', __.containsString('some'));
var sut;
beforeEach(function () {
sut = __.anyOf('expected value', __.containsString('some'));
});

it('should match if any matcher matches', function () {
assertTrue(sut.matches('expected value'));
Expand All @@ -23,9 +23,8 @@ describe('AnyOf', function () {

describe('description', function () {
var description;

beforeEach(function () {
description = new Description();
description = new __.Description();
});

it('should contain each matcher', function () {
Expand Down

0 comments on commit cbdff97

Please sign in to comment.