Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
QUnit JavaScript Testing on Rails 3.2+
Ruby JavaScript CoffeeScript
branch: master

This branch is 54 commits behind frodsan:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
lib
vendor/assets
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
qunit-rails.gemspec

README.md

QUnit on Rails

QUnit JavaScript Unit Testing framework for Rails.

Requirements

  • Ruby 1.9.x
  • Rails 3.2+

Getting Started

QUnit on Rails works with Rails 3.2. You can add it to your Gemfile with:

group :development, :test do
  gem 'qunit-rails'
end

Run the bundle command to install it.

The engine is automatically mounted into your application in the development and test environments.

After you install it and add it to your Gemfile, you need to run the install generator:

rails g qunit:install

The generator by default will create two directories with two files inside your test folder:

test/javascripts/test_helper.js
test/stylesheets/test_helper.css

If you prefer CoffeeScript, you can run:

rails g qunit:install -c

This will generate a test_helper.js.coffe file instead of test_helper.js.

Usage

JavaScript/CoffeeScript Tests

The test/javascripts/test_helper.js file has the following content:

//= require application
//= require_tree .
//= require_self

This loads all the javascripts defined in app/assets/javascripts/application.js. Also, this pulls in all your test files from the javascripts folder into QUnit-Rails:

test/javascripts/*_test.js
test/javascripts/*_test.js.coffee
test/javascripts/*_test.js.erb

Here's an example test/javascripts/foo_test.js:

test('Foo always says the truth', function() {
  foo = new Foo();

  equal(foo.truth, true, 'foo.truth is not true');
});

If you're not comfortable with loading all the javascript defined in the application.js manifest file, you can delete //= require application from test_helper.js or #= require application from test_helper.js.coffee and use the require dependency mechanism in your tests to pull the dependencies.

Here's an example test/javascripts/foo_test.js:

//= require foo

test('Foo always says the truth', function() {
  foo = new Foo();

  equal(foo.truth, true, 'foo.truth is not true');
});

Stylesheets

For including stylesheets in your tests, QUnit-Rails uses test/javascripts/test_helper.css. Use Sprockets directives to include the right css files:

/*
 *= require application
 *= require_tree .
*/

Run Tests

Start server

Start the server to run the tests:

rails s

Go to http://localhost:3000/qunit to see the QUnit Test Runner.

From the CLI

COMING SOON

Autotest

COMING SOON

What's next?

Profit.

License

MIT License. Copyright 2012 Francesco Rodriguez. http://www.frodsan.com

Something went wrong with that request. Please try again.