User:Lkommi/sandbox

Jasmine is an automated testing framework that is behaviour driven, developed by Pivotal labs and commonly used for JavaScript code. Any javascript code can be tested against specifications given by the user. The software is based on unit testing. This framework is popular as it does not need any Documentation Object Model (DOM) and it does not have any dependencies. Due to the rise of mobile applications which need JavaScript, Jasmine has become one of most used testing softwares. The software has “MIT Licence” and works across Operating Systems. Jasmine can be used anywhere JavaScript is used; from websites to Node.js. Jasmine can run on frameworks like Sinatra and Ruby on Rails but has a standalone version of it as well. Using the Jasmine Ruby gem, testing can be done on Ruby code as well.

Version History
The first release of the Jasmine framework was in September 14, 2010. The version Jasmine 2.3 was the first stable release.

Jasmine Ruby Gem
Jasmine Ruby or Jasmine Ruby gem is a package that is used for Ruby programming based web development projects. These projects primarily use Sinatra or Ruby on Rails. The package file is used with the Jasmine testing framework and is also compatible with JavaScript codes. At the same time, the Jasmine Ruby Gem is not dependant on any framework(s) but can be used with frameworks like Sinatra or the Ruby on Rails framework.

Setup
The installation, initialisation and usage of jasmine in the Rails framework allows us to test javascript without making changes to the spec HTML file. Jasmine can also be installed as a standalone package.

Installation
Jasmine needs the gem files and bundle to be installed before any testing. The "bundle install" command installs all the necessary dependencies to the Gem file. $ gem "jasmine" $ bundle install $ rails generate jasmine:install

Initialisation
If the project is using Rails, jasmine has generators that can be used to set everything up. the "rails generate" command is very useful in reducing the code needed to write. Time is saved on the part of the code that is mandatory for the working of the application. This uses the template to simplify working. $ rails generate jasmine:install $ rails generate jasmine:examples

Usage
Once jasmine is installed, two commands will be available in rake. rake jasmine command is used to start the jasmine server. rake jasmine:ci is used for continuous integration environments. This is needed for projects where multiple users are utilising a shared repository to make any changes. The changes will only go through once all the test cases have been passed. $ rake jasmine $ rake jasmine:ci

Example
The JavaScript example taken, prints "This is a test!". Jasmine is used to test whether the code will give the expected output. function test { return "This is a test!"; }

Given below is the test suite for the above JavaScript code. The function describe takes two arguments, a string which is the title for the test suite and a function which implements it. The function it defines a spec which describes the expected output of a piece of code, by taking two arguments, a string and a function. Matchers are used in Jasmine to compare the output of a program with an argument. In this example, toEqual matcher is used to test whether the output of the program is "This is a test!". Several other matchers are inbuilt in Jasmine and matchers can also be user-defined. describe("Jasmine Test", function {  it("prints that this is a test", function { expect(test).toEqual("This is a test!"); }); });