Skip to content

Refactor value matchers and postFix dependent syntax #56

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

Merged
merged 2 commits into from
Nov 9, 2018

Conversation

ultrasecreth
Copy link
Member

Refactor eqToVal matcher (Fixes #55)
Replace all syntax that requires postFix notation (Fixex #54) (@jozic please take a look)

Copy link
Contributor

@jozic jozic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

left some minor comments

@@ -240,7 +249,7 @@ val aMock = mock[Foo]

when(aMock.bar) thenReturn "mocked!" <=> aMock.bar shouldReturn "mocked!"
when(aMock.bar) thenReturn "mocked!" thenReturn "mocked again!" <=> aMock.bar shouldReturn "mocked!" andThen "mocked again!"
when(aMock.bar) thenCallRealMethod() <=> aMock.bar shouldCallRealMethod
when(aMock.bar) thenCallRealMethod() <=> aMock.bar shouldCall realMethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any other things you can type after shouldCall?
If not, then I'm not sure it's worth splitting it, just my 2c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also postfix notation and had a similar compiler error if it had a follow up line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about shouldReturn whateverRealMethdoReturns (not really sure what to put as the shouldReturn parameter, but it would make it more consistent if we can find something that reads nicely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think shouldReturn whateverRealMethdoReturns looks too long, so shouldCall realMethod is probably better

another way looking at it can be aMock.bar should not be mocked

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be would clash with ScalaTest, so it's a no go
I wasn't being literal with whateverRealMethdoReturns :P just looking for suggestions

verify(aMock, times(2)).bar <=> aMock.bar wasCalled twice
verify(aMock, times(6)).bar <=> aMock.bar wasCalled sixTimes
verifyNoMoreInteractions(aMock) <=> aMock was never called again
verifyNoMoreInteractions(aMock) <=> aMock wasNever calledAgain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively this can be
aMock wasCalled neverAgain
it looks more consistent with wasCalled twice and so on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

verify(aMock).bar <=> aMock.bar was called
verify(aMock).bar(any) <=> aMock.bar(*) was called
verify(aMock, only).bar <=> aMock.bar wasCalled onlyHere
verify(aMock, never).bar <=> aMock.bar was never called
verify(aMock, never).bar <=> aMock.bar wasNever called
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively aMock.bar wasCalled zeroTimes or aMock.bar wasCalled never

it's more consistent with the rest of the api, though I admit wasNever Called (or was neverCalled) reads better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'll take a second look

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about wasNot called and wasNot calledAgain
I know still doesn't uses the wasCalled but reads much better and it allows you to copy/paste and just add 'Not' (I've found myself doing that many times, so I think it's a popular use case`

also using Not instead of Never seems nicer, the reason I didn't do it before was that not was a keyword and it clashed with the same defined by ScalaTest, but if I use it as part of the method name then that's not an issue anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming things is hard, and there always will be who thinks it can have a better name, so i suggest juts pick something that compiles in all circumstances and be happy :)

i personally think that consistency is more important than following English, easy to remember => quick to use => more productive
but again, this is just me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but one of the main purposes of the DSL is to get rid of awkward reading sentences as well, and the current form is consistent with what it was there before (in both version 1.0.0 and 0.x.x) so I'm gonna keep it like this, history will judge me XD

Thanks a lot for your help!

@ultrasecreth ultrasecreth merged commit aaa1fd9 into release/1.x Nov 9, 2018
@ultrasecreth ultrasecreth deleted the refactor-value-matchers branch November 9, 2018 19:48
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.

2 participants