Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (89 sloc) 2.64 KB

Inspec: A JavaScript BDD Test Framework

Inspec is a Javascript BDD Test Library that aims to be flexible and powerful yet clean and easy to extend. Packaged as a Narwhal Package.

Dependencies

You need:

Narwhal

Installation

Setup your path for narwhal

cd ~
mkdir ~/.bin
nano ~/.bash_profile

Add the following line at the end of your .bash_profile

PATH=~/.bin:$PATH

Save your .bash_profile.
Update your environment variables by running the following in the console:

source ~/.bash_profile

Get narwhal

cd ~ && mkdir serverjs
cd ~/serverjs
git clone git://github.com/tlrobinson/narwhal.git

Get Inspec

cd ~/serverjs/narwhal/packages
git clone git://github.com/aq1018/inspec.git

Link narwhal and Inspec executables to your bin folder

cd ~/.bin
ln -s ~/serverjs/narwhal/bin/* .
ln -s ~/serverjs/narwhal/packages/inspec/bin/* .

Run Inspec self test

cd ~/serverjs/narwhal/packages/inspec
inspec

Specing your own

  1. Make a directory called ‘spec’
  2. Your spec files should be in spec folder and/or its subfolders
  3. Inspec looks for files with name ending with ‘Spec.js’. E.g. ‘fooSpec.js’, ‘barSpec.js’
  4. type ‘inspec’ on the parent directory of ‘spec’ to see test results

Highlights

  • Nested Example Groups
  • Shared Example Groups (A.K.A. it_should_behave_like in RSpec )
  • support multiple definition of before / after blocks (add array)
  • support multiple definition of same behaviors (see below)
  • Sandboxed Example Scope
  • Cascading beforeEach, beforeAll, afterEach, afterAll
  • Clean API
  • Easy to extend

Sample spec

Highly suggest you to look at the spec directory for more sample code on specing


sharedExamplesFor("a shared example group", function(){
  it("should work as shared example", function(){
    expect(true).to(beTrue);
  })

  describe("with nested example groups in shared", function(){
    it("should work as a nested example group in shared", function(){
      expect(true).to(beTrue);
    })
  })

})

describe("Inspec", function(){
  it("should work", function(){
    expect(true).to(beTrue);
  })
    
  it("should fail", function(){
    expect(true).toNot(beTrue);
  })

  it("should error", function(){
    it.should.error.out;
  })
  
  it("should be pending")
    
  describe("with a nested example group", function(){
    it("should work as a nested example group", function(){
      expect(true).to(beTrue);
    })
  })

  itShouldBehaveLike("a shared example group")
})