How to integrate TestRail with RSpec

Hey, folks!

Recently I came across some Test Case Management system, which called TestRail, and it somehow not based on Rails. Our QA staff uses this tool to write down all their test cases, etc.

But what about RSpec and other beautiful ruby tools? Well, we have specs with good coverage on our project, and I thought, why not integrate our tests with TestRail?

Let’s automate this!

Context is easy: every time RSpec is running on CI, it updates (or creates new) TestRail Run called by git branch.

What if we can just pass case id to some RSpec example?

# spec/features/index_spec.rb
# ...
it 'does something', testrail_id: 123 do
  # do some stuff

That would be awesome, you know? Why not release it to public? Here it is:

How it works

Add this line to your application’s Gemfile:

gem 'rspec-testrail'

And then execute:

$ bundle

Update your spec/spec_helper.rb:

# spec/spec_helper.rb

require 'rspec/testrail'

RSpec.configure do |config|

  config.before :all do
    # Uncomment if you are using gem `webmock`
    # WebMock.allow_net_connect!
    RSpec::Testrail.init url: '',
                         user: '',
                         password: ENV['TESTRAIL_PASSWORD'],
                         project_id: 228,
                         suite_id: 1337,
                         run_name: `git rev-parse --abbrev-ref HEAD`.strip,
                         run_description: `git rev-parse HEAD`.strip

  config.after :example, testrail_id: proc { |value| !value.nil? } do |example|
    # Uncomment if you are using gem `webmock`
    # WebMock.allow_net_connect!

Before all we init our TestRail integration, and after each example it sends information to TestRail API with status updates.

It also posts comment if some case failed.

And, as I said before, you need to specify testrail_id to each example you need to synchronise.

Now I need a little sleep, and you have a nice day or night, whatever :)

Your issues, suggestions or PR’s are welcome:

Dmitry Zuev

Dmitry has over two years of experience developing web applications on Ruby (mostly on Rails), and about five years of web development total. Now he is a part of development team at Rambler & Co, a Russian media company with an audience of around 40 million. Dmitry prefers back-end web development.