Introducing Vigia: API testing using RAML files in ruby



I’d like to introduce Vigia to the RAML community. Vigia is ruby gem that generates integration RSpec test by consuming a RAML definition file. Short story, with a RAML file like this:

#%RAML 0.8
title: World Music API
version: v1
        description: filter the songs by genre
        example: 'rock'
            schema: !include songs.json

Vigia will generate the following RSpec tests

describe Vigia::RSpec do
  describe 'Resource: songs' do
    describe 'Method: get' do
      describe 'Response 200' do
        describe 'Content type application/json' do
          it 'has a valid response code' do
            expect(response.status).to eql 200
          # more examples run here

Currently, Vigia Raml support is still beta and some raml functionalities are not working (like the security schemas).

You can get more information about it on the project github:



Cool David. Thanks for contributing. QQ: In a continues integration environment -> you would run Vigia during the testing phase. I guess you have to generate the RSpec test before and fill in the tests logic, or everything will be generated automatically?


Everything will be generated automatically. The only three things you have to pass to the Vigia configuration block is the localisation of the raml file, the adapter class that it will be use (in this case Vigia::Adapter::Raml although, I am thinking in doing this automatically when user provoides a file with the .raml extension) and the host url of the API server you want to test. That’s it!


Thanks David. So what is included in the testing besides valid response status?


By default, Vigia runs two comparison for each request sent to the server. The first one, as I posted above, is that the response matches the expected http status code. The second one, is that the response headers includes the content type specified in the RAML definition file. In the example I posted above, the response should include application/json.

You can see the actual RSpec expectations for these two examples here:

These two examples run by default as I said, but Vigia can be easily extended. For example, you can create a new example that ensures the response is a valid JSON by including the following code

# expect the response body to be a valid SON block. don't do it if response status is 204 (no body)
  expectation: -> { expect { JSON.parse(result.body) }.not_to raise_error },
  disable_if:  -> { result.code == 204 } 

You can get more information about how to include more examples in Vigia’s wiki page about shared examples and expectations/examples