Contents

How to integrate TestRail with RSpec

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

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?

1
2
3
4
5
# spec/features/index_spec.rb
# ...
it 'does something', testrail_id: 123 do
  # do some stuff
end

That would be awesome, you know? Why not release it to public? Here it is: https://github.com/dmitryzuev/rspec-testrail.

How it works

Add this line to your application’s Gemfile:

1
gem 'rspec-testrail'

And then execute:

1
$ bundle

Update your spec/spec_helper.rb:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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: 'http://testrail.site',
                         user: '[email protected]',
                         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
  end

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

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: https://github.com/dmitryzuev/rspec-testrail