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

API for implicit selfies (bad idea) #51

Closed
wants to merge 1 commit into from
Closed

Conversation

nedtwigg
Copy link
Member

@nedtwigg nedtwigg commented Dec 19, 2023

I'm pushing this up just to document an idea which turned out to be bad.

For my Selfie usecase, I am often snapshotting two things:

  • io.restassured.response.Response which models everything about an HTTP response (content, cookies, headers, etc)
  • common.EmailAssert an in-house data structure which models everything about an email (content, subject, etc)

I made a custom Snapshotter<T> for each of them

object TSelfie {
	object Response : Snapshotter<io.restassured.response.Response> { ... }
	object Email : Snapshotter<common.EmailDev> { ... }

but it was a pain to write out expectSelfie(somePage, TSelfie.Response) everywhere, so I tried the approach in this PR.

This turns out to be a bad approach, because a much better approach is

object TSelfie {
	object Response : Snapshotter<io.restassured.response.Response> {
		override fun snapshot(value: io.restassured.response.Response) = ...
		@JvmStatic
		fun expectSelfie(value: io.restassured.response.Response) = Selfie.expectSelfie(value, this)
	}

	object Email : Snapshotter<EmailAssert> {
		override fun snapshot(value: EmailAssert) = ...
		@JvmStatic fun expectSelfie(value: EmailAssert) = Selfie.expectSelfie(value, this)
	}
}

and then in a test I just do:

import static mypkg.TSelfie.Response.expectSelfie
import static mypkg.TSelfie.Email.expectSelfie
import static com.diffplug.selfie.expectSelfie

And I now I get seamless syntax and type-checking without any fanciness from Selfie.

@nedtwigg nedtwigg closed this Dec 19, 2023
@nedtwigg nedtwigg deleted the feat/implicit-selfie branch December 20, 2023 17:23
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

Successfully merging this pull request may close these issues.

1 participant