Closed havenqi closed 5 years ago
So a bug was reported and fixed in 1.8.1 related to how variables are resolved in the Groovy closures. The closures now resolve the delegate first, which is really the best approach; however, this can cause some odd scoping issues especially with static content.
While this is not ideal, you should be able to use variables in the test method itself, such as:
def 'some test'(){
setup:
String bodyContent = BODY_CONTENT
server.expectations {
... use bodyContent in here rather than BODY_CONTENT
}
}
When I have time I will try to look into ways to resolve this issue so that it works as it did before, but for now, please just use the workaround I mentioned above.
Note: yes, the fluid build approach will work too since it is standard Java, not a Groovy closure.
To summarize from the other issue (closed):
When the Groovy closure variable resolution gets confused it does some odd things. The response body DSL method calls the request body object in this case which creates another request expectation.
Some workarounds:
I will see what I can find.
Thanks for your quick answer. I'll also try java way to confirm if any other odd things occur with closure again.
BODY_CONTENT was mistakenly resolved in both request and response body in expectation. I had to use literal String ‘abc’ or local variable to make it work. While the same varialbe can be resolved correctly in chained builder style of coding. In below test spec,
Posting 3: works with chained builder style