Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find mocktail files in [NSBundle KIFTestBundle] #11

Open
wanbok opened this issue Jan 6, 2016 · 7 comments
Open

Can't find mocktail files in [NSBundle KIFTestBundle] #11

wanbok opened this issue Jan 6, 2016 · 7 comments

Comments

@wanbok
Copy link

wanbok commented Jan 6, 2016

I've install AMYServer via Cocoapods
So, [NSBundle KIFTestBundle] can't contain my mocktail files. also [NSBundle mainBundle].

These files are contained in [NSBundle allBundles][1]

@phatmann
Copy link
Contributor

phatmann commented Jan 6, 2016

Are you using the use_frameworks! option in CocoaPods?

@wanbok
Copy link
Author

wanbok commented Jan 7, 2016

@phatmann Yeah. I've monkey-patched waitForRequestMatchingMocktail.

    func waitForRequestMatching(mocktail mocktail: String, inBundle bundle: NSBundle? = NSBundle.KIFTestBundle(), withHTTPBodyMatchingBlock block: ((NSData, NSErrorPointer) -> KIFTestStepResult)?, andRespondWithValues values: [String: AnyObject]?) {
        let response: _AMYMocktailResponse?
        let headers: [NSObject: AnyObject]?
        let body: NSData?
        var errorType = "load mocktail"
        do {
            response = try _AMYMocktailResponse(fromTail: mocktail, bundle: bundle)

            errorType = "generate headers"
            headers = try response?.headersWithValues(values)

            errorType = "generate body"
            body = try response?.bodyWithValues(values)

            let request = waitForRequestMatchingBlock { [weak self] (req, error) -> KIFTestStepResult in
                return self?.KIFTestWaitCondition(response?.matchesURL(req.URL, method: req.HTTPMethod, patternLength: nil) ?? false, error: error, errorMessage: "Could not find request matching mocktail.") ??
                {
                    block?(req.HTTPBody ?? NSData(), error)
                    return .Success
                }()
            }

            request.respondWithStatusCode(response?.statusCode ?? 500, headerFields: headers)
            request.sendData(body)
            request.close()
        } catch let error as NSError {
            let errorToThrow = NSError(domain: "KIFTest", code: Int(KIFTestStepResult.Failure.rawValue), userInfo: [NSLocalizedDescriptionKey: "Failed to \(errorType): \(error.localizedDescription)", NSUnderlyingErrorKey: error])
            failWithError(errorToThrow, stopTest: true)
        }
    }

and use it like that

//
//  IntroTest.swift
//  Frip
//
//  Created by 최완복 on 2016. 1. 6..
//  Copyright © 2016년 Frientrip. All rights reserved.
//

import KIF

class IntroTest: KIFTestCase {
    var server: MockingServer { return server() }
    override func beforeAll() {
        server.start()
    }

    override func afterAll() {
        server.stop()
    }

    func testSuccess() {
        server.waitForRequestMatching(mocktail: "successful-intro", inBundle: NSBundle(forClass: self.dynamicType), andRespondWithValues: nil)
    }
}

@phatmann
Copy link
Contributor

phatmann commented Jan 7, 2016

Can you submit a pull request with a fix? And be sure to use a new branch for it :-)

@wanbok
Copy link
Author

wanbok commented Jan 8, 2016

Ok, I'll do it. until next week. ;-)

@BenchR267
Copy link

What about this pull request? 'next week' is long ago :)

@wanbok
Copy link
Author

wanbok commented May 11, 2016

Would be closed by #13

@BenchR267
Copy link

Yeah, I thought that too but unfortunately I had the same error as before. That's why I closed this pull request..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants