ColdBox Platform v3.8.0

coldbox.system.testing
Class BaseSpec

WEB-INF.cftags.component
        extended by coldbox.system.testing.BaseSpec
Direct Known Subclasses:
TestCase

public class BaseSpec
extends WEB-INF.cftags.component

******************************************************************************* Copyright 2005-2009 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.coldbox.org | www.luismajano.com | www.ortussolutions.com ******************************************************************************* This is a base spec object that is used to test XUnit and BDD style specification methods

Method Summary
 any addAssertions(any assertions)
          Add custom assertions to the $assert object
 any addMatchers(any matchers)
          Add custom matchers to your expectations
 any afterEach(any body)
          This function is used for BDD test suites to store the afterEach() function to execute for a test suite group
 any assert(any expression, [any message=''])
          Assert that the passed expression is true
 any beforeEach(any body)
          This function is used for BDD test suites to store the beforeEach() function to execute for a test suite group
 any clearDebugBuffer()
          Clear the debug array buffer
 any closureStub()
 any console(any var, [any top='9999'])
          Send some information to the console via writedump( output="console" )
 any createEmptyMock([string className], [any object], [boolean callLogging='true'])
          Create an empty mock
 any createMock([string className], [any object], [boolean clearMethods='false'])
          Create a mock with or without clearing implementations, usually not clearing means you want to build object spies
 any createStub([boolean callLogging='true'], [string extends=''], [string implements=''])
          Create an empty stub object that you can use for mocking
 any debug([any var], [boolean deepCopy='false'])
          Debug some information into the TestBox debugger array buffer
 any describe(string title, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
 Expectation expect([any actual])
          Start an expectation expression
 any expectedException([any type=''], [any regex='.*'])
          Expect an exception from the testing spec
 any fail([any message=''])
          Fail an assertion
 array getDebugBuffer()
          Get the debug array buffer from scope
 any getMockBox([string generationPath])
          Get a reference to the MockBox engine
private boolean isExpectedException(any exception, any specName, any runner)
          Check if the incoming exception is expected or not
 any it(string title, any body, [any labels='[runtime expression]'], [any skip='false'])
          The it() function describes a spec or a test in TestBox
 any makePublic(any target, string method, [string newName=''])
          Make a private method on a CFC public with or without a new name and returns the target object
 any prepareMock([any object], [boolean callLogging='true'])
          Prepares an already instantiated object to act as a mock for spying and much more
 any print(any message)
          Write some output to the ColdFusion output buffer
 any println(any message)
          Write some output to the ColdFusion output buffer using a
attached
 any querySim(any queryData)
          First line are the query columns separated by commas
remote any runRemote([string testSpecs=''], [string testSuites=''], [boolean debug='false'], [string reporter='simple'])
          Run a test remotely, only useful if the spec inherits from this class
 any runSpec(any spec, any suite, any testResults, any suiteStats, any runner)
          Run a BDD test in this target CFC
 any runTestMethod(any spec, any testResults, any suiteStats, any runner)
          Runs a xUnit style test method in this target CFC
 any xdescribe(string title, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'])
          This is a convenience method that makes sure the test suite is skipped from execution
 any xit(string title, any body, [any labels='[runtime expression]'])
          This is a convenience method that makes sure the test spec is skipped from execution
 
Methods inherited from class WEB-INF.cftags.component
None
 

Method Detail

addAssertions

public any addAssertions(any assertions)
Add custom assertions to the $assert object

Parameters:
assertions - The structure of custom assertion functions to register or a path or instance of a CFC containing all the assertion functions to register

addMatchers

public any addMatchers(any matchers)
Add custom matchers to your expectations

Parameters:
matchers - The structure of custom matcher functions to register or a path or instance of a CFC containing all the matcher functions to register

afterEach

public any afterEach(any body)
This function is used for BDD test suites to store the afterEach() function to execute for a test suite group

Parameters:
body - The closure function

assert

public any assert(any expression, [any message=''])
Assert that the passed expression is true

Parameters:
expression
message

beforeEach

public any beforeEach(any body)
This function is used for BDD test suites to store the beforeEach() function to execute for a test suite group

Parameters:
body - The closure function

clearDebugBuffer

public any clearDebugBuffer()
Clear the debug array buffer


closureStub

public any closureStub()


console

public any console(any var, [any top='9999'])
Send some information to the console via writedump( output="console" )

Parameters:
var - The data to send
top - Apply a top to the dump, by default it does 9999 levels

createEmptyMock

public any createEmptyMock([string className], [any object], [boolean callLogging='true'])
Create an empty mock

Parameters:
className - The class name of the object to mock. The mock factory will instantiate it for you
object - The object to mock, already instantiated
callLogging - Add method call logging for all mocked methods. Defaults to true

createMock

public any createMock([string className], [any object], [boolean clearMethods='false'])
Create a mock with or without clearing implementations, usually not clearing means you want to build object spies

Parameters:
className - The class name of the object to mock. The mock factory will instantiate it for you
object - The object to mock, already instantiated
clearMethods - If true, all methods in the target mock object will be removed. You can then mock only the methods that you want to mock. Defaults to false

createStub

public any createStub([boolean callLogging='true'], [string extends=''], [string implements=''])
Create an empty stub object that you can use for mocking

Parameters:
callLogging - Add method call logging for all mocked methods. Defaults to true
extends - Make the stub extend from certain CFC
implements - Make the stub adhere to an interface

debug

public any debug([any var], [boolean deepCopy='false'])
Debug some information into the TestBox debugger array buffer

Parameters:
var - The data to send
deepCopy - By default we do not duplicate the incoming information, but you can :)

describe

public any describe(string title, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The title is usually what you are testing or grouping of tests. The body is the function that implements the suite.

Parameters:
title - The name of this test suite
body - The closure that represents the test suite
labels - The list or array of labels this suite group belongs to
asyncAll - If you want to parallelize the execution of the defined specs in this suite group.
skip - A flag or a closure that tells TestBox to skip this suite group from testing if true. If this is a closure it must return boolean.

expect

public Expectation expect([any actual])
Start an expectation expression. This returns an instance of Expectation so you can work with its matchers.

Parameters:
actual - The actual value, it is not required as it can be null.

expectedException

public any expectedException([any type=''], [any regex='.*'])
Expect an exception from the testing spec

Parameters:
type - The type to expect
regex - Optional exception message regular expression to match, by default it matches .*

fail

public any fail([any message=''])
Fail an assertion

Parameters:
message

getDebugBuffer

public array getDebugBuffer()
Get the debug array buffer from scope


getMockBox

public any getMockBox([string generationPath])
Get a reference to the MockBox engine

Parameters:
generationPath - The path to generate the mocks if passed, else uses default location.

isExpectedException

private boolean isExpectedException(any exception, any specName, any runner)
Check if the incoming exception is expected or not.

Parameters:
exception
specName
runner

it

public any it(string title, any body, [any labels='[runtime expression]'], [any skip='false'])
The it() function describes a spec or a test in TestBox. The body argument is the closure that implements the test which usually contains one or more expectations that test the state of the code under test.

Parameters:
title - The title of this spec
body - The closure that represents the test
labels - The list or array of labels this spec belongs to
skip - A flag or a closure that tells TestBox to skip this spec test from testing if true. If this is a closure it must return boolean.

makePublic

public any makePublic(any target, string method, [string newName=''])
Make a private method on a CFC public with or without a new name and returns the target object

Parameters:
target - The target object to expose the method
method - The private method to expose
newName - If passed, it will expose the method with this name, else just uses the same name

prepareMock

public any prepareMock([any object], [boolean callLogging='true'])
Prepares an already instantiated object to act as a mock for spying and much more

Parameters:
object - The object to mock, already instantiated
callLogging - Add method call logging for all mocked methods. Defaults to true

print

public any print(any message)
Write some output to the ColdFusion output buffer

Parameters:
message

println

public any println(any message)
Write some output to the ColdFusion output buffer using a
attached

Parameters:
message

querySim

public any querySim(any queryData)
First line are the query columns separated by commas. Then do a consecuent rows separated by line breaks separated by | to denote columns.

Parameters:
queryData

runRemote

remote any runRemote([string testSpecs=''], [string testSuites=''], [boolean debug='false'], [string reporter='simple'])
Run a test remotely, only useful if the spec inherits from this class. Useful for remote executions.

Parameters:
testSpecs - A list or array of test names that are the ones that will be executed ONLY!
testSuites - A list or array of suite names that are the ones that will be executed ONLY!
debug - Show debug output on the reports or not
reporter - The type of reporter to run the test with

runSpec

public any runSpec(any spec, any suite, any testResults, any suiteStats, any runner)
Run a BDD test in this target CFC

Parameters:
spec - The spec definition to test
suite - The suite definition this spec belongs to
testResults - The testing results object
suiteStats - The suite stats that the incoming spec definition belongs to
runner - The runner calling this BDD test

runTestMethod

public any runTestMethod(any spec, any testResults, any suiteStats, any runner)
Runs a xUnit style test method in this target CFC

Parameters:
spec - The spec definition to test
testResults - The testing results object
suiteStats - The suite stats that the incoming spec definition belongs to
runner - The runner calling this BDD test

xdescribe

public any xdescribe(string title, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'])
This is a convenience method that makes sure the test suite is skipped from execution

Parameters:
title - The name of this test suite
body - The closure that represents the test suite
labels - The list or array of labels this suite group belongs to
asyncAll - If you want to parallelize the execution of the defined specs in this suite group.

xit

public any xit(string title, any body, [any labels='[runtime expression]'])
This is a convenience method that makes sure the test spec is skipped from execution

Parameters:
title - The title of this spec
body - The closure that represents the test
labels - The list or array of labels this spec belongs to

ColdBox Platform v3.8.0