Last active
August 10, 2017 14:01
-
-
Save glowacki-dev/dd617e850af64dccc2375cb89b772653 to your computer and use it in GitHub Desktop.
Basic example of using rspec_api_documentation
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
require 'acceptance_helper' | |
resource 'Posts' do | |
explanation 'Posts are entities holding some text information. | |
They can be created and seen by anyone' | |
post '/posts' do | |
with_options scope: :post do | |
parameter :title, 'Title of a post. Can be empty' | |
parameter :body, 'Main text of a post. Must be longer than 10 letters', required: true | |
end | |
response_field :id, 'Id of the created post' | |
response_field :title, 'Title of the created post' | |
response_field :body, 'Main text of the created post' | |
header 'Accept', 'application/json' | |
header 'Content-Type', 'application/json' | |
let(:title) { 'Foo' } | |
let(:body) { 'Lorem ipsum dolor sit amet' } | |
example_request 'Creating a post' do | |
explanation 'You can create a post by sending its body text and an optional title' | |
expect(status).to eq 201 | |
response = JSON.parse(response_body) | |
expect(response['title']).to eq title | |
expect(response['body']).to eq body | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment