= Evergreen
{}[http://travis-ci.org/abepetrillo/evergreen]
{
}[https://coveralls.io/r/abepetrillo/evergreen]
"Because green is the new Blue(Ridge)"
Evergreen is a tool to run javascript unit tests for client side JavaScript. It
combines a server which allows you to serve up and run your specs in a browser,
as well as a runner which uses Capybara and any of its drivers to run your
specs. Evergreen uses the Jasmine unit testing framework for JavaScript.
http://github.com/abepetrillo/evergreen
== Philosophy
Evergreen is a unit testing tool. Its 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}[http://github.com/jnicklas/capybara].
== Maintenance note
Jonas has kindly given me push access so I can help maintain the project and manage pull requests.
If you have any questions or suggestions please feel free to {contact me}[http://github.com/abepetrillo]
== 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/javascripts/widget.js
spec/javascripts/widget_spec.js
You can require files from the public directory inside your spec file:
require('/javascripts/widget.js')
describe('a widget', function() {
...
});
You can now look at your spec files inside a browser by starting up the
Evergreen server:
evergreen serve
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. 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
== Integrating with Rails 2
Add the following line to your Rakefile:
require 'evergreen/tasks'
This will give you the `spec:javascripts` rake task. Note that mounting is not
possible under Rails 2 and that `require 'evergreen/rails'` will fail.
== Configuration
By default, Evergreen uses Selenium to run your specs and assumes a certain
directory structure. If this standard is fine for you, then you don't need to
do anything else. If you need to configure Evergreen to suit your needs,
Evergreen will automatically look for and load the following files:
config/evergreen.rb
.evergreen
~/.evergreen
The content of these files could look like this:
require 'capybara-webkit'
Evergreen.configure do |config|
config.driver = :webkit
config.public_dir = 'public_html'
config.template_dir = 'templates'
config.spec_dir = 'spec'
end
== 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('