1

I pull OHHTTPStubs via cocoa pods but I'm having some issues I can not figure out why. Here is a copy of my podFile

# platform :ios, '11.3'

target 'myApp' do
  use_frameworks!
  target 'myAppTests' do
    inherit! :search_paths
   pod 'OHHTTPStubs/Swift'
  end
end

On my test file:

import OHHTTPStubs
@testable import myApp

class myTest: XCTestCase {

    var client: CryptoCompareClient!

    override func setUp() {
        super.setUp()
        OHHTTPStubs.onStubMissing { request in
            XCTFail("Missing stub for \(request)")
        }
    }

On this lines:

    OHHTTPStubs.onStubMissing { request in
        XCTFail("Missing stub for \(request)")
    }

I'm getting the following error:

Type 'OHHTTPStubs' has no member 'onStubMissing'

Also I'm trying to load file from bundle using OHHTTPStubs:

let bundle = OHResourceBundle("myFixtures", FixtureLoader.self)!
        let path = OHPathForFileInBundle(filename, bundle)!
        return OHHTTPStubsResponse(fileAtPath: path, statusCode: 200, headers: nil)

But I'm getting this errors:

Use of unresolved identifier 'OHResourceBundle' and Use of unresolved identifier 'OHPathForFileInBundle'

My question to you guys is what I'm doing wrong or why I'm getting this errors?

I'll really appreciate your help.

user2924482
  • 8,380
  • 23
  • 89
  • 173

2 Answers2

13

For anyone uses OHHTTPStubsResponse as I can see it is renamed as HTTPStubsResponse.

abdullahselek
  • 7,893
  • 3
  • 50
  • 40
1

onStubMissing is not a property of OHHTTPStubs, but a function instead, so you just need to add () to the function call you already have, like this

OHHTTPStubs.onStubMissing() { request in
    XCTFail("Missing stub for \(request)")
}

and it should work

As for your second question, OHPathForFileInBundle doesn't take a bundle parameter, you'll need to send the resource file name and the class whose bundle contains that resource, from the examples:

let stubPath = OHPathForFile("stub.txt", type(of: self))

Note the second parameter is a class, not a bundle