ApiTests.swift 1.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
////
////  ApiTests.swift
////  Api
////
////  Created by Mauro Bender on 13/8/16.
////  Copyright © 2016 CocoaPods. All rights reserved.
////

import Quick
import Nimble
import Mockingjay
import Api

class ApiTests: QuickSpec {
	override func setUp() {
		super.setUp()
		
		// Register stubs
		stub( matchApiPath( "tests/get", method: .GET ), builder: http( 200 ) )
		stub( matchApiPath( "tests/delete", method: .DELETE ), builder: http( 200 ) )
	}
	
	override func spec() {
		describe( "Api" ) {
			let api = Api( baseURL: baseURL, apiPath: apiPath )
			
			describe( "resource" ) {
28
				let resource : Resource = api.resource( "items" )
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
				
				it( "should have the correct api" )  { expect( resource.api )  == api }
				it( "should have the correct path" ) { expect( resource.path ) == "items" }
			}
			
			describe( "request" ) {
				it( "should call the correct endpoint with the correct method" ) {
					waitUntil { done in
						api.request( .DELETE, path: "tests/delete" ) { result in done() }
					}
				}
			}
			
			describe( "get" ) {
				it( "should call the correct endpoint" ) {
					waitUntil { done in api.get( "tests/get" ) { result in done() } }
				}
			}
		}
	}
}