Instant Download of Premium Web Templates
JSpec | Java-ScriptGate.com

Java-ScriptGate.com - Java Script Is Difficult

JS and App

January 5, 2010

JSpec

We recently posted a unit test roundup, so I noticed that JSpec has been updated to version 3. This version introduces several interesting updates (see the full change list):
  • Rhino’s jar is included so console tests can work without installing extra stuff
  • Added a jspec stats command
  • Subcommand hooks — checks for spec/commands/*_command.rb
  • Ruby server is now a Sinatra app
JSpec is now version 3.0 and currently has over 200 followers on GitHub, so it’s worth checking out.

Syntax Examples

JSpec tests can be written using a custom DSL or a grammar-less JavaScript syntax. When using the DSL in browser-based tests, be sure to use JSpec.exec() to run tests rather than including the code in script tags (more details are in the README). Tests written with the DSL look like this:
describe 'ShoppingCart'
  before_each
    cart = new ShoppingCart
  end

  describe 'addProducts'
    it 'should add several products'
      cart.addProduct('cookie')
      cart.addProduct('icecream')
      cart.should.have 2, 'products'
    end
  end

  describe 'checkout'
    it 'should throw an error when checking out with no products'
      -{ cart.clear().checkout() }.should.throw_error EmptyCart
    end
  end
end
JavaScript equivalent:
JSpec.describe('ShoppingCart', function(){
  before_each(function{
    cart = new ShoppingCart
  })

  describe('addProducts', function(){
    it ('should add several products', function(){
      cart.addProducts('cookie')
      cart.addProducts('icecream')
      expect(cart).to(have, 2, 'products')
    })
  })

  describe('checkout', function(){
    it ('should throw an error when checking out with no products', function(){
      expect(function(){ cart.clear().checkout() }).to(throw_error, EmptyCart)
    })
  })
})

Custom Matchers

Custom matchers can be defined using JSpec.addMatchers. It’s possible to control the error messages. It’s also possible to create sets of macros with similar names:
JSpec.addMatchers({
  'be disabled selected checked' : function(attr) {
    return 'jQuery(actual).attr("' + attr + '")'
  },

  'have type id title alt href src sel rev name target' : function(attr) {
    return function(actual, value) {
      return value ? jQuery(actual).attr(attr) ## value:
                     jQuery(actual).attr(attr)
    }
  }
})

Other Features

JSpec includes a command-line tool that can initialise project templates, as well as auto-testing when files are changed. It can also work with Growl in Mac OS X. It includes lots of familiar matchers and works well in a browser and console.

Installation

To try JSpec out, you can install it with RubyGemsgem install jspec and read the docs on github.com/visionmedia/jspec. The future telecommunication technology is video conference facilities or video conferencing solutions. This communication facility allows several locations to interact with people via audio and video simultaneously. Video conference software brings a cost effective video conferencing system which is held over ISDN. This is very good video picture quality and also much more reliable than the normal internet.
SPORTSBETTING.COM is the simplest and most popular destination for sports betting on the Internet. Our many years of experience guarantee you a superior betting service. Join today to take advantage of all our great offers.
MCITP upgradeEnroll to Intense School's highest rated MCITP Upgrade Boot Camp now. For more information, visit Intesneschool.com now! LiteSpeed Hosting Provider-LiteSpeed hosting with Ultra Website hosting .com. Increase the speed of your website with UltraWebsiteHosting.com’s LiteSpeed web services. Three times faster than Apache with the most competitive pricing. Live Support, price guarantee, 45-day money back guarantee… it’s tough to beat these guys!

Sorry, the comment form is closed at this time.

Download Premium Web Templates Instantly
Download Website Templates For Free