Monday, February 15, 2016

Two things to check when your Travis build fails



You created a gem, tested it all in your local development environment, all tests passed and you a happy developer. But...

Then you push your gem to GitHub and your repository there is connected with Travis (https://travis-ci.org). More than that, you have a badge in your README.md page. And when you refresh your GitHub project page, you see your Travis build failed!

What a frustration!

Well, this already happened to me and it is not good at all. But let me tell you the good news: there are two small things to check before desperation when your Travis build fails.

1) Have you required sudo powers?

This is a fundamental question, because you are just a visitor in Travis platform and you have no special powers there. At least not all powers needed to run some of the tests in some cases.

So, if your gem requires, for instance, that you have write access to the file system, better ask for sudo powers. It is easy. Just edit the .travis.yml file in your gem's home directory and append

sudo: require

to it.

2) Check your Rspec tests for absolute references to files

This is a usual mistake. We are in our local development environments and we know exactly where we may read/write or not. Then we give a full path to the file to be read/written and it all works fine. But then we moved to the Travis file system and the paths we used don't even exist and Travis build fails.

This already happened to me and it is not funny at all. So, I hope this helps you to avoid the same.