Skip to content

Commit

Permalink
TESTBOX-394 #resolve
Browse files Browse the repository at this point in the history
new `test(), xtest(), ftest()` alias for more natuarl testing
  • Loading branch information
lmajano committed Sep 7, 2024
1 parent f1e4bf4 commit f3c8064
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
72 changes: 69 additions & 3 deletions system/BaseSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
component {

// Param default URL method runner.
// Param default URL method runner when it runs remotely
param name="url.method" default="runRemote";

// Assertions object
Expand Down Expand Up @@ -551,6 +551,48 @@ component {
return this;
}

/**
* An alias to the it() function to provide a more natural language for BDD.
*
* @title The title of this test
* @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
* @focused A flag that tells TestBox to only run this spec and no other
*/
any function test(
required string title,
required any body,
any labels = [],
any skip = false,
struct data = {},
boolean focused = false
){
return this.it( argumentCollection = arguments );
}

/**
* A focused alias to the fit() function to provide a more natural language for BDD.
*
* @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
* @focused A flag that tells TestBox to only run this spec and no other
*/
any function ftest(
required string title,
required any body,
any labels = [],
any skip = false,
struct data = {},
boolean focused = false
){
return this.fit( argumentCollection = arguments );
}

/**
* 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.
Expand All @@ -560,13 +602,15 @@ component {
* @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
* @focused A flag that tells TestBox to only run this spec and no other
*/
any function then(
required string then,
required any body,
any labels = [],
any skip = false,
struct data = {}
struct data = {},
boolean focused = false
){
return it( argumentCollection = arguments, title = "Then " & arguments.then );
}
Expand All @@ -579,13 +623,15 @@ component {
* @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
* @focused A flag that tells TestBox to only run this spec and no other
*/
any function fthen(
required string then,
required any body,
any labels = [],
any skip = false,
struct data = {}
struct data = {},
boolean focused = false
){
return fit( argumentCollection = arguments, title = "Then " & arguments.then );
}
Expand Down Expand Up @@ -744,6 +790,26 @@ component {
return this.then( argumentCollection = arguments );
}

/**
* This is a convenience method that makes sure the test spec is skipped from execution
*
* @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
* @focused A flag that tells TestBox to only run this spec and no other
*/
any function xtest(
required string title,
required any body,
any labels = [],
struct data = {},
boolean focused = false
){
arguments.skip = true;
return this.test( argumentCollection = arguments );
}

/**
* Start an expectation expression. This returns an instance of Expectation so you can work with its matchers.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/BDDTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,16 @@ component extends="testbox.system.BaseSpec" {
structDelete( variables, "calc" );
} );

it( "Can have a separate beforeEach for this suite", function(){
test( "Can have a separate beforeEach for this suite", function(){
expect( request.calc ).toBeComponent();
} );

xit( "can add incorrectly and fail", function(){
xtest( "can add incorrectly and fail (Skipped)", function(){
var r = calc.add( 2, 2 );
expect( r ).toBe( 5 );
} );

it( "cannot divide by zero", function(){
test( "cannot divide by zero", function(){
expect( function(){
request.calc.divide( 4, 0 );
} ).toThrow( regex = "zero" );
Expand Down

0 comments on commit f3c8064

Please sign in to comment.