Tag: testing

How to Run with Rails: Configure Travis CI to use multiple databases

When building any large application, a stable and efficient test suite is a must in order to maintain a reliable codebase. Thanks to tools such as RSpec and MiniTest, building your own test suite for your Ruby on Rails application can be a fairly painless endeavour. However, when building open source projects, you need to ensure your application has been tested in several different environments. Today we are going to look at how to test your application with several database softwares within the Travis CI cloud testing suite.

Once you have set up your account over at Travis CI and configured your application to begin running tests within the platform, we can start to build our configuration files. Our aim is to tell Travis CI to run tests for each of the commonly used database softwares: MySQL, PostgreSQL and SQLite. We can achieve this by passing environment variables within the .travis.yml configuration file. As you can see from the example below taken from the Trado github repository, we have defined 3 database types under the matrix subcategory; global environment variables are data values which are used globally across all builds whereas matrix environment variables trigger one build per item. For example:

When Travis CI receives the new commit, it will run a build for each database in the matrix environment variable list. You can view each individual build in the UI, as seen below:

Screen Shot 2016-03-09 at 14.01.31

If you would like more information, check out the Travis CI documentation: https://docs.travis-ci.com/user/environment-variables/#Global-Variables

Need help cleaning up your test database when running tests? Check out my post about using DatabaseCleaner: http://tomdallimore.com/blog/taking-the-test-trash-out-with-databasecleaner-and-rspec/

09th March 2016