Last active
June 27, 2018 08:50
-
-
Save andriy-baran/27a2f9a68c780c67020385d5be393daa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Helpers | |
def assert_body | |
expect(response.body).to eq message # raw body | |
end | |
def assert_response_object | |
expect(response_object).to have_attributes(resp_attrs) # object | |
end | |
def assert_response_body | |
expect(response_body).to eq(resp_attrs) # collection | |
end | |
%i(get post put delete).each do |http_verb| | |
define_method :"do_#{http_verb}" do | |
public_send(http_verb, path, valid_params, valid_headers) | |
end | |
{ text: 'text/plain', json: 'application/json'}.each do |type, mime_type| | |
{ not_found: 404, unprocessable_entity: 422, ok: 200 }.each do |status, code| | |
%i(body response_object parsed_body).each do |resp_assertion| | |
define_method :"assert_#{code}_#{type}_#{resp_assertion}" do | |
expect(response).to have_http_status(status) | |
expect(response.content_type).to eq mime_type | |
public_send(:"assert_#{resp_assertion}") | |
end | |
define_method :"do_#{http_verb}_and_assert_#{code}_#{type}_#{resp_assertion}" do | |
public_send(:"do_#{http_verb}") | |
public_send(:"assert_#{code}_#{type}_#{resp_assertion}") | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment