Package org.javalite.activeweb
Class ViewSpec
java.lang.Object
org.javalite.activeweb.SpecHelper
org.javalite.activeweb.ViewSpec
- All Implemented Interfaces:
JSpecSupport
This is a spec used to test templates and custom tags.
- Author:
- Max Artyukhov
-
Nested Class Summary
Nested classes/interfaces inherited from class org.javalite.activeweb.SpecHelper
SpecHelper.DynamicBuilder, SpecHelper.ModuleBuilder
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
contentFor(String name)
This method returns chunks of content that was assigned from a tested template.protected void
registerTag(String name, FreeMarkerTag tag)
Use to register a tag before the test.protected String
Renders a template by nameprotected String
Renders a template by name.protected String
Renders a template by nameprotected <T extends AppController>
voidsetCurrentController(Class<T> controllerClass)
This method is only needed as a hint to theLinkToTag
.protected void
setInjector(com.google.inject.Injector injector)
Sets injector for tags if they require dependencies.void
setTemplateLocation(String templateLocation)
By default the template location is set tosrc/main/webapp/WEB-INF/views
.Methods inherited from class org.javalite.activeweb.SpecHelper
afterEnd, atStart, createInjector, flash, flash, flashExists, injector, session, session, session, sessionBoolean, sessionDouble, sessionFloat, sessionHas, sessionInteger, sessionLong, sessionObject, sessionString
-
Constructor Details
-
ViewSpec
public ViewSpec()
-
-
Method Details
-
beforeTest
public final void beforeTest() -
afterTest
public final void afterTest() -
setTemplateLocation
By default the template location is set tosrc/main/webapp/WEB-INF/views
. However in some cases you want to have test templates that are different from runtime templates. In those cases you can override that default location with your value,- Overrides:
setTemplateLocation
in classSpecHelper
- Parameters:
templateLocation
- location of your templates relative to the directory where test is executed, usually a root of your Maven module
-
setInjector
protected void setInjector(com.google.inject.Injector injector)Sets injector for tags if they require dependencies.- Overrides:
setInjector
in classSpecHelper
- Parameters:
injector
- injector to source dependencies form.
-
registerTag
Use to register a tag before the test.- Overrides:
registerTag
in classSpecHelper
- Parameters:
name
- name of tag as used in a template.tag
- tag instance
-
render
Renders a template by name- Parameters:
templateName
- name of template to render- Returns:
- rendered template
-
render
Renders a template by name- Parameters:
templateName
- name of template to rendervalues
- values to be passed into template- Returns:
- rendered template content as string
-
render
Renders a template by name.- Parameters:
templateName
- name of template to rendernamesAndValues
- - list of names and values, where first, third, etc argument is a name and second, fourth, etc. argument is a corresponding value.- Returns:
- rendered template content as string
-
setCurrentController
This method is only needed as a hint to theLinkToTag
. If thelink_to
tag is used in a template without thecontroller
attribute, it needs a current controller in context to generate a proper link. At runtime as well as in controller tests, a controller is always present in context, andlink_to
works as expected. However, since view specs are executed outside of controller execution, if you have alink_to
in the template you are testing, you will need to provide a clue to your view before the test is executed.- Parameters:
controllerClass
- controller class to aid to thelink_to
tag to generate a proper link.
-
contentFor
This method returns chunks of content that was assigned from a tested template. Call this method after rendering a view in order to verify that the view did set appropriate text chunks with theContentForTag
when it is used in a template, example:<@content for="title">Book title</@content>
- Parameters:
name
- name of a content piece as was specified by the "for" attribute of the "content" tag.- Returns:
- piece of content assigned from "content" tag if one was used in a tested view.
-