Move specFilter function to TrivialReporter.

This commit is contained in:
Aaron Peckham & Christian Williams 2009-08-10 16:00:42 -07:00
parent e476f2375a
commit b1a007dfb5
4 changed files with 52 additions and 39 deletions

View File

@ -10,25 +10,23 @@
<script type="text/javascript"></script>
<link href="/jasmine/lib/jasmine.css" rel="stylesheet"/>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
var jsApiReporter = new jasmine.JsApiReporter();
jasmineEnv.specFilter = function(spec) {
var paramMap = {};
var params = document.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
var jsApiReporter;
(function() {
var jasmineEnv = jasmine.getEnv();
jsApiReporter = new jasmine.JsApiReporter();
var trivialReporter = new jasmine.TrivialReporter();
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) > -1;
};
jasmineEnv.addReporter(jsApiReporter);
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.addReporter(jsApiReporter);
jasmineEnv.addReporter(new jasmine.TrivialReporter());
window.onload = function() {
jasmineEnv.execute();
};
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
window.onload = function() {
jasmineEnv.execute();
};
})();
</script>
<% spec_files.each do |spec_file| %>

View File

@ -59,6 +59,22 @@ jasmine.TrivialReporter.prototype.log = function() {
console.log.apply(console, arguments);
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) > -1;
};
//protect against console.log incidents
if (!("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

View File

@ -37,31 +37,11 @@
jasmine.include('suites/RunnerTest.js', true);
jasmine.include('suites/SpecRunningTest.js', true);
jasmine.include('suites/SpyTest.js', true);
jasmine.include('suites/TrivialReporterTest.js', true);
</script>
<style type="text/css">
.spec {
margin: 5px;
}
.passed {
background-color: lightgreen;
}
.failed {
background-color: pink;
}
.resultMessage {
white-space: pre;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
}
</style>
<link href="../lib/jasmine.css" rel="stylesheet"/>
<body>

View File

@ -0,0 +1,19 @@
describe("TrivialReporter", function() {
function fakeSpec(name) {
return {
getFullName: function() { return name; }
};
}
it("should allow for focused spec running", function() {
var trivialReporter = new jasmine.TrivialReporter();
spyOn(trivialReporter, 'getLocation').andReturn({search: "?spec=run%20this"});
expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
});
it("should not run specs that don't match the filter", function() {
var trivialReporter = new jasmine.TrivialReporter();
spyOn(trivialReporter, 'getLocation').andReturn({search: "?spec=run%20this"});
expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
});
});