Requires ColdBox 4.2+ and TestBox 2.3+
Install the package from ForgeBox:
box install integratedImportant:
Add the Integrated lib directory to this.javaSettings in your *tests* directory's Application.cfc.
this.javaSettings = { loadPaths = [ "Integrated/lib" ], reloadOnChange = false };Change your Integration tests to extend from Integration.BaseSpecs.ColdBoxBaseSpec. (Make sure to call the parent class's beforeAll method.)
component extends="Integrated.BaseSpecs.ColdBoxBaseSpec" {
function beforeAll() {
// Make sure to call the parent class's beforeAll() method.
super.beforeAll();
}
}Start using an easy, fluent API for your integration tests!
function run() {
describe( "Registering", function() {
it( "allows a new user to register for the site", function() {
this.visitEvent('register.new')
.type('Eric', 'name')
.type('mYAw$someP2ssw0rd!', 'password')
.press('Register')
.seeTitleIs('Home')
.seeOnPage('Welcome, Eric!');
});
});
}You can see all the different methods you can call in the API docs.
You can add automatic database transactions by adding one line to the top of your spec:
component extends="Integrated.BaseSpecs.ColdBoxBaseSpec" {
this.useDatabaseTransactions = true;
function run() {
describe( "Registering", function() {
it( "allows a new user to register for the site", function() {
this.visitEvent('register.new')
.type('Eric', 'name')
.type('mYAw$someP2ssw0rd!', 'password')
.press('Register')
.seeTitleIs('Home')
.seeOnPage('Welcome, Eric!');
});
});
}
}Easily add database transactions around your tests by adding this one property to your test:
this.useDatabaseTransactions = true;To create your own framework specific BaseSpec, first extend the Integrated.BaseSpecs.AbstractBaseSpec component.
component extends="Integrated.BaseSpecs.AbstractBaseSpec" {
function beforeAll() {
super.beforeAll(); // IMPORTANT! Don't forget to call `beforeAll()`!
// Your specific setup here.
}
}There are three abstract methods that you need to implement:
makeFrameworkRequest— makes a request specifically for your framework. Return whatever event object your framework uses. That object will be passed to thegetHTMLmethod you implement.getHTML— returns the html string from your framework's event object. This html string is then parsed and available for your tests.parseActionFromForm— returns just the route portion of a full uri. For example,http://localhost:8500/index.cfm/loginshould return just/loginin ColdBox.
You can look at Integrated.BaseSpecs.ColdBoxBaseSpec for how this is done for ColdBox.
This package is heavily inspired by Jeffrey Way's Integrated package for Laravel. I learned about it at Laracasts, which I consider my best programming resource regardless of the fact that I have never deployed a line of PHP code.