Skip to main content
  1. Posts/
  2. Dev/

How to integrate TestRail with RSpec

·286 words·2 mins·
Ruby Ruby on Rails

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
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:

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: '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

Author
Dmitry Zuev

Related

How to convert human readable number to float in Ruby
·506 words·3 mins
Ruby Ruby on Rails
During my 30 days of code challenge I’m working now on fun project which convert amount of money from user input to amount of subways, which you may build in Omsk.
How to integrate drag and drop email builder to your Ruby on Rails project
·831 words·4 mins
Ruby Ruby on Rails
This is a short story about integration of BeeFree email builder into Ruby on Rails application.