Travis CI & Automated Testing with Ruby

Getting Started With Travis CI

Integrating Travis CI into GitHub project is easy but developing an automated test scripts for Ruby is challenging. I have never heard about Travis CI but had some knowledge regarding these kind of hosting services which I got introduced during my first release 0.1 The service I have used in the first release was Treeherder.

The first initial step is to create an account for Travis CI and link it with an existing Github account so by that it can sync all repositories into the Travis CI domain. After the synchronization is complete I have to specify which repository I want to begin testing with (by enabling it from the website) and I must create a .travis.yml file (in that repository) in order for Travis CI to work. What I have found fascinating about this is in that file (.yml) I can specify all versions of RVM for Ruby to test making the code more portable for all versions of Ruby environment.

.travis.yml file

Running Travis CI for the first time!

After everything is setup, the CI will automatically start to test this repository (FileInfoFinder). The first build wasn't successful and this error took some time to figure it out.  

The error occurred because no rakefile was found. after doing some research I had to find testable framework and download some  dependencies to enable the automation testing to succeed.

 

Build Error
Build #1 Fail...

There are many unit test tools available for Ruby. The testing tool I have used for this is named Rspec. Rspec enables to create automation testing scripts.

The script that I have created validates 4 tasks:

  1. FindPath() - The  absolute path should return mydata.txt. 
  2. FindSize() - Validates the Size of the file should be equal to the one in the repository.
  3. DigestFileSha1() - Based on the string in the mydata.txt file it should return the correct hashed value.
  4. DigestFileMd5() - Based on the string in the mydata.txt file it should return the correct hashed value.

 

 

Test Script Example

Build Complete

After many build attempts I have finally manage to get a build passing on build #65 this took some time due to receiving all kinds of errors. Overall this is a great practice experience, TravisCI is a great service that I find useful to create code scripts instead of testing them manually. the most challenging part of this was how to create Ruby scripts as I have little experience with Ruby language. In spite of that It's always useful to learn new programming language!

Build #65 PASS!

Leave a Reply

Your email address will not be published. Required fields are marked *