Running tests with Teaspoon

If you’ve gone through the Getting started tutorial, this article will show you how to run your tests using Teaspoon.

Teaspoon is a JavaScript test running for Rails. jstest has a reporter plugin that will autodetect if you’re using Teaspoon and wire everything up for you. To get started, add teaspoon to your Gemfile:

# Gemfile

gem 'teaspoon'

Then run the following commands to install Teaspoon in your app:

$ bundle update teaspoon
$ rails generate teaspoon:install

Let’s copy the example files from Getting started into this project.

cp build/jstest.js          teaspoon_demo/vendor/assets/javascripts/jstest.js
cp example/lib/set.js       teaspoon_demo/app/assets/javascripts/set.js
cp example/spec/set_spec.js teaspoon_demo/spec/javascripts/set_spec.js

To load jstest.js and set.js into the test page, add this to spec/javascripts/spec_helper.js:

// spec/javascripts/spec_helper.js

//= require jstest
//= require set

Then boot your Rails app and open http://localhost:3000/teaspoon. You should see this page:

Clicking the link to set_spec.js should run that test and show you the results.