Last Updated: February 25, 2016
·
1.53K
· Alexandr K

describe api rspec method for sinatra or grape.

Hello.

In the one project we are using describe_api method for describing sinatra or grape routes. Probably it could be useful for skipping the same steps all the time.

spec/spec_helper.rb

RSpec.configure do |config|
  config.include ApiHelper, api: true
  config.include Rack::Test::Methods, api: true
end

spec/support/api.rb

def describe_api klass, &block
  describe klass, api: true do
    define_method(:app) do
      klass
    end

    instance_eval(&block)
  end
end

spec/api/v1/example_spec.rb

describe_api V1::Example do
  before { get '/api' }

   it { expect(response.status).to eq(200) }
end