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

Unify method naming #252

Open
11 of 15 tasks
gavv opened this issue Jan 28, 2023 · 0 comments
Open
11 of 15 tasks

Unify method naming #252

gavv opened this issue Jan 28, 2023 · 0 comments
Assignees
Labels
refactoring Refactoring task
Milestone

Comments

@gavv
Copy link
Owner

gavv commented Jan 28, 2023

Current httpexpect API suffers from a problem: it's not always clear what a method returns: the same object on which it was called, or a new object.

To address this problem, two steps will be done:

  • method naming will be unified, so that it's easy to guess from the name what is returned
  • a new set of methods will be added for inspecting nested objects using callbacks, so that you can write a bit more verbose but also more structured assertions, if you want

This issue is for the first part; the second will be tracked in a separate issue.

Renaming methods will be a gradual process. A few subsequent releases will add methods with new names and mark old methods as deprecated. All deprecated methods will be kept until release of v3. There will be a time window between deprecations and release of v3 so that the users have time to update.

The following naming convention is suggested:

  • assertions - IsXxx(), InXxx(), HasXxx(), ContainsXxx(), ConsistsXxx()

    Methods that perform a check on the object and return the same object, will all have distinguishable prefixes listed above. Examples: IsEmpty, InRange, HasSuffix, ContainsAny. Many of these methods are already named this way.

  • converters - AsXxx()

    Methods that convert given object to another type and return it, will have prefix As. Examples: AsNumber, AsDateTime. All such methods are already named this way.

  • accessors - Noun()

    Methods that extract another (new) object from the given one and return it, will keep their names and will be named just as nouns. Examples: Body, Form, Element.

    I was thinking about given them a prefix as well (e.g. GetXxx), but this would break too much code and significantly harm brevity.

Actual renames to be done:

  • All: Empty => IsEmpty (2.11.0)
  • All: Equal* => IsEqual* (2.11.0)
  • Boolean: True, False => IsXxx (2.12.0)
  • Value: Null => IsNull (2.12.0)
  • Array: Element => Value (2.13.0)
  • Object: ValueEqual => HasValue (2.13.0)
  • Response: ContentType, ContentEncoding, TransferEncoding => HasXxx (2.16.0)
  • Match: Index => Submatch (2.17.0)
  • Match: Name => NamedSubmatch (2.17.0)
  • Match: Values => HasSubmatches (2.17.0)
  • Cookie: HasMaxAge => ContainsMaxAge (2.17.0)
  • Response: Status => HasStatus
  • Response: StatusRange, StatusList => HasStatusInXxx
  • All: Gt, Ge, Lt, Le => IsXx
  • WebsocketMessage: Is<TYPE>, HasType, HasCode
@gavv gavv added the refactoring Refactoring task label Jan 28, 2023
@gavv gavv added this to the v2 milestone Jan 28, 2023
@gavv gavv self-assigned this Jan 28, 2023
@gavv gavv mentioned this issue Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring task
Projects
None yet
Development

No branches or pull requests

1 participant