Open leonard84 opened 3 years ago
I’ve been using a bunch of regex search/replaces in IntelliJ. My assertThat search, mainly for the is()
flavour, is:
assertThat\((.*),\s*is\((.*)\)\)
$1 == $2
So the is(not(
equivalent would be:
assertThat\((.*),\s*is\(not\((.*)\)\)\)
$1 != $2
And a more interesting variant to transform assertThrows
:
assertThrows\((\w+)(?:.class),[\(\)\{\s]+->(.*)[\}]*\)
when: "we execute our test"\n$2\n\n then: "a $1 was thrown"\n thrown($1)\n
Although I guess our matchers might be more sophisticated...
Thank you for your input, I'll go for it.
@rojyates If you have more Regex or Replacements which you would like to have, feel free create more issues. I created a new issue template to facilitate the process of creating replacement issues. Even if the complete framework support is on the roadmap I'll focus on the concrete cases by the users which I'll find in the issues.
@masooh that's a great idea. I'll start adding some of them in. Another useful option would be to make use of https://github.com/marcingrzejszczak/spock-subjects-collaborators-extension, which gives a Spock version for Mockito's @InjectMocks.
btw. Support assertSame
would be kind
@rojyates IMHO we should focus on supporting the core Spock features first, but feel free to open another ticket for the collaborator extension.
This can be a two step approach.
Spock has
spock.util.matcher.HamcrestSupport
so the basic approach would be to replace theassertThat
invocations with thethat()
(inexpect
-blocks) orexpect()
(inthen
-blocks) methods ofHamcrest
-support.In a second iteration, the matchers could be analyzed and replaced if there is a simple Spock equivalent, e.g.,
assertThat(x, is("ok"))
would bex == "ok"
, andassertThat(x, is(not("ok")))
would bex != "ok"
.