-
-
Notifications
You must be signed in to change notification settings - Fork 535
Testing
Testing Tracks is fairly simple. For its tests two different technologies are used:
-
minitest for unit, functional, and integration tests (in
/test) -
Cucumber with Capybara for acceptance tests (in
/features)
The tests make use of some gems which need to be installed first. If you have previously done a bundle install --without development test you will need to edit your .bundle/config and re-run bundle install.
Ensure you have the test section properly configured in your config/database.yml.
Since Rails 4.1, the test environment automatically loads the database schema, so you do not need to run the migrations.
To run the entire minitest suite, from the root directory of the project, run
bin/rake test
To run an individual test file, append the path to the file, as in
bin/rake test test/models/project_test.rb
To run a single test, include the name of the file and the name of the test itself, e.g.
bin/rake test test/models/project_test.rb test_has_default_context
Acceptance tests are written using Cucumber. For those features that require JavaScript/AJAX, Tracks uses Capybara and Selenium.
To run all the features excluding the work-in-progress (wip) features, run
bin/cucumber
This will execute all features, including those using Selenium.
To run the features that are work in progress run these:
bin/rake cucumber:wip
To run an individual test file, append the path to the file, as in
bin/cucumber features/calendar.feature
To run a single test, include the path to the file and the test's starting line number, as in
bin/cucumber features/calendar.feature:45
If you encounter problems running selenium tests, look at the Problems with cucumber selenium tests section below.
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.
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
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
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.
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.
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