TestBox 2.4.0

testbox.system
Class BaseSpec

railo-context.Component
        extended by testbox.system.BaseSpec
Direct Known Subclasses:
Assertionscf9Test , BDDInheritanceTest , BDDLifecycleTest , BDDTest , CustomAssertions , DebugTests , EdgeCases , GivenWhenThenTest , LabelsTest , NestedAroundEachTest , NestedDescribeTest , SpecDataTests , ThreadCollisions , MockBoxTest , TeardownWithFailureBDD , ExampleParentTestCase , TestCase , BDDTest

public class BaseSpec
extends railo-context.Component

Copyright Since 2005 TestBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com --- This is a base spec object that is used to test XUnit and BDD style specification methods


Constructor Summary
remote init()
          Constructor
 
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 aroundEach(any body)
          This is used to surround a spec with your own closure code to provide a nice around decoration advice
 any aroundStub([any spec])
 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], [string label=''], [boolean deepCopy='false'], [numeric top='999'])
          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
 any feature(string feature, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
 any generateAroundEachClosuresStack([array closures], any suite, any spec)
          Generates a specs stack for executions
 array getDebugBuffer()
          Get the debug array buffer from scope
 any getMockBox([string generationPath])
          Get a reference to the MockBox engine
 any getProperty(any target, any name, [any scope='variables'], [any defaultValue])
          Get a private property
 any given(string given, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
 boolean hasExpectedException(any specName, any runner)
          Check if an expected exception is defined
 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'], [struct data='[runtime expression]'])
          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
 BaseSpec runAfterEachClosures(any suite, any spec)
          Execute the after each closures in order for a suite and spec
 BaseSpec runAroundEachClosures(any suite, any spec)
          Execute the around each closures in order for a suite and spec
 BaseSpec runBeforeEachClosures(any suite, any spec)
          Execute the before each closures in order for a suite and spec
remote any runRemote([string testSpecs=''], [string testSuites=''], [string reporter='simple'], [string labels=''])
          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 scenario(string scenario, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
private any sliceTagContext(any tagContext)
          removes the TestBox tag contexts from the beginning of the Failure Origin
 any story(string story, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
 any then(string then, any body, [any labels='[runtime expression]'], [any skip='false'], [struct data='[runtime expression]'])
          The then() function describes a spec or a test in TestBox and is an alias for it
 any when(string when, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
          The way to describe BDD test suites in TestBox
 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]'], [struct data='[runtime expression]'])
          This is a convenience method that makes sure the test spec is skipped from execution
 
Methods inherited from class railo-context.Component
 

Constructor Detail

init

remote init()
Constructor

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

aroundEach

public any aroundEach(any body)
This is used to surround a spec with your own closure code to provide a nice around decoration advice

Parameters:
body - The closure function

aroundStub

public any aroundStub([any spec])

Parameters:
spec

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], [string label=''], [boolean deepCopy='false'], [numeric top='999'])
Debug some information into the TestBox debugger array buffer

Parameters:
var - The data to debug
label - The label to add to the debug entry
deepCopy - By default we do not duplicate the incoming information, but you can :)
top - The top numeric number to dump on the screen in the report, defaults to 999

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

feature

public any feature(string feature, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The feature is an alias for describe usually use when you are writing in a Given-When-Then style The body is the function that implements the suite.

Parameters:
feature - 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.

generateAroundEachClosuresStack

public any generateAroundEachClosuresStack([array closures], any suite, any spec)
Generates a specs stack for executions

Parameters:
closures - The array of closures data to build
suite - The target suite
spec - The target spec

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.

getProperty

public any getProperty(any target, any name, [any scope='variables'], [any defaultValue])
Get a private property

Parameters:
target - The target to get a property from
name - The name of the property to retrieve
scope - The scope to get it from, defaults to 'variables' scope
defaultValue - A default value if the property does not exist

given

public any given(string given, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The given is an alias for describe usually use when you are writing in a Given-When-Then style The body is the function that implements the suite.

Parameters:
given
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.

hasExpectedException

public boolean hasExpectedException(any specName, any runner)
Check if an expected exception is defined

Parameters:
specName
runner

isExpectedException

public 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'], [struct data='[runtime expression]'])
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.
data - A struct of data you would like to bind into the spec so it can be later passed into the executing body function

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

runAfterEachClosures

public BaseSpec runAfterEachClosures(any suite, any spec)
Execute the after each closures in order for a suite and spec

Parameters:
suite - The suite definition
spec - The spec definition

runAroundEachClosures

public BaseSpec runAroundEachClosures(any suite, any spec)
Execute the around each closures in order for a suite and spec

Parameters:
suite - The suite definition
spec - The spec definition

runBeforeEachClosures

public BaseSpec runBeforeEachClosures(any suite, any spec)
Execute the before each closures in order for a suite and spec

Parameters:
suite - The suite definition
spec - The spec definition

runRemote

remote any runRemote([string testSpecs=''], [string testSuites=''], [string reporter='simple'], [string labels=''])
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!
reporter - The type of reporter to run the test with
labels - A list or array of labels to apply to the testing.

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

scenario

public any scenario(string scenario, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The scenario is an alias for describe usually use when you are writing in a Given-When-Then style The body is the function that implements the suite.

Parameters:
scenario
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.

sliceTagContext

private any sliceTagContext(any tagContext)
removes the TestBox tag contexts from the beginning of the Failure Origin

Parameters:
tagContext - The tag context

story

public any story(string story, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The story is an alias for describe usually use when you are writing using Gherkin-esque language The body is the function that implements the suite.

Parameters:
story - 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.

then

public any then(string then, any body, [any labels='[runtime expression]'], [any skip='false'], [struct data='[runtime expression]'])
The then() function describes a spec or a test in TestBox and is an alias for it. 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:
then - 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.
data - A struct of data you would like to bind into the spec so it can be later passed into the executing body function

when

public any when(string when, any body, [any labels='[runtime expression]'], [boolean asyncAll='false'], [any skip='false'])
The way to describe BDD test suites in TestBox. The when is an alias for scenario usually use when you are writing in a Given-When-Then style The body is the function that implements the suite.

Parameters:
when
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.

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]'], [struct data='[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
data - A struct of data you would like to bind into the spec so it can be later passed into the executing body function

TestBox 2.4.0