Skip to content

Commit a79368c

Browse files
committed
Simplified RegexSpecFilter
1 parent 720a280 commit a79368c

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

lib/filters/regex_spec_filter.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module.exports = exports = RegexSpecFilter;
1+
module.exports = exports = regexSpecFilter;
22

3-
function RegexSpecFilter(options) {
4-
const filterString = options && options.filterString;
3+
function regexSpecFilter(filterString) {
54
const filterPattern = new RegExp(filterString);
65

7-
this.matches = function(specName) {
8-
return filterPattern.test(specName);
6+
return function(spec) {
7+
return filterPattern.test(spec.getFullName());
98
};
109
}

lib/jasmine.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const ExitHandler = require('./exit_handler');
2-
const RegexSpecFilter = require('./filters/regex_spec_filter');
2+
const regexSpecFilter = require('./filters/regex_spec_filter');
33
const RunnerBase = require('./runner_base');
44

55
/**
@@ -196,12 +196,9 @@ class Jasmine extends RunnerBase {
196196
}
197197

198198
if (filterString) {
199-
const specFilter = new RegexSpecFilter({
200-
filterString: filterString
199+
this.env.configure({
200+
specFilter: regexSpecFilter(filterString)
201201
});
202-
this.env.configure({specFilter: function(spec) {
203-
return specFilter.matches(spec.getFullName());
204-
}});
205202
}
206203

207204
if (files && files.length > 0) {

lib/parallel_worker.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const RegexSpecFilter = require("./filters/regex_spec_filter");
1+
const regexSpecFilter = require("./filters/regex_spec_filter");
22

33
class ParallelWorker {
44
constructor(options) {
@@ -65,13 +65,8 @@ class ParallelWorker {
6565
}
6666

6767
if (options.filter) {
68-
const specFilter = new RegexSpecFilter({
69-
filterString: options.filter
70-
});
7168
env.configure({
72-
specFilter: function (spec) {
73-
return specFilter.matches(spec.getFullName());
74-
}
69+
specFilter: regexSpecFilter(options.filter)
7570
});
7671
}
7772

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
const RegexSpecFilter = require('../../lib/filters/regex_spec_filter');
2-
3-
describe("RegexSpecFilter", function() {
1+
const regexSpecFilter = require('../../lib/filters/regex_spec_filter');
42

3+
describe("regexSpecFilter", function() {
54
it("should match when no string is provided", function() {
6-
const specFilter = new RegexSpecFilter();
5+
const specFilter = regexSpecFilter();
76

8-
expect(specFilter.matches("foo")).toBe(true);
9-
expect(specFilter.matches("*bar")).toBe(true);
7+
expect(specFilter({ getFullName: () => "foo" })).toBe(true);
8+
expect(specFilter({ getFullName: () => "*bar" })).toBe(true);
109
});
1110

1211
it("should match the provided string", function() {
13-
const specFilter = new RegexSpecFilter({
14-
filterString: "foo"
15-
});
12+
const specFilter = regexSpecFilter("foo");
1613

17-
expect(specFilter.matches("foo")).toBe(true);
18-
expect(specFilter.matches("bar")).toBe(false);
14+
expect(specFilter({ getFullName: () => "foo"})).toBe(true);
15+
expect(specFilter({ getFullName: () => "bar"})).toBe(false);
1916
});
2017

2118
it("should match by part of spec name", function() {
22-
const specFilter = new RegexSpecFilter({
23-
filterString: "ba"
24-
});
19+
const specFilter = regexSpecFilter("ba");
2520

26-
expect(specFilter.matches("foo")).toBe(false);
27-
expect(specFilter.matches("bar")).toBe(true);
28-
expect(specFilter.matches("baz")).toBe(true);
21+
expect(specFilter({ getFullName: () => "foo"})).toBe(false);
22+
expect(specFilter({ getFullName: () => "bar"})).toBe(true);
23+
expect(specFilter({ getFullName: () => "baz"})).toBe(true);
2924
});
3025
});

0 commit comments

Comments
 (0)