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

Stub GET (or POST) params in different order #101

Open
patoroco opened this issue Dec 29, 2014 · 3 comments
Open

Stub GET (or POST) params in different order #101

patoroco opened this issue Dec 29, 2014 · 3 comments

Comments

@patoroco
Copy link

Hi,

I'm trying to stub a request with Nocilla, and I'm not sure that with regex should be enough to define path structure.
I mean, when you send GET or POST params, you don't need to send these params in any order, so regex isn't the same for GET: http://api.myhost.com/users?pagination=5&per_page=10 than for GET: http://api.myhost.com/users?per_page=10&pagination=5, but API response should be the same.

Should be interesting to have a dictionary with GET/POST params instead of a NSString and iterate over it instead of match exactly? If your answer is yes, I could start to work in my first PR to Nocilla :)

What do you think about that?

@Ben-G
Copy link

Ben-G commented Jun 24, 2015

👍 I realize that this issue is super old, but I would appreciate this feature :)

@luisobo
Copy link
Owner

luisobo commented Jun 24, 2015

@patoroco @Ben-G

Hi,

It's not documented but Nocilla is pretty extensible. In the DSL, both the expected URL and the expected body, expect an LSMatcheable.

All you have to do is create an object that conforms to that protocol and has the logic that you wish to implement and pass that object to the DSL. For instance you could do:

stubRequest(@"GET", matchingUrl(@"http://foo.com").withQuery(@{"abc": @"123"}))
.withBody(matchingJson(@{"fgh":@"666"))

Your functions matchingUrl().withQuery() and matchingJson() should return an LSMatcheable

And LSMatcheable spits LSMatchers that can compare in arbitrary ways the actual string (url, body, anything) with whatever data you passed into the DSL. That comparison could be order agnostic if you wish.

Nocilla is internally implemented using LSMatcheable, that's how I added support for regular expressions in URL, so you'll have examples of usage in the code already.

Play with it, let me know if you have any questions and contribute back if you feel like it.

@Ben-G
Copy link

Ben-G commented Jun 26, 2015

Thanks @luisobo. I think I'll look into this!

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