Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Run Jasmine JavaScript unit tests, integrate them into Ruby applications.

tag: 0.2.1

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 config
Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .gitmodules
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 evergreen.gemspec
README.rdoc

Evergreen

“Because green is the new Blue(Ridge)”

Evergreen is a tool to run javascript unit tests for client side JavaScript. It combines a runner which allows you to serve up and run your specs in a browser, as well as a headless runner based on envjs. Evergreen uses the Jasmine unit testing framework for JavaScript.

github.com/jnicklas/evergreen

Philosophy

Evergreen is a unit testing tool. It's purpose is to test JavaScript in isolation from your application. If you need a tool that tests how your JavaScript integrates with your application you should use an integration testing framework, such as Capybara.

Installation

Install as a Ruby gem:

gem install evergreen

Usage

Evergreen assumes a file and directory structure, place all your javascript code inside ./public and all spec files inside ./spec/javascripts. All spec files should end in _spec.js. For example:

public/widget.js
spec/javascripts/widget_spec.js

You can require files from the public directory inside your spec file:

require('/widget.js')

describe('a widget', function() {
  ...
});

You can now look at your spec files inside a browser by starting up the Evergreen server:

evergreen server

Alternatively you can run the specs headlessly by running:

evergreen run

Integrating with Rails 3

Add Evergreen to your Gemfile:

gem 'evergreen', :require => 'evergreen/rails'

Start your rails application and navigate to /evergreen/list. You should now see a list of all spec files, click on one to run it.

There's a rake task provided for you that you can use to run your specs:

rake spec:javascripts

Transactions

One problem often faced when writing unit tests for client side code is that changes to the page are not reverted for the next example, so that successive examples become dependent on each other. Evergreen adds a special div to your page with an id of test. This div is automatically emptied before each example. You should avoid appending markup to the page body and instead append it to this test div:

describe('transactions', function() {
  it("should add stuff in one test...", function() {
    $('#test').append('<h1 id="added">New Stuff</h1>');
    expect($('#test h1#added').length).toEqual(1);
  });

  it("... should have been removed before the next starts", function() {
    expect($('#test h1#added').length).toEqual(0);
  });
});

Templates

Even more powerful than that, Evergreen allows you to create HTML templates to go along with your specs. Simply name the template the same as the spec, only with an html extension. For example:

spec/javascripts/widget_spec.js
spec/javascripts/widget_spec.html

The template will be placed inside the test div, so that means it should not include html, head, body or similar tags. The template will be restored for each example, so that at the start of each example, the markup inside the test div is identical.

License:

(The MIT License)

Copyright © 2009 Jonas Nicklas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.