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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcontentFor(String name)This method returns chunks of content that was assigned from a tested template.protected voidregisterTag(String name, FreeMarkerTag tag)Use to register a tag before the test.protected StringRenders a template by nameprotected StringRenders a template by name.protected StringRenders a template by nameprotected <T extends AppController>
voidsetCurrentController(Class<T> controllerClass)This method is only needed as a hint to theLinkToTag.protected voidsetInjector(com.google.inject.Injector injector)Sets injector for tags if they require dependencies.voidsetTemplateLocation(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:
setTemplateLocationin 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:
setInjectorin classSpecHelper- Parameters:
injector- injector to source dependencies form.
-
registerTag
Use to register a tag before the test.- Overrides:
registerTagin 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_totag is used in a template without thecontrollerattribute, 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_toworks as expected. However, since view specs are executed outside of controller execution, if you have alink_toin 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_totag 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 theContentForTagwhen 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.
-