A "plugin" for Jasmine 2.0 to facilitate focusing on specific suites/specs a la RSpec tagging.
- Add the 'jasmine-focus.js' script after jasmine.js script and before you include the boot.js file:
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="../jasmine-focus.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>
-
Modify boot.js to call
jasmineRequire.enableFocusTagging()
(see /example/lib/jasmine-2.0.0/boot.js) -
Replace the
env.execute()
withenv.executeFiltered()
in boot.js (see /example/lib/jasmine-2.0.0/boot.js)
Suites and specs can be tagged in one of two ways:
- By using the
fdescribe
andfit
methods instead of regulardescribe
andfit
- By adding a
{ focus: true }
object as second argument to regulardescribe
orit
function calls.
describe("when song has been paused", function() {
beforeEach(function() {
player.play(song);
player.pause();
});
// this spec will be executed
it("should be possible to resume", { focus: true }, function() {
player.resume();
expect(player.isPlaying).toBeTruthy();
});
// this spec will not be executed
it("should indicate that the song is currently paused", function() {
expect(player.isPlaying).toBeFalsy();
});
});
// this spec will also be executed, due to fit() being used
fit("tells the current song if the user has made it a favorite", function() {
spyOn(song, 'persistFavoriteStatus');
player.play(song);
player.makeFavorite();
expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
});
// this entire describe suite will be executed
describe("#resume", { focus: true }, function() {
it("should throw an exception if song is already playing", function() {
player.play(song);
expect(function() {
player.resume();
}).toThrowError("song is already playing");
});
});
Open /example/SpecRunner.html
in a web browser to see an example based on the
Jasmine 2.0 standalone distribution.
- jasmine-focused This is a node-module-specific implementation of Jasmine focused execution.
The guts of this library were taken more or less directly from the Karma project.