Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created January 31, 2018 16:53
Show Gist options
  • Save coreyjs/6aa643373a187f3e86d461f2e0260916 to your computer and use it in GitHub Desktop.
Save coreyjs/6aa643373a187f3e86d461f2e0260916 to your computer and use it in GitHub Desktop.
Rails API Spec Example
module ApiHelper
include Rack::Test::Methods
def app
Rails.application
end
end
RSpec.configure do |config|
config.include ApiHelper, api: true
end
# spec
require 'spec_helper'
describe "api/v1/objects", api: true do
let(:url) { "api/v1/objects" }
let(:object) { Factory.create(:object) }
let(:token) { "YOUR_SECRET_TOKEN" }
let(:data) { JSON.parse(last_response.body) }
before(:each) { get url, token: token } # here's where API call made
subject { data }
it { should have(1).object }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment