Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into mauricioborges-master

- Merges #67 from @mauricioborges
- Fixes #66
  • Loading branch information
slackersoft committed Mar 10, 2016
2 parents 1b716d0 + 0142105 commit 3a41f74
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
13 changes: 6 additions & 7 deletions lib/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function Jasmine(options) {
this.specFiles = [];
this.helperFiles = [];
this.env = this.jasmine.getEnv();
this.reportersCount = 0;
this.exitCodeReporter = new ExitCodeReporter();
this.onCompleteCallbackAdded = false;
this.exit = exit;
Expand Down Expand Up @@ -47,7 +46,10 @@ Jasmine.prototype.addSpecFile = function(filePath) {

Jasmine.prototype.addReporter = function(reporter) {
this.env.addReporter(reporter);
this.reportersCount++;
};

Jasmine.prototype.provideFallbackReporter = function(reporter) {
this.env.provideFallbackReporter(reporter);
};

Jasmine.prototype.configureDefaultReporter = function(options) {
Expand All @@ -62,7 +64,7 @@ Jasmine.prototype.configureDefaultReporter = function(options) {
this.printDeprecation('Passing in an onComplete function to configureDefaultReporter is deprecated.');
}
var consoleReporter = new module.exports.ConsoleReporter(options);
this.addReporter(consoleReporter);
this.provideFallbackReporter(consoleReporter);
this.defaultReporterAdded = true;
};

Expand Down Expand Up @@ -139,10 +141,7 @@ Jasmine.prototype.stopSpecOnExpectationFailure = function(value) {

Jasmine.prototype.execute = function(files, filterString) {
this.loadHelpers();

if(this.reportersCount === 0) {
this.configureDefaultReporter({ showColors: this.showingColors });
}
this.configureDefaultReporter({ showColors: this.showingColors });

if(filterString) {
var specFilter = new ConsoleSpecFilter({
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/console_reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var util = require('util');
var options = {
showColors: true,
print: function() {
process.stdout.write(util.format.apply(this, arguments));
}
};

jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(options));
12 changes: 7 additions & 5 deletions spec/jasmine_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Jasmine', function() {
this.bootedJasmine = {
getEnv: jasmine.createSpy('getEnv').and.returnValue({
addReporter: jasmine.createSpy('addReporter'),
provideFallbackReporter: jasmine.createSpy('provideFallbackReporter'),
execute: jasmine.createSpy('execute'),
throwOnExpectationFailure: jasmine.createSpy('throwOnExpectationFailure'),
randomizeTests: jasmine.createSpy('randomizeTests')
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('Jasmine', function() {
this.testJasmine.configureDefaultReporter(reporterOptions);

expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions);
expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'});
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'});
});

it('creates a reporter with a default option if an option is not specified', function() {
Expand All @@ -81,7 +82,7 @@ describe('Jasmine', function() {
};

expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions);
expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'});
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'});
});

it('sets the defaultReporterAdded flag', function() {
Expand Down Expand Up @@ -289,15 +290,16 @@ describe('Jasmine', function() {
expect(this.testJasmine.env.execute).toHaveBeenCalled();
});

it('does not add a default reporter if a reporter was already added', function() {
it('adds a default reporter as a fallback reporter', function() {
this.testJasmine.addReporter(new Jasmine.ConsoleReporter({}));

spyOn(this.testJasmine, 'configureDefaultReporter');
//spyOn(this.testJasmine, 'configureDefaultReporter');
spyOn(this.testJasmine, 'loadSpecs');

this.testJasmine.execute();

expect(this.testJasmine.configureDefaultReporter).not.toHaveBeenCalled();
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalled();
expect(this.testJasmine.env.addReporter).toHaveBeenCalled();
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
expect(this.testJasmine.env.execute).toHaveBeenCalled();
});
Expand Down

0 comments on commit 3a41f74

Please sign in to comment.