Skip to content
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

Fix flaky tests by using different template names for each test. #13224

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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