-
Notifications
You must be signed in to change notification settings - Fork 36
SpecTests for BRJS Plugins
sospirited edited this page Apr 8, 2014
·
1 revision
It's the Java test framework used in BRJS which adopts a Given
/When
/Then
style to writetests in a way that promotes readability of the system specification.
- Allow you to create whatever folder/directory structure and JS dependencies in a BDD style
- Capture all exceptions and output them to the console if they were not an expectation of the test
- Will do all of their 'work' inside the OS temporary directory
- Tests will cleanup after themselves after running tests
public class CreateApplicationCommand exteds SpecTest {
App app;
@Before
public void init() throws Exception()
{
given(brjs).hasCommands(new CreateApplicationCommand())
.and(brjs).hasBeenCreated();
app = brjs.app("myapp");
}
// Asserts the expected exception, with the expected exception parameters
@Test
public void exceptionIsThrownIfTheAppAlreadyExists() throws Exception
{
given(app).hasBeenCreated();
when(brjs).runCommand("create-app", "app", "appx");
then(exceptions).verifyException(NodeAlreadyExistsException.class, unquoted(app.getName())
.whereTopLevelExceptionIs(CommandArgumentsException.class);
}
}
public class CompositeJsTagHandlerPluginTest extends SpecTest {
App app;
Aspect aspect;
StringBuffer requestResponse = new StringBuffer();
@Before
public void initTestObjects() throws Exception
{
given(brjs).automaticallyFindsBundlers()
.and(brjs).automaticallyFindsMinifiers()
.and(brjs).hasBeenCreated();
app = brjs.app("app1");
aspect = app.aspect("default");
}
@Test
public void jsBundleTagMakesRequestToCorrectJsClasses() throws Exception
{
given(aspect).hasClasses("appnamespace/Class1", "appnamespace/subfolder/Class2")
.and(aspect).indexPageHasContent("<@js.bundle@/>");
when(aspect).indexPageLoadedInDev(pageResponse, "en_GB");
then(pageResponse).containsRequests(
"node-js/module/appnamespace/Class1.js",
"node-js/module/appnamespace/subfolder/Class2.js");
}
}