Skip to content
lrbalt edited this page Apr 3, 2012 · 7 revisions

Testing

Testing Tracks is fairly simple. For its tests 3 different technologies are used:

  • Ruby unit tests (in $RAILS_ROOT/test)
  • RSpec (in $RAILS_ROOT/spec)
  • Cucumber (in $RAILS_ROOT/features)

Setup

The tests make use of some gems which need to be installed first

Install required gems with


bundle install

Running the Rails test suite

Assuming you’ve already checked out the source code using git, change to the root directory of the project ($RAILS_ROOT) and run


bundle exec rake test

If it completes successfully 0 failures, you’re good to go!

Running the RSpec test suite

NOTE: rspec tests are not actively maintained.

To run the Rspec tests run


bundle exec rake spec

Running the cucumber test suite

For integration testing Tracks uses cucumber. For those features that require javscript/ajax, Tracks uses Selenium and Capybara

To run all the features excluding the work-in-progress (wip) features, run


bundle exec rake cucumber RAILS_ENV=development

This will execute all features, including those using Selenium.

To run the features that are work in progress run these:


bundle exec rake cucumber:wip

To run a feature by hand run these.


bundle exec cucumber features/my_feature.feature

If you encounter problems runnig selenium tests, look at the Problems with cucumber selenium tests section below.

Running the tests headless

All tests will run on a headless setup except for the selenium tests. They will need a webbrowser which will need a running X-server.

You can solve this by running a virtual framebuffer X server or by using the capybara-webkit driver.

Using webkit

Uncomment the capybara-webkit gem in the Gemfile and run bundle install. This will need the Qt development libraries on your system.

Run the features using webkit:


bundle exec rake cucumber JS_DRIVER=webkit

Framebuffer
For the framebuffer in Fedora, you need to install the packages xorg-x11-server-Xvfb and xorg-x11-apps


Xvfb :99 -ac -screen 0 1024x768x16 &

DISPLAY=:99.0 bundle exec rake cucumber:selenium

killall Xvfb

Running the old browser-based Selenium test suite

We are migrating from the selenium test suite in the browser to cucumber and selenium on webrat. To run the selenium scripts that are not yet migrated, the following still applies:

To run the suite simply run Tracks in the test environment:


  bundle exec script/server -e test

in a separate command window, then run


  bundle exec rake test:acceptance

and Firefox will pop up and run the suite. If this does not work, you can run the suite manually by launching the server in test mode with the command above, and navigating to

http://localhost:3000/selenium/ in your browser of choice.

Problems with cucumber selenium tests

Tests doesn’t start

Firefox 3.x is required to run the selenium tests properly. It’s also recommended to use an english version, to avoid problems due to the locale.
You can get an old version of firefox here.

Sqlite3 Lock exceptions

In the default settings sqlite locks the db immediately. This behavior can cause problems with the fast executing online tests. Add a timeout to the database.yml configuration file to avoid these errors.
For example:


test: &TEST
    adapter: sqlite3
    database: db/test.db
    timeout: 10000
Clone this wiki locally