When we work with Ruby projects, Travis CI will run by default our rake test
recipe. But what if we need to run many scripts at the same time?
Wait, why would we ever do that? Well, for instance, to get better control over the Travis CI console output. You know… scrolling through pages and pages looking for our failing specs. Generally speaking it could come in handy when using the RSpec’s progress format it’s not enough or you’re running RSpec test suites mixed with other kinds of scripts and tests.
In order to get rid of all that noise, we could create a script like the one below. Let’s name it script/ci
:
Let’s make it executable by using the chmod
command:
$ chmod +x script/ci
After that, we need to specify in our .travis.yml
file that we need to override the default script and run script/ci
instead:
So now at the end of Travis CI console output we will get the list of our failing test suites:
That’s interesting but it’s not enough, we still need to scroll through the page to detect the failures.
A step beyond could be to collapse each suite output just like Travis CI already does with all the preliminary steps like bundle install
and so on.
Digging into the Travis CI source code I found out how they achieve that.
def fold(name, &block)
raw "echo -en 'travis_fold:start:#{name}\\r'"
result = yield(self)
raw "echo -en 'travis_fold:end:#{name}\\r'"
result
end
So now we can just wrap each test suite and introduce the same solution in our script.
Now that we have each test suite output collapsed we have a nicer output and we could access the test suites that failed to find out easily errors and back traces.
So, that’s all! Please feel free to ping me for suggestions, ideas, improvements, rants, etc.