Module: Virtuatable::Specs
- Defined in:
- lib/virtuatable/specs.rb
Overview
This module holds all the logic for the specs tools for all micro services (shared examples and other things).
Constant Summary collapse
- @@declared =
false
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.
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 88 |
# File 'lib/virtuatable/specs.rb', line 9 def self.include_shared_examples if !@@declared RSpec.shared_examples 'a route' do |_verb, _path| let(:verb) { _verb } let(:path) { _path } def do_request(parameters) public_send verb.to_sym, path, parameters 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(last_response.body).to include_json( status: 400, field: 'token', error: 'required' ) 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 gateway token' do expect(last_response.body).to include_json( status: 400, field: 'app_key', error: 'required' ) 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 response if the parameters do not contain a gateway token' do expect(last_response.body).to include_json( status: 404, field: 'app_key', error: 'unknown' ) 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(last_response.body).to include_json( status: 404, field: 'token', error: 'unknown' ) end end end end end @@declared = true end end |