Skip to content

Instantly share code, notes, and snippets.

View glowacki-dev's full-sized avatar
🐧
🐦

Maciej Głowacki glowacki-dev

🐧
🐦
View GitHub Profile
@glowacki-dev
glowacki-dev / posts_spec.rb
Last active August 10, 2017 14:01
Basic example of using rspec_api_documentation
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
@glowacki-dev
glowacki-dev / posts_spec.rb
Last active September 3, 2020 06:52
Previous example (https://gist.github.com/glowacki-dev/dd617e850af64dccc2375cb89b772653) extended with stubbing 3rd party requests
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
# ... Same as previously ...
before do
@glowacki-dev
glowacki-dev / shared_examples_for_api_requests.rb
Created August 9, 2017 16:03
Basic shared example for rspec_api_documentation request
shared_examples 'api_requests' do |name, explanation|
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
example_request name do
explanation explanation
# ... Do some stuff here later ...
end
end
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
@glowacki-dev
glowacki-dev / api_request.rb
Created August 9, 2017 16:15
Base ApiRequest class
class ApiRequest
def initialize
end
end
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
# ... Same as before ...
subject do
@glowacki-dev
glowacki-dev / posts_spec.rb
Last active September 3, 2020 06:57
Specifying successful request in subject set previously (https://gist.github.com/glowacki-dev/2d1de022e03ae2ac62da9f1f34203cb3)
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
# ... Same as before ...
subject do
shared_examples 'api_requests' do |name, explanation|
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
example name do
explanation explanation
do_request
expect(status).to eq(subject.status)
end
@glowacki-dev
glowacki-dev / api_request.rb
Last active September 3, 2020 06:59
ApiRequest (https://gist.github.com/glowacki-dev/33135500ac72ab53f7a56d114c924db1) updated with success and failure methods
class ApiRequest
attr_reader :status
def initialize
end
def success(code = 200)
@status = code
self
end
@glowacki-dev
glowacki-dev / posts_spec.rb
Last active September 3, 2020 07:03
Extending previous example (https://gist.github.com/glowacki-dev/28643f08830fc54917e7bd420193a1c2) with expected responses
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
# ... Same as before ...