0.0.4 • Published 9 years ago

spectator v0.0.4

Weekly downloads
57
License
MIT
Repository
github
Last release
9 years ago

#Spectator.js

###what is it? Spectator is a grunt plugin which lets your add test-comments to your JS code and generates spec files for those tests.

###why should i use it?

	<li>Save time and effort : Spectator makes it easier to create and maintain your project's unit testing code.</li>
<li>Improve readability : Spectator will greatly improve code readability since the tests are included side-by-side real code, along with suite and individual test descriptions.</li>
<li>Ensure testability : Spectator makes it easy to examine your code and find places where unit tests are missing or insufficient.</li>

<li>HTML Spec Runner : Spectator will be happy to carve-out an html spec-runner page of the type you specify - supported types currently include Jasmine, Mocha and QUnit.</li>
	<li>Syntax : Use any assertion syntax you like, we don't judge - we just render! if you wish to use the HTML spec runner generated, a valid type needs to be specified per file.</li>

###how does it work? Spectator is a grunt plugin, that takes the path for the relevant JS files, processes them, and creates test files inside a default, or specific location.

###let's get busy: ###1: Spectator syntax lives inside JS comments, and is recognised by the delimiter '@#' For a basic unit test , one would simply write:

(a.js)

/* 
	@# describe("A suite", function() {
	@#   it("contains spec with an expectation", function() {
	@#  	expect(true).toBe(true);
	@#   });
	@# });
*/
function foo()
{
	return bar;
}

to render the following spec file.

(aSpec.js)

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

pretty simple, huh?

###2: Specific file name and path for output can be specified:

(a.js)

//@# file:'/someDir/someSpec.js'
//@#...

(/someDir/someSpec.js])

...

###3: Spectator syntax can be placed anywhere inside the JS file, which can improve readability!

(a.js)

function doSomething()
{
	//Tests:
	//@# describe('A suite', function(){ 
	//@# 	it('initially, flag should be false', function(){
	//@# 		expect(flag).toBe(false);
	//@#	}
	
	doSomething();
	
	//@# 	it("doSomething should change flag to true", function() {
	//@# 		doSomething()
	//@# 		expect(flag).toBe(true);
	//@# 	}
	//@# }

 }

(aSpec.js)

describe("A suite", function() {

  it("initially, flag should be false", function() {
	expect(flag).toBe(false);
  });

  it("doSomething should change flag to true", function() {
	 doSomething();
	 expect(flag).toBe(true);
  });
  
});

###4: Spectator can automagically create your dedicated spec runner file, which will contain the files you've specified and the specs that were created for them. to use this feature, init the tasks config in the following way: (gruntfile.js)

grunt.initConfig({
        // Configuration to be run (and then tested).
        Spectator: {
            files: ['test/fixtures/*.js'],
            options: {
                output_dir: 'test/Spectator/',
                test_runner: {
                    enabled: true,
                    version: '2.1.3',
                    type: 'jasmine',
                    folder: [output folder for the spec runner]
                }
            }
        }
});

###Spectator will do the rest to serve a fully functional specRunner. (Work in progress)...

###5: Want to add comments to your spec? no sweat!

(a.js)

/* 
   @# describe('A suite', function(){ 
   @# 	// COMMENTS COMMENTS COMMENTS
   @# 	it('contains spec with an expectation', function(){
   @# 		expect(true).toBe(true);
   @# 	}
   @# });
*/
0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

2.0.0

10 years ago