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

Xcode can't find stub or matcher now #28

Closed
pigeon-archive opened this issue Oct 12, 2015 · 6 comments
Closed

Xcode can't find stub or matcher now #28

pigeon-archive opened this issue Oct 12, 2015 · 6 comments
Labels

Comments

@pigeon-archive
Copy link

We have jsonData now but now Xcode is complaining that stub and matcher are unavailable. Not sure why.

import Foundation
import Mockingjay

class TestModel: NSObject {

    class func testRequest() {
        let path = NSBundle.mainBundle().pathForResource("Plaid", ofType: "json")
        let data = NSData(contentsOfFile: path!)!

        stub(matcher, builder: jsonData(data))
    }

}

Ideas?

screen shot 2015-10-12 at 10 51 24 am

@kylef
Copy link
Owner

kylef commented Oct 12, 2015

@istx25 The stub method is on XCTest/XCTestCase, is there any particular reason you're not doing these from your tests?

@kylef kylef added the question label Oct 12, 2015
@kylef
Copy link
Owner

kylef commented Oct 12, 2015

The missing matcher is because you haven't provided a matcher to the stub method. See https://github.com/kylef/Mockingjay#usage

@pigeon-archive
Copy link
Author

Does this library only support test cases? I am trying to stub network requests in the main target to provide a fake response to network requests/prototype an application.

@kylef
Copy link
Owner

kylef commented Oct 12, 2015

@istx25 That's possible, if you're using CocoaPods. You will want to depend on Mockingjay/Core to prevent XCTest being included.

The reason XCTest has it's own stub method, is because those stubs are removed at the end of the test case. You can instead add a stub yourself:

MockingjayProtocol.addStub(uri("/{user}/{repository}"), builder: json(data))

You can make a convenience global stub function as follows:

public func stub(matcher:Matcher, builder:Builder) -> Stub {
  return MockingjayProtocol.addStub(matcher, builder: builder)
}

I'll add a global stub method in the next release to make this easier.

@pigeon-archive
Copy link
Author

Thanks!

@pigeon-archive
Copy link
Author

I'll check this out. :)

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

No branches or pull requests

2 participants