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

Provide Intent Oriented Syntax #1

Open
dupdob opened this issue Jun 17, 2015 · 4 comments
Open

Provide Intent Oriented Syntax #1

dupdob opened this issue Jun 17, 2015 · 4 comments

Comments

@dupdob
Copy link
Contributor

dupdob commented Jun 17, 2015

I would like to have a syntax that focuses on intent to improve further on readability. So instead of

                    Responses
                        .WithStatusCode(200)
                        .WithBody(@"{ msg: ""Hello world!""}")

I would prefer

                    Responses
                        .Success
                        .WithBody(@"{ msg: ""Hello world!""}")

other example

                    Responses
                        .RedirectTo("/bar");

I think it may also be helpful when you want to simulate ill behaving servers

@jbuiss0n
Copy link

jbuiss0n commented Sep 7, 2015

I would prefer method chaing instead of properties, something like:

Responses
    .WithSuccess()
    .WithBody(@"{ msg: ""Hello world!""}")

This way I find the alias/shortcut more obvious.

@dupdob
Copy link
Contributor Author

dupdob commented Sep 7, 2015

Makes sense to me. Next the next question is : which use cases should be supported through shortcuts. Should we list broad categories (such as 2xx = with success, 3xx = WithRedirect, 4xx = WithRrror, 5xx=WithServerError) , or dig into more specifics (404=WithNotFound)?

@alexvictoor
Copy link
Owner

Thanks for the feedback
The problem is HTTP defines quite a bunch of possible status code.
I think it is a good idea to list most common scenario as listed by dupdob and keep a generic WithStatusCode() method for hedge cases.
WDYT?

@dupdob
Copy link
Contributor Author

dupdob commented Sep 9, 2015

We definitely need both shortcuts for the most beaten paths as well as the ability to be very specific for the edge cases. In order to favor the 'pit of success' factor, one need to makes what is frequently used easy and what is less frequent possible. So I would propose:

Responses.WithSuccess() // ok for any 2xx code
Responses.WithOk() // ok if code = 200
Responses.WithSuccess().AndCode(2xx) // ok for code 2xx

Responses.WithError() // ok for any 4-5xx
Responses.WithNotFound() // ok for 404
Responses.WithInternalError() // ok for 5xx

Responses.WithSpecific().ForCode(xxx) // ok for code xxx

see the idea. Writing those samples, I realize I feel there is a wording issue with 'Responses'. But I will open a new issue to discuss it

alexvictoor pushed a commit that referenced this issue Jan 26, 2016
Added test for searching body using wildcards
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