-
Notifications
You must be signed in to change notification settings - Fork 27
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
Document AssertJ interoperability with Spock 2.4 and Groovy #167
Comments
If I understand correctly, AssertJ breaks Spock interoperability as soon as the Is there anything in the Spock documentation about this? Mainly to understand if there are additional caveats to consider. |
I think it should be fixed at Spock side, it shouldn't wrap |
I also have the feeling preventing specific method names in AssertJ shouldn't be the way to go but I'm happy to elaborate on it better. @nweiser94 would you mind raising a related issue to Spock and see what they think? Happy to chime in, if needed. |
I actually think that this is not just a Spock specific issue, but a more general conflict with the Groovy language as assertj now hides Groovy built-ins. @scordio Nonetheless, i will raise an issue to Spock to see what they think. 👍 |
fyi: Raised Spock issue spockframework/spock#1897 |
I'm reading about power assertions as a Groovy language feature. However, in your example, there is no
So it sounds like something where Spock would have control? Looking forward to the maintainers' feedback. |
According to spockframework/spock#1897 (comment), this isn't something to be solved in AssertJ, so I'm closing the issue but happy to reconsider in case of new arguments. |
I am really not sure here, because this also break, when Spock is not involved, but only Groovy: import static org.assertj.core.api.Assertions.assertThat
def someString = 'some string'
assert assertThat(someString).isEqualTo('some string') AssertJ does not play well here with the Groovy semantic to use the method @scordio Can you have a second look? |
@AndreasTu is the Groovy semantic and the The power assertions section doesn't seem to tell the full story. I would like to understand the overall impact, if it's really about It seems quite an aggressive move to reserve a method name and force libraries not to use it... or, as you said in spockframework/spock#1897 (comment), maybe using AssertJ Core on top of Groovy power assertions makes little sense? |
@scordio You can find the documentation about that in the section Customizing the truth with asBoolean() methods in the Groovy documentation. Groovy has more such methods, see operator overloading |
I agree with that to a degree and Groovy should probably check the return type of But in general to map such semantics on top of some special methods in Groovy has more benefit than harm. if(myObject){
result += myObject
}
//instead of in Java
if(myObject.asBoolean()){
result = result.add(myObject)
}
My opinion would be: In general use AssertJ in Java code and use groovy power assertions in Groovy code. |
@AndreasTu looking at the plain Groovy example, what is the purpose of prefixing the We have some basic Groovy integration tests and none of them uses In addition, the junit5-jupiter-starter-gradle-groovy from the JUnit samples doesn't use My current impression is that there is nothing wrong with Groovy itself but only the way AssertJ is used with the Groovy language features. I understand that Spock introduces a layer of abstraction on top of Groovy, "wiring" the content of the |
assert assertThat(someString).isEqualTo('some string') It happens to work before assertj add |
None. It was just a sample without Spock, where AsssertJ is "violating" the Groovy-Truth evaluation.
Yes, and therefore there is an invisible So when AssertJ is used with Spock ( //Spock code
then:
!! assertThat(someString).isEqualTo('some string') would prevent the exception. The only additional thing I could see, is to open a ticket at Groovy and ask them, if they would handle the case where an Or maybe just live with the fact, that usage of AssertJ and Groovy-Truth may throw a |
I was halfway through it when I realized that it's the usage pattern in the plain example that is not OK. It's like saying that AssertJ doesn't work properly when used inside JUnit or Truth assertions... just don't do it 🙂
Yes, sorry – what you already wrote went through this time 😅 In light of that, the guideline should be:
What we can do is enhance the AssertJ docs to highlight this pitfall with Spock and Groovy. |
Describe the bug
The feature from assertj/assertj#2520 seems to be incompatible with using the
StringAssert
from assertj-core in a Groovy and Spock setup.The
then
block in a spock test feature wraps any assertion code line with an groovy powerassertassert
under the hood expecting the actual assertion expression to be evaluated as a boolean value. In Groovy there is theorg.codehaus.groovy.runtime.DefaultGroovyMethods#asBoolean(java.lang.Object)
method that Spock is calling. Due to the changes made to the AbstractStringAssert class this method is inaccessible and returns aBooleanAssert
instead.Test case reproducing the bug
Add a test case showing the bug that we can run
The text was updated successfully, but these errors were encountered: