Skip to content

Commit

Permalink
Merge pull request #869 from ljwall/jasmine
Browse files Browse the repository at this point in the history
Fixes #855
  • Loading branch information
Greg Chattin-McNichols and Gregg Van Hove committed Aug 3, 2015
2 parents cd55f03 + 7bfc4c0 commit 750a9aa
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 15 deletions.
25 changes: 20 additions & 5 deletions lib/jasmine-core/jasmine.js
Expand Up @@ -711,13 +711,17 @@ getJasmineRequireObj().Env = function(j$) {

this.describe = function(description, specDefinitions) {
var suite = suiteFactory(description);
if (currentDeclarationSuite.markedPending) {
suite.pend();
}
addSpecsToSuite(suite, specDefinitions);
return suite;
};

this.xdescribe = function(description, specDefinitions) {
var suite = this.describe(description, specDefinitions);
suite.disable();
var suite = suiteFactory(description);
suite.pend();
addSpecsToSuite(suite, specDefinitions);
return suite;
};

Expand Down Expand Up @@ -823,6 +827,9 @@ getJasmineRequireObj().Env = function(j$) {

this.it = function(description, fn, timeout) {
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
if (currentDeclarationSuite.markedPending) {
spec.pend();
}
currentDeclarationSuite.addChild(spec);
return spec;
};
Expand All @@ -833,9 +840,9 @@ getJasmineRequireObj().Env = function(j$) {
return spec;
};

this.fit = function(){
var spec = this.it.apply(this, arguments);

this.fit = function(description, fn, timeout){
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
currentDeclarationSuite.addChild(spec);
focusedRunnables.push(spec.id);
unfocusAncestor();
return spec;
Expand Down Expand Up @@ -2031,6 +2038,10 @@ getJasmineRequireObj().Suite = function(j$) {
this.disabled = true;
};

Suite.prototype.pend = function(message) {
this.markedPending = true;
};

Suite.prototype.beforeEach = function(fn) {
this.beforeFns.unshift(fn);
};
Expand All @@ -2056,6 +2067,10 @@ getJasmineRequireObj().Suite = function(j$) {
return 'disabled';
}

if (this.markedPending) {
return 'pending';
}

if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
Expand Down
15 changes: 15 additions & 0 deletions spec/core/SuiteSpec.js
Expand Up @@ -90,6 +90,21 @@ describe("Suite", function() {
expect(suite.getResult().status).toBe('disabled');
});

it("retrieves a result with pending status", function() {
var suite = new j$.Suite({});
suite.pend();

expect(suite.getResult().status).toBe('pending');
});

it("priviledges a disabled status over pending status", function() {
var suite = new j$.Suite({});
suite.disable();
suite.pend();

expect(suite.getResult().status).toBe('disabled');
});

it("is executable if not disabled", function() {
var suite = new j$.Suite({});

Expand Down
85 changes: 80 additions & 5 deletions spec/core/integration/EnvSpec.js
Expand Up @@ -1115,6 +1115,78 @@ describe("Env integration", function() {

env.execute();
});

it('should run focused tests inside an xdescribe', function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);

reporter.jasmineDone.and.callFake(function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 1
});

expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'with a fit spec',
status: 'failed'
}));

done();
});

env.addReporter(reporter);

env.xdescribe("xd suite", function() {
env.fit("with a fit spec", function() {
env.expect(true).toBe(false);
});
});

env.execute();
});

it('should run focused suites inside an xdescribe', function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);

reporter.jasmineDone.and.callFake(function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 1
});

expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'with a spec',
status: 'failed'
}));

done();
});

env.addReporter(reporter);

env.xdescribe("xd suite", function() {
env.fdescribe("fd suite", function() {
env.it("with a spec", function() {
env.expect(true).toBe(false);
});
});
});

env.execute();
});
});

it("should report as expected", function(done) {
Expand Down Expand Up @@ -1227,9 +1299,10 @@ describe("Env integration", function() {
totalSpecsDefined: 1
});

expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'disabled' }));
expect(reporter.suiteDone.calls.count()).toBe(3);

expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' }));
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' }));
expect(reporter.suiteDone.calls.count()).toBe(4);

done();
});

Expand All @@ -1238,8 +1311,10 @@ describe("Env integration", function() {
env.describe("A Suite", function() {
env.describe("nested", function() {
env.xdescribe("xd out", function() {
env.it("with a spec", function() {
env.expect(true).toBe(false);
env.describe("nested again", function() {
env.it("with a spec", function() {
env.expect(true).toBe(false);
});
});
});
});
Expand Down
17 changes: 12 additions & 5 deletions src/core/Env.js
Expand Up @@ -261,13 +261,17 @@ getJasmineRequireObj().Env = function(j$) {

this.describe = function(description, specDefinitions) {
var suite = suiteFactory(description);
if (currentDeclarationSuite.markedPending) {
suite.pend();
}
addSpecsToSuite(suite, specDefinitions);
return suite;
};

this.xdescribe = function(description, specDefinitions) {
var suite = this.describe(description, specDefinitions);
suite.disable();
var suite = suiteFactory(description);
suite.pend();
addSpecsToSuite(suite, specDefinitions);
return suite;
};

Expand Down Expand Up @@ -373,6 +377,9 @@ getJasmineRequireObj().Env = function(j$) {

this.it = function(description, fn, timeout) {
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
if (currentDeclarationSuite.markedPending) {
spec.pend();
}
currentDeclarationSuite.addChild(spec);
return spec;
};
Expand All @@ -383,9 +390,9 @@ getJasmineRequireObj().Env = function(j$) {
return spec;
};

this.fit = function(){
var spec = this.it.apply(this, arguments);

this.fit = function(description, fn, timeout){
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
currentDeclarationSuite.addChild(spec);
focusedRunnables.push(spec.id);
unfocusAncestor();
return spec;
Expand Down
8 changes: 8 additions & 0 deletions src/core/Suite.js
Expand Up @@ -42,6 +42,10 @@ getJasmineRequireObj().Suite = function(j$) {
this.disabled = true;
};

Suite.prototype.pend = function(message) {
this.markedPending = true;
};

Suite.prototype.beforeEach = function(fn) {
this.beforeFns.unshift(fn);
};
Expand All @@ -67,6 +71,10 @@ getJasmineRequireObj().Suite = function(j$) {
return 'disabled';
}

if (this.markedPending) {
return 'pending';
}

if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
Expand Down

0 comments on commit 750a9aa

Please sign in to comment.