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

Add clear routing testing strategy & example #11

Open
chrismaddern opened this issue Feb 5, 2015 · 2 comments
Open

Add clear routing testing strategy & example #11

chrismaddern opened this issue Feb 5, 2015 · 2 comments

Comments

@chrismaddern
Copy link
Contributor

No description provided.

@gregkerzhner
Copy link

I was able to test using routing using the following strategy (I am using DPLRouteHandler subclasses, not block based routes). Examples are in swift (and might not compile, just giving my general strategy here)

Make route handlers classes configurable for stubbing:

class MyRouter: DPLDeepLinkRouter {
    init(oneHandler: OneHandler.Type = OneHandler.self,
        twoHandler: TwoHandler.Type = TwoHandler.self
        ) {
        super.init()
        self["one"] =  forumsRouteHandler
        self["two"] = articleRouteHandler
    }
}

I created a dummy route handler which always fails when hit

class DummyFailOneHandler: OneHandler {
    public override func targetViewController() -> UIViewController! {
        fatalError("I should not be called")
        return nil
    }

    override public func viewControllerForPresentingDeepLink(deepLink: DPLDeepLink!) -> UIViewController! {
        fatalError("I should not be called")
        return nil
    }
}

In my test, when I want to confirm that a certain route has been hit, make all other route handlers fail by stubbing them with this failed handler.

router = MyRouter(oneHandler: DummyFailOneHandler.self, twoHandler: TwoHandler.self)
let nsUrl = NSURL(string: "two")
let handled = router?.handleURL(nsUrl, withCompletion: nil)
expect(handled).to(beTrue())

This way if handleUrl returns true I know that the route has been handled by the specific route handler that is supposed to handle it (because all other route handlers automatically fail).

Sorry, code above is not tested for syntax, just a general idea.

@wumuu
Copy link

wumuu commented Jan 21, 2016

it is a good way to deal with my complex project file

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

No branches or pull requests

3 participants