Skip to content

Commit

Permalink
Merge pull request #13224 from matrei/matrei/fix-flaky-rendertests
Browse files Browse the repository at this point in the history
Fix flaky tests by using different template names for each test.
  • Loading branch information
puneetbehl authored Nov 23, 2023
2 parents 8592c40 + c548313 commit 4ac6c05
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class AnotherController {
render(view:"foo")
}

def renderTemplate = {
render(template:"bar")
def renderTemplate(String template) {
render(template: template)
}

def renderXml = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,37 @@ class AstEnhancedControllerUnitTestMixinTests extends Specification implements C
file.targetFileLocation.path == "${File.separatorChar}local${File.separatorChar}disk${File.separatorChar}myFile"
}

void testRenderBasicTemplateNoTags() {
void testRenderBasicTemplateNoTags() {
given:
def templateName = 'testRenderBasicTemplateNoTags'

when:
groovyPages['/another/_bar.gsp'] = 'Hello <%= 10 %>'
controller.renderTemplate()
groovyPages["/another/_${templateName}.gsp" as String] = 'Hello <%= 10 %>'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello 10"
}

void testRenderBasicTemplateWithTags() {
given:
groovyPages['/another/_bar.gsp'] = 'Hello <g:message code="foo.bar" />'
def templateName = 'testRenderBasicTemplateWithTags'

when:
controller.renderTemplate()
groovyPages["/another/_${templateName}.gsp" as String] = 'Hello <g:message code="foo.bar" />'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello World"
}

void testRenderBasicTemplateWithLinkTag() {
void testRenderBasicTemplateWithLinkTag() {
given:
def templateName = 'testRenderBasicTemplateWithLinkTag'

when:
groovyPages['/another/_bar.gsp'] = 'Hello <g:createLink controller="bar" />'
controller.renderTemplate()
groovyPages["/another/_${templateName}.gsp" as String] = 'Hello <g:createLink controller="bar" />'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello /bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,37 @@ class ControllerUnitTestMixinTests extends Specification implements ControllerUn
}

void testRenderBasicTemplateNoTags() {
given:
def templateName = 'testRenderBasicTemplateNoTags'

when:
groovyPages['/test/_bar.gsp'] = 'Hello <%= 10 %>'
controller.renderTemplate()
groovyPages["/test/_${templateName}.gsp" as String] = 'Hello <%= 10 %>'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello 10"
}

void testRenderBasicTemplateWithTags() {
messageSource.addMessage("foo.bar", request.locale, "World")
given:
def templateName = 'testRenderBasicTemplateWithTags'

when:
groovyPages['/test/_bar.gsp'] = 'Hello <g:message code="foo.bar" />'
controller.renderTemplate()
messageSource.addMessage("foo.bar", request.locale, "World")
groovyPages["/test/_${templateName}.gsp" as String] = 'Hello <g:message code="foo.bar" />'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello World"
}

void testRenderBasicTemplateWithLinkTag() {

given:
def templateName = 'testRenderBasicTemplateWithLinkTag'

when:
groovyPages['/test/_bar.gsp'] = 'Hello <g:createLink controller="bar" />'
controller.renderTemplate()
groovyPages["/test/_${templateName}.gsp" as String] = 'Hello <g:createLink controller="bar" />'
controller.renderTemplate(templateName)

then:
response.contentAsString == "Hello /bar"
Expand Down Expand Up @@ -595,8 +602,8 @@ class TestController {
render(view:"foo")
}

def renderTemplate = {
render(template:"bar")
def renderTemplate(String template) {
render(template: template)
}

def renderXml = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,24 @@ class RenderMethodTests extends Specification implements ControllerUnitTest<Rend
}

void testRenderTemplateWithCollectionUsingImplicitITVariable() {
given:
def templateName = 'testRenderTemplateWithCollectionUsingImplicitITVariable'

when:
views['/render/_peopleTemplate.gsp'] = '${it.firstName} ${it.middleName}<br/>'
controller.renderTemplateWithCollection()
views["/render/_${templateName}.gsp" as String] = '${it.firstName} ${it.middleName}<br/>'
controller.renderTemplateWithCollection(templateName)

then:
response.contentAsString == 'Jacob Ray<br/>Zachary Scott<br/>'
}

void testRenderTemplateWithCollectionUsingExplicitVariableName() {
given:
def templateName = 'testRenderTemplateWithCollectionUsingExplicitVariableName'

when:
views['/render/_peopleTemplate.gsp'] = '${person.firstName} ${person.middleName}<br/>'
controller.renderTemplateWithCollectionAndExplicitVarName()
views["/render/_${templateName}.gsp" as String] = '${person.firstName} ${person.middleName}<br/>'
controller.renderTemplateWithCollectionAndExplicitVarName(templateName)

then:
response.contentAsString == 'Jacob Ray<br/>Zachary Scott<br/>'
Expand Down Expand Up @@ -249,19 +255,19 @@ class RenderController {
def renderTemplate() {
render(template:"testTemplate", model:[hello:"world"])
}
def renderTemplateWithCollection() {
def renderTemplateWithCollection(String template) {
def people = [
[firstName: 'Jacob', middleName: 'Ray'],
[firstName: 'Zachary', middleName: 'Scott']
]
render(template:"peopleTemplate", collection: people)
render(template: template, collection: people)
}
def renderTemplateWithCollectionAndExplicitVarName() {
def renderTemplateWithCollectionAndExplicitVarName(String template) {
def people = [
[firstName: 'Jacob', middleName: 'Ray'],
[firstName: 'Zachary', middleName: 'Scott']
]
render(var: 'person', template:"peopleTemplate", collection: people)
render(var: 'person', template: template, collection: people)
}
def renderXmlTemplate() {
render(template:"xmlTemplate",contentType:"text/xml")
Expand Down

0 comments on commit 4ac6c05

Please sign in to comment.