Created
January 31, 2018 16:53
-
-
Save coreyjs/6aa643373a187f3e86d461f2e0260916 to your computer and use it in GitHub Desktop.
Rails API Spec Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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