[testbox-2.0.0] BDD procedural question

I’ve got a CFC that is a proxy for a 3rd party API. Each of the methods takes some arguments, creates an XML file and sends it off to the SOAP endpoint, does some processing and returns a native ColdFusion structure of data.

In setting up my test suites and specs, I need to run several different tests against the result of method of the CFC under test. Right now, I have the call to the CFC under test in the beforeEach() which means that every spec fires off a call to the 3rd party API.

My question is, what is the preferred method to make one call to the method in the CFC under test, then run several several test specs against the one return value from the result of that one call to the method? I tried putting the call to the CFC under test right inside the describe() block but TestBox told me it couldn’t find my component under test.

Thanks
Dan

Dan, can you use the beforeAll() method? I’d need to see your test component to understand the error you mentioned, but if you are creating the test CFC in a separate method, you will need to put it in the variables scope inside your spec so it can be accessed in other methods.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Sorry Brad…I started to reply to this and got pulled away for several hours.

I’ve created a Gist with a sanitized version of my test suite here: BDD Test Suite Question · GitHub

Basically, in test suites for method1() I’d like to have the result of theObject.method1() only retrieved once and then all of the it() methods in that suite would use the same result to test against. Right now the way it is, theObject.method1() is run before every it() method (if I understand correctly what it’s doing).

Please let me know if I’m off base with this.

Thanks
Dan

At first glance, I would expect you to be able to move the actual method call out into the body of the “describe” method. It should have access to the object as long as the object is in the variables scope.

What version of Adobe CF/Railo are you using?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Railo 4.2.1.000 final (as launched by CommandBox YEAH!).

I moved the call to the component under test to be right inside the describe() block for each method’s suite of specs.

That produced a Railo exception: Component [_tests.path.to.ObjectTest] has no accessible Member with name [THEOBJECT]

Can you paste that new describe block in here so I can see it? And +1 for using CommandBox :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Here ya go:


//test suite for the method1() method
describe( 'The method1() function...', function(){
	result = theObject.method1( argumentCollection={});  

	// before each spec in this suite group
	beforeEach( function(){

	});
 
	// after each spec in this suite group
	afterEach( function(){
				
	});

	it( '... returns a structure of values', function( result ){

		expect( result ).toBeStruct();
	});
 
	it( '... returns no errors', function( result ){
		expect( result.errors ).notToBeStruct();
	});
			
	it( '... returns a sucessful status', function( result ){
		expect( result.status ).toBe( 1 );
	});
 
});

Hmm, I wonder if that’s a Railo bug. Also, in the message “Component [tests.path.to.ObjectTest] has no accessible Member with name [THEOBJECT]" I would have expected that to be "… Member with name [method1]_”

What if you dump/abort theObject there in the code and see if it is what you expect?

If I get a chance later, I’ll test it myself.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com