Skip to content

Commit ae180c1

Browse files
committed
Merge pull request #47 from mapbox/1ec5-ohhttpstubs
Replace Nocilla w/ OHHTTPStubs
2 parents fc30be8 + fc14f65 commit ae180c1

File tree

6 files changed

+34
-77
lines changed

6 files changed

+34
-77
lines changed

MapboxGeocoder.xcodeproj/project.pbxproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
DA5170B41CF1B1EF00CD6DCF /* GeocoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA701C001CB1292C00B0E520 /* GeocoderTests.swift */; };
2828
DA5170B51CF1B1EF00CD6DCF /* ForwardGeocodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA210BAA1CB4BE73008088FD /* ForwardGeocodingTests.swift */; };
2929
DA5170B61CF1B1EF00CD6DCF /* ReverseGeocodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF1E84C1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift */; };
30-
DA5170B71CF1B1F300CD6DCF /* Fixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA701C021CB12A1800B0E520 /* Fixture.swift */; };
3130
DA5170B81CF1B1F900CD6DCF /* forward_valid.json in Resources */ = {isa = PBXBuildFile; fileRef = DA210BAC1CB4BFF7008088FD /* forward_valid.json */; };
3231
DA5170B91CF1B1F900CD6DCF /* forward_invalid.json in Resources */ = {isa = PBXBuildFile; fileRef = DA210BAE1CB4C5A7008088FD /* forward_invalid.json */; };
3332
DA5170BA1CF1B1F900CD6DCF /* reverse_valid.json in Resources */ = {isa = PBXBuildFile; fileRef = DDF1E85B1BD70E4C00C40C78 /* reverse_valid.json */; };
3433
DA5170BB1CF1B1F900CD6DCF /* reverse_invalid.json in Resources */ = {isa = PBXBuildFile; fileRef = DDF1E85A1BD70E4C00C40C78 /* reverse_invalid.json */; };
3534
DA701C011CB1292C00B0E520 /* GeocoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA701C001CB1292C00B0E520 /* GeocoderTests.swift */; };
36-
DA701C031CB12A1800B0E520 /* Fixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA701C021CB12A1800B0E520 /* Fixture.swift */; };
3735
DD342B5619A140EE00219F77 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD342B5519A140EE00219F77 /* AppDelegate.swift */; };
3836
DD342B5819A140EE00219F77 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD342B5719A140EE00219F77 /* ViewController.swift */; };
3937
DDC2295C1A36074F006BE405 /* MapboxGeocoder.h in Headers */ = {isa = PBXBuildFile; fileRef = DDC229581A36073B006BE405 /* MapboxGeocoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -131,7 +129,6 @@
131129
DA5170961CF1B18F00CD6DCF /* MapboxGeocoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxGeocoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
132130
DA51709F1CF1B18F00CD6DCF /* MapboxGeocoderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxGeocoderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
133131
DA701C001CB1292C00B0E520 /* GeocoderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeocoderTests.swift; sourceTree = "<group>"; };
134-
DA701C021CB12A1800B0E520 /* Fixture.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Fixture.swift; sourceTree = "<group>"; };
135132
DD342B5019A140EE00219F77 /* Geocoder (Swift).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Geocoder (Swift).app"; sourceTree = BUILT_PRODUCTS_DIR; };
136133
DD342B5419A140EE00219F77 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
137134
DD342B5519A140EE00219F77 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -307,7 +304,6 @@
307304
DDF1E84C1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift */,
308305
DDF1E84E1BD6F7BA00C40C78 /* Info.plist */,
309306
DDF1E8571BD700EB00C40C78 /* Fixtures */,
310-
DA701C021CB12A1800B0E520 /* Fixture.swift */,
311307
);
312308
path = MapboxGeocoderTests;
313309
sourceTree = "<group>";
@@ -696,7 +692,6 @@
696692
DA5170B61CF1B1EF00CD6DCF /* ReverseGeocodingTests.swift in Sources */,
697693
DA5170B41CF1B1EF00CD6DCF /* GeocoderTests.swift in Sources */,
698694
DA5170B51CF1B1EF00CD6DCF /* ForwardGeocodingTests.swift in Sources */,
699-
DA5170B71CF1B1F300CD6DCF /* Fixture.swift in Sources */,
700695
);
701696
runOnlyForDeploymentPostprocessing = 0;
702697
};
@@ -738,7 +733,6 @@
738733
DDF1E84D1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift in Sources */,
739734
DA210BAB1CB4BE73008088FD /* ForwardGeocodingTests.swift in Sources */,
740735
DA701C011CB1292C00B0E520 /* GeocoderTests.swift in Sources */,
741-
DA701C031CB12A1800B0E520 /* Fixture.swift in Sources */,
742736
);
743737
runOnlyForDeploymentPostprocessing = 0;
744738
};

