public class ControllerSpec extends RequestSpecHelper
public class GreeterController extends AppController{ ... }then the test will look like this:
public class GreeterControllerSpec extends ControllerSpec{ ... }ActiveWeb controller specs allow for true TDD, since they do not have a compiler dependency on controllers. You can describe full behavior of your controller before a controller class even exists. Simplest example:
public GreeterControllerSpec extends ControllerSpec{ @Test public void shouldRespondWithGreetingMessage(){ request().get("index"); a(responseCode()).shouldBeEqual(200); a(assigns().get("message")).shouldBeEqual("Hello, earthlings!"); } }In a code snippet above, a request with HTTP GET method is simulated to the GreeterController, index() action. Controller is expected to assign an object called "message" with value "Hello, earthlings!" to a view. This class will not open a connection to a test DB. If you need a connection, use
DBControllerSpec
.org.javalite.activeweb.DBControllerSpec}.
SpecHelper.ModuleBuilder
Constructor and Description |
---|
ControllerSpec() |
Modifier and Type | Method and Description |
---|---|
void |
atStart() |
protected String |
getControllerClassName() |
protected String |
getControllerPath()
Returns a controller path - this includes packages if there are any after "app.controllers".
|
protected RequestBuilder |
request()
Use this DSL-ish method to send requests to controllers from specs.
|
protected RequestBuilder |
request(boolean integrateViews)
Version of
request() that also sets integrateViews == true |
assigns, atStart00, bytesContent, contentType, cookie, cookieValue, count, getCookies, header, layout, redirected, redirectValue, responseContent, statusCode, template, text, val, val, valBoolean, valDouble, valFloat, valInteger, valLong, vals, valString
afterEnd, createInjector, flash, flash, flashExists, registerTag, session, session, session, sessionBoolean, sessionDouble, sessionFloat, sessionHas, sessionInteger, sessionLong, sessionObject, sessionString, setInjector, setTemplateLocation
public void atStart()
atStart
in class SpecHelper
protected RequestBuilder request()
RequestBuilder
with convenience methods.protected RequestBuilder request(boolean integrateViews)
request()
that also sets integrateViews == trueintegrateViews
- true to also generate response contentRequestBuilder
with convenience methods.protected final String getControllerPath()
protected final String getControllerClassName()
Copyright © 2016. All rights reserved.