Module: Arkaan::Specs
- Defined in:
- lib/arkaan/specs.rb
Overview
This module holds all the logic for the specs tools for all micro services (shared examples and other things).
Class Method Summary collapse
-
.include_shared_examples ⇒ Object
Includes all the shared examples you could need, describing the basic behaviour of a route.
Class Method Details
.include_shared_examples ⇒ Object
Includes all the shared examples you could need, describing the basic behaviour of a route.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/arkaan/specs.rb', line 7 def self.include_shared_examples RSpec.shared_examples 'a route' do |_verb, _path| let(:verb) { _verb } let(:path) { _path } def do_request(parameters) public_send verb.to_sym, path, ['get', 'delete'].include?(verb) ? parameters : parameters.to_json end describe 'common errors' do describe 'bad request errors' do describe 'no token error' do before do do_request({app_key: 'test_key'}) end it 'Raises a bad request (400) error when the parameters don\'t contain the token of the gateway' do expect(last_response.status).to be 400 end it 'returns the correct response if the parameters do not contain a gateway token' do expect(JSON.parse(last_response.body)).to eq({ 'status' => 400, 'field' => 'token', 'error' => 'required', 'docs' => 'https://github.com/jdr-tools/wiki/wiki/Common-errors#gateway-token-not-given' }) end end describe 'no application key error' do before do do_request({token: 'test_token'}) end it 'Raises a bad request (400) error when the parameters don\'t contain the application key' do expect(last_response.status).to be 400 end it 'returns the correct response if the parameters do not contain a application key' do expect(JSON.parse(last_response.body)).to eq({ 'status' => 400, 'field' => 'app_key', 'error' => 'required', 'docs' => 'https://github.com/jdr-tools/wiki/wiki/Common-errors#application-key-not-given' }) end end end describe 'not_found errors' do describe 'application not found' do before do do_request({token: 'test_token', app_key: 'another_key'}) end it 'Raises a not found (404) error when the key doesn\'t belong to any application' do expect(last_response.status).to be 404 end it 'returns the correct body when the application doesn\'t exist' do expect(JSON.parse(last_response.body)).to eq({ 'status' => 404, 'field' => 'app_key', 'error' => 'unknown', 'docs' => 'https://github.com/jdr-tools/wiki/wiki/Common-errors#application-key-not-found' }) end end describe 'gateway not found' do before do do_request({token: 'other_token', app_key: 'test_key'}) end it 'Raises a not found (404) error when the gateway does\'nt exist' do expect(last_response.status).to be 404 end it 'returns the correct body when the gateway doesn\'t exist' do expect(JSON.parse(last_response.body)).to eq({ 'status' => 404, 'field' => 'token', 'error' => 'unknown', 'docs' => 'https://github.com/jdr-tools/wiki/wiki/Common-errors#gateway-token-not-found' }) end end end end end end |