MapboxGeocoderTests/Fixture.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

MapboxGeocoderTests/ForwardGeocodingTests.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import XCTest
2-
import Nocilla
2+
import OHHTTPStubs
33
import CoreLocation
44
@testable import MapboxGeocoder
55

66
class ForwardGeocodingTests: XCTestCase {
7-
override func setUp() {
8-
super.setUp()
9-
LSNocilla.sharedInstance().start()
10-
}
11-
127
override func tearDown() {
13-
LSNocilla.sharedInstance().clearStubs()
14-
LSNocilla.sharedInstance().stop()
15-
super.setUp()
8+
OHHTTPStubs.removeAllStubs()
9+
super.tearDown()
1610
}
1711

1812
func testValidForwardGeocode() {
1913
let expectation = expectationWithDescription("forward geocode should return results")
2014

21-
let json = Fixture.stringFromFileNamed("forward_valid")
22-
stubRequest("GET", "https://api.mapbox.com/geocoding/v5/mapbox.places/1600+pennsylvania+ave.json?country=ca&access_token=\(BogusToken)").andReturn(200).withHeaders(["Content-Type": "application/json"]).withBody(json)
15+
stub(isHost("api.mapbox.com")
16+
&& isPath("/geocoding/v5/mapbox.places/1600+pennsylvania+ave.json")
17+
&& containsQueryParams(["country": "ca", "access_token": BogusToken])) { _ in
18+
let path = NSBundle(forClass: self.dynamicType).pathForResource("forward_valid", ofType: "json")
19+
return OHHTTPStubsResponse(fileAtPath: path!, statusCode: 200, headers: ["Content-Type": "application/json"])
20+
}
2321

2422
let geocoder = Geocoder(accessToken: BogusToken)
2523
var addressPlacemark: Placemark! = nil
@@ -68,8 +66,12 @@ class ForwardGeocodingTests: XCTestCase {
6866
}
6967

7068
func testInvalidForwardGeocode() {
71-
let json = Fixture.stringFromFileNamed("forward_invalid")
72-
stubRequest("GET", "https://api.mapbox.com/geocoding/v5/mapbox.places/Sandy+Island,+New+Caledonia.json?country=nc&types=region,place,locality,poi&access_token=\(BogusToken)").andReturn(200).withHeaders(["Content-Type": "application/json"]).withBody(json)
69+
stub(isHost("api.mapbox.com")
70+
&& isPath("/geocoding/v5/mapbox.places/Sandy+Island,+New+Caledonia.json")
71+
&& containsQueryParams(["country": "nc", "types": "region,place,locality,poi", "access_token": BogusToken])) { _ in
72+
let path = NSBundle(forClass: self.dynamicType).pathForResource("forward_invalid", ofType: "json")
73+
return OHHTTPStubsResponse(fileAtPath: path!, statusCode: 200, headers: ["Content-Type": "application/json"])
74+
}
7375

7476
let expection = expectationWithDescription("forward geocode execute completion handler for invalid query")
7577
let geocoder = Geocoder(accessToken: BogusToken)

MapboxGeocoderTests/GeocoderTests.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import XCTest
2-
import Nocilla
2+
import OHHTTPStubs
33
@testable import MapboxGeocoder
44

55
let BogusToken = "pk.feedCafeDadeDeadBeef-BadeBede.FadeCafeDadeDeed-BadeBede"
66

77
class GeocoderTests: XCTestCase {
8-
override func setUp() {
9-
super.setUp()
10-
LSNocilla.sharedInstance().start()
11-
}
12-
138
override func tearDown() {
14-
LSNocilla.sharedInstance().clearStubs()
15-
LSNocilla.sharedInstance().stop()
9+
OHHTTPStubs.removeAllStubs()
1610
super.tearDown()
1711
}
1812

MapboxGeocoderTests/ReverseGeocodingTests.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import XCTest
2-
import Nocilla
2+
import OHHTTPStubs
33
import CoreLocation
44
@testable import MapboxGeocoder
55

66
class ReverseGeocodingTests: XCTestCase {
7-
8-
override func setUp() {
9-
super.setUp()
10-
LSNocilla.sharedInstance().start()
11-
}
12-
137
override func tearDown() {
14-
LSNocilla.sharedInstance().clearStubs()
15-
LSNocilla.sharedInstance().stop()
16-
super.setUp()
8+
OHHTTPStubs.removeAllStubs()
9+
super.tearDown()
1710
}
1811

1912
func testValidReverseGeocode() {
2013
let expectation = expectationWithDescription("reverse geocode should return results")
2114

22-
let json = Fixture.stringFromFileNamed("reverse_valid")
23-
stubRequest("GET", "https://api.mapbox.com/geocoding/v5/mapbox.places/-95.78558,37.13284.json?access_token=\(BogusToken)").andReturn(200).withHeaders(["Content-Type": "application/json"]).withBody(json)
15+
stub(isHost("api.mapbox.com")
16+
&& isPath("/geocoding/v5/mapbox.places/-95.78558,37.13284.json")
17+
&& containsQueryParams(["access_token": BogusToken])) { _ in
18+
let path = NSBundle(forClass: self.dynamicType).pathForResource("reverse_valid", ofType: "json")
19+
return OHHTTPStubsResponse(fileAtPath: path!, statusCode: 200, headers: ["Content-Type": "application/json"])
20+
}
2421

2522
let geocoder = Geocoder(accessToken: BogusToken)
2623
var pointOfInterestPlacemark: Placemark?
@@ -75,8 +72,12 @@ class ReverseGeocodingTests: XCTestCase {
7572
}
7673

7774
func testInvalidReverseGeocode() {
78-
let json = Fixture.stringFromFileNamed("reverse_invalid")
79-
stubRequest("GET", "https://api.mapbox.com/geocoding/v5/mapbox.places/0.00000,0.00000.json?access_token=\(BogusToken)").andReturn(200).withHeaders(["Content-Type": "application/json"]).withBody(json)
75+
stub(isHost("api.mapbox.com")
76+
&& isPath("/geocoding/v5/mapbox.places/0.00000,0.00000.json")
77+
&& containsQueryParams(["access_token": BogusToken])) { _ in
78+
let path = NSBundle(forClass: self.dynamicType).pathForResource("reverse_invalid", ofType: "json")
79+
return OHHTTPStubsResponse(fileAtPath: path!, statusCode: 200, headers: ["Content-Type": "application/json"])
80+
}
8081

8182
let expection = expectationWithDescription("reverse geocode execute completion handler for invalid query")
8283
let geocoder = Geocoder(accessToken: BogusToken)

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use_frameworks!
88
#end
99

1010
def shared_test_pods
11-
pod 'Nocilla', :configurations => ['Debug']
11+
pod 'OHHTTPStubs/Swift', '~> 5.0.0', :configurations => ['Debug']
1212
end
1313

1414
target 'MapboxGeocoderTests' do
@@ -17,6 +17,6 @@ target 'MapboxGeocoderTests' do
1717
end
1818

1919
target 'MapboxGeocoderMacTests' do
20-
platform :osx, '10.10'
20+
platform :osx, '10.10'
2121
shared_test_pods
2222
end

0 commit comments

Comments
 (0)