Skip to content

murphydan/integrated

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Integrated

A TestBox package for even better Integration tests in ColdBox!

Master Branch Build Status Development Branch Build Status

Requirements

Requires ColdBox 4.2+ and TestBox 2.3+

Installation

Install the package from ForgeBox:

box install integrated

Important: Add the Integrated lib directory to this.javaSettings in your *tests* directory's Application.cfc.

this.javaSettings = { loadPaths = [ "Integrated/lib" ], reloadOnChange = false };

Usage

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;

Creating Framework-specific BaseSpecs

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:

  1. makeFrameworkRequest — makes a request specifically for your framework. Return whatever event object your framework uses. That object will be passed to the getHTML method you implement.
  2. getHTML — returns the html string from your framework's event object. This html string is then parsed and available for your tests.
  3. parseActionFromForm — returns just the route portion of a full uri. For example, http://localhost:8500/index.cfm/login should return just /login in ColdBox.

You can look at Integrated.BaseSpecs.ColdBoxBaseSpec for how this is done for ColdBox.

Credits

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.

About

A TestBox package for even better Integration tests in ColdBox!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 69.4%
  • JavaScript 13.2%
  • ColdFusion 10.0%
  • CSS 7.4%