#106 has changed the logic in test method generation and the fix from #109 will not work anymore. Modified it to make single value validation possible. Added tests.

This commit is contained in:
Olga Maciaszek-Sharma
2015-07-31 13:14:36 +02:00
parent c582c3d1d6
commit 3a8baa2212
3 changed files with 47 additions and 0 deletions

View File

@@ -98,6 +98,9 @@ abstract class SpockMethodBodyBuilder {
} else if (contentType == ContentType.XML) {
bb.addLine("def responseBody = new XmlSlurper().parseText($responseAsString)")
// TODO xml validation
} else {
bb.addLine("def responseBody = ($responseAsString)")
processBodyElement(bb, "", responseBody)
}
}

View File

@@ -359,4 +359,26 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification {
then:
spockTest.contains("entity('', 'application/octet-stream')")
}
def "should generate test for String in response body"() {
given:
GroovyDsl contractDsl = GroovyDsl.make {
request {
method "POST"
url "test"
}
response {
status 200
body "test"
}
}
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def spockTest = blockBuilder.toString()
then:
spockTest.contains('def responseBody = (response.body.asString())')
spockTest.contains('responseBody == "test"')
}
}

View File

@@ -306,4 +306,26 @@ class MockMvcSpockMethodBuilderSpec extends Specification {
then:
spockTest.contains(".body('')")
}
def "should generate test for String in response body"() {
given:
GroovyDsl contractDsl = GroovyDsl.make {
request {
method "POST"
url "test"
}
response {
status 200
body "test"
}
}
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def spockTest = blockBuilder.toString()
then:
spockTest.contains('def responseBody = (response.body.asString())')
spockTest.contains('responseBody == "test"')
}
}