Click the first line (Eclipse) or link (IDEA) in the failure output to
open a diff view comparing the two objects. This works for arbitrary
types of objects. Kudos to FEST-Assert (http://fest.easytesting.org/)
for the idea!
7. Better Eclipse and IDEA integration
--------------------------------------
As always, we have worked with the folks behind Groovy-Eclipse and
IDEA to provide the best possible IDE experience.
8. Other improvements and fixes
-------------------------------
> Click the first line (Eclipse) or link (IDEA) in the failure output to > open a diff view comparing the two objects. This works for arbitrary > types of objects. Kudos to FEST-Assert (http://fest.easytesting.org/) > for the idea!
> 7. Better Eclipse and IDEA integration > --------------------------------------
> As always, we have worked with the folks behind Groovy-Eclipse and > IDEA to provide the best possible IDE experience.
> 8. Other improvements and fixes > -------------------------------
> The Spock Grails plugin comes in two distributions for Grails 1.2 and > 1.3, respectively. See http://grails.org/plugin/spock for more > information.
> Thanks to everyone who provided ideas, feedback, patches, or helped to > promote Spock. Please keep supporting us!
> What's Up Next > ==============
> 0.6 will be a smaller and quicker release. Main goal is to write a > comprehensive Spock manual.
> Have fun with Spock! > Peter
> -- > You received this message because you are subscribed to the Google Groups "Spock Framework - User" group. > To post to this group, send email to spockframework@googlegroups.com. > To unsubscribe from this group, send email to spockframework+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
then: "I should receive and XML with an OK notification"
res.status == 200
res.data.text() == "OK"
and: "The userTemplate should have been updated"
res = settingsService.get(path: "templates", query:
[X_Security_Token: token.value])
res.status == 200
def newTemplate = res.data.userTemplate.find {it.@id ==
newUserTemplateId}
println "Retrieved template id is $newUserTemplateId"
newTemplate.@id == newUserTemplateId
newTemplate.label == "An updated user template"
But Spock 0.5 complains that "Groovy:Expected a condition, but found
an assignment. Did you intend to write '==' ?" on the first line of
the and: block.
Docs says that variables can be defined in when: blocks, and this
worked perfect in Spock 0.4
If this is no longer possible by design, how should I refactor my
test?
On Dec 11, 1:50 am, Peter Niederwieser <pnied...@gmail.com> wrote:
> Click the first line (Eclipse) or link (IDEA) in the failure output to
> open a diff view comparing the two objects. This works for arbitrary
> types of objects. Kudos to FEST-Assert (http://fest.easytesting.org/)
> for the idea!
> 7. Better Eclipse and IDEA integration
> --------------------------------------
> As always, we have worked with the folks behind Groovy-Eclipse and
> IDEA to provide the best possible IDE experience.
> 8. Other improvements and fixes
> -------------------------------
> But Spock 0.5 complains that "Groovy:Expected a condition, but found > an assignment. Did you intend to write '==' ?" on the first line of > the and: block. > Docs says that variables can be defined in when: blocks, and this > worked perfect in Spock 0.4
The problem is in this line:
then: res = settingsService.get(path: "templates", query: [X_Security_Token: token.value])
This code doesn't declare a new variable, but reassigns an existing one. It is evaluated as a condition and will fail if the assigned value is false according to Groovy truth. This behavior is almost never desirable, and can give rise to nasty bugs. For example, if you write "x = y" when you really meant "x == y", the condition will almost always be true, and will lead you to believe that x and y are equal even when they aren't.
> If this is no longer possible by design, how should I refactor my test?
Hi Peter, thanks for your answer.
Yeah, it helps, partially.
Maybe I'm not using the best practices, since I'm quite new to Groovy
and Spock.
My case is like this, I want to test some REST calls. These REST
service allows me to create, update and delete templates. So I have a
specification to excersice this.
The first method will create a template, then check that the template
has been created, and saves the template id in a variable.
Second method will update the template, then check that the template
has been updated.
Third one will delete the template, then check that it has been
actually deleted.
So, I used to save the templateId in a class variable (annotated with
@Shared) and use it in all my test (so I always work with the same
template)
@Shared newUserTemplateId = 0
def "Create a new user template"() {
when: "I create a new userTemplate with the REST service"
def res = settingsService.post(
path: "userTemplate",
query: [X_Security_Token: token.value,
data_xml: """<?xml version="1.0" encoding="UTF-8" standalone="no"?
><blah/>"""]
)
then: "I should receive an XML with the userTemplateId"
res.status == 200
res.data.toInteger() > 0
newUserTemplateId = res.data.text()
println "The new templateId is $newUserTemplateId"
}
If I cannot assign the newUserTemplateId variable in the then: block,
where then? I cannot do it at the end of the when: block because I
still don't know if the call was successful. It would work in the
cleanup: block, but is that the right place?
Thanks,
Alex.
On Dec 13, 6:36 pm, Peter Niederwieser <pnied...@gmail.com> wrote:
> > But Spock 0.5 complains that "Groovy:Expected a condition, but found
> > an assignment. Did you intend to write '==' ?" on the first line of
> > the and: block.
> > Docs says that variables can be defined in when: blocks, and this
> > worked perfect in Spock 0.4
> The problem is in this line:
> then:
> res = settingsService.get(path: "templates", query: [X_Security_Token: token.value])
> This code doesn't declare a new variable, but reassigns an existing one. It is evaluated as a condition and will fail if the assigned value is false according to Groovy truth. This behavior is almost never desirable, and can give rise to nasty bugs. For example, if you write "x = y" when you really meant "x == y", the condition will almost always be true, and will lead you to believe that x and y are equal even when they aren't.
> > If this is no longer possible by design, how should I refactor my test?
> Hi Peter, thanks for your answer. > Yeah, it helps, partially.
> Maybe I'm not using the best practices, since I'm quite new to Groovy > and Spock. > My case is like this, I want to test some REST calls. These REST > service allows me to create, update and delete templates. So I have a > specification to excersice this.
> The first method will create a template, then check that the template > has been created, and saves the template id in a variable. > Second method will update the template, then check that the template > has been updated. > Third one will delete the template, then check that it has been > actually deleted.
> So, I used to save the templateId in a class variable (annotated with > @Shared) and use it in all my test (so I always work with the same > template)
> @Shared newUserTemplateId = 0
> def "Create a new user template"() { > when: "I create a new userTemplate with the REST service" > def res = settingsService.post( > path: "userTemplate", > query: [X_Security_Token: token.value, > data_xml: """<?xml version="1.0" encoding="UTF-8" standalone="no"? >> <blah/>"""] > ) > then: "I should receive an XML with the userTemplateId" > res.status == 200 > res.data.toInteger() > 0 > newUserTemplateId = res.data.text() > println "The new templateId is $newUserTemplateId" > }
> If I cannot assign the newUserTemplateId variable in the then: block, > where then? I cannot do it at the end of the when: block because I > still don't know if the call was successful. It would work in the > cleanup: block, but is that the right place?
> Thanks, > Alex.
> On Dec 13, 6:36 pm, Peter Niederwieser <pnied...@gmail.com> wrote: >> On 13.12.2010, at 19:04, Ale Sarco wrote:
>>> But Spock 0.5 complains that "Groovy:Expected a condition, but found >>> an assignment. Did you intend to write '==' ?" on the first line of >>> the and: block. >>> Docs says that variables can be defined in when: blocks, and this >>> worked perfect in Spock 0.4
>> The problem is in this line:
>> then: >> res = settingsService.get(path: "templates", query: [X_Security_Token: token.value])
>> This code doesn't declare a new variable, but reassigns an existing one. It is evaluated as a condition and will fail if the assigned value is false according to Groovy truth. This behavior is almost never desirable, and can give rise to nasty bugs. For example, if you write "x = y" when you really meant "x == y", the condition will almost always be true, and will lead you to believe that x and y are equal even when they aren't.
>>> If this is no longer possible by design, how should I refactor my test?
>> The solution is to introduce another variable:
>> then: >> def newRes = ...
>> Hope this helps.
>> Cheers, >> Peter
> -- > You received this message because you are subscribed to the Google Groups "Spock Framework - User" group. > To post to this group, send email to spockframework@googlegroups.com. > To unsubscribe from this group, send email to spockframework+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.