Xero
Xero

Reputation: 4175

Rspec group test ouput

How group some tests to be displayed in a group ?

I launch :

bin/rspec --format=documentation

Actual, I got :

Countries API
  GET /countries
    return list of countries
    returns status code 200
  GET /states/{country_abbrev}
    return list of states
    returns status code 200

Companies API
  GET /companies
    returns companies
    returns status code 200

InvoiceLineRepository
  #create
    create invoice line in database

InvoiceRepository
  #create
    create invoice in database

And I want to have :

  API  
    Countries API
      GET /countries
        return list of countries
        returns status code 200
      GET /states/{country_abbrev}
        return list of states
        returns status code 200

    Companies API
      GET /companies
        returns companies
        returns status code 200

 Repository  
    InvoiceLineRepository
      #create
        create invoice line in database

    InvoiceRepository
      #create
        create invoice in database

The tests that's concern API, are grouped togheter. The tests that's concern Repository, are grouped togheter.

I want this to better organize the visualisation and exploration of my tests

EDIT :

context (see mrzasa response) do not fill my requirements :

Repository
  AddressRepository
    #create
      create address in database

Repository
  AgencyRepository
    #create
      create agency in database

Repository
  ArticleRepository
    #create
      create article in database

Upvotes: 0

Views: 86

Answers (2)

Mihai Târnovan
Mihai Târnovan

Reputation: 662

You could implement a custom formatter, take a look at the documentation formatter for an example, but as others have said this does not scale, and what exactly is a "group"?

Upvotes: 1

mrzasa
mrzasa

Reputation: 23327

You need to add contexts for API and Repository:

context 'API' do
  context 'Countries' do
    describe 'GET /countries' do
      # examples
    end
    describe 'GET /states/{country_abbrev}' do
      # examples
    end
  end
end

context 'Repository do
   # context/describe blocks for  InvoiceLineRepository and  InvoiceRepository
end

Upvotes: 0

Related Questions