[coldbox:23309] Re: [coldbox 4.0][testbox 2.0] tests fail as part of suite, but pass individually

I’m on my phone so I can’t see the code very well, but are you calling reset() Behr each event to reset the request context? Also, are you using an async runner?

What debugging have you done to troubleshoot the values coming back and what’s wrong with them?

Sent on the new Sprint Network from my Samsung Galaxy S®4.

No, I’m not calling reset() before each event.

But I tried it and didn’t change the results. I don’t see this in the docs. I’m guessing it goes in a beforeEach().

`

function run(){
describe( title=“Project Search, searchHandler”, body=function(){

beforeEach(function(){
reset();
});

it( “should list atleast 1 project by geolocation(santa ana office)”, function(){
url.lat = 33.6948545;
url.lng = -117.8604357;
var event = execute( event=“project:searchHandler.searchByLatLng”);
// debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});

`

No, I’m not using async.

As far as debugging it within the testing framework, I don’t know. Outside of that everything is as expected.

Ok, I did find out that the url parameters that are set in another spec from the other bundle are being passed in to this spec.

Here is spec 6 from bundle 1:

`
component extends=“coldbox.system.testing.BaseTestCase” {

// executes before all suites+specs in the run() method
function beforeAll(){
// do your own stuff here
// super.setup();

super.beforeAll();
}

// executes after all suites+specs in the run() method
function afterAll(){
super.beforeAll();
// do your own stuff here
}

function run(){
describe( title=“Project, projectHandler”, body=function(){

beforeEach(function(){
reset();
});

it( “should list a max of 100 most recently created projects”, function(){
var event = execute( event=“project:projectHandler.index”);
expect( Arraylen(getRequestContext().getRenderData().DATA.data) ).toBeBetween(1,100);
});
it( “should list 13 most recently created projects”, function(){
url.max = 13;
var event = execute( event=“project:projectHandler.index”);
// debug( getRequestContext().getRenderData() );
expect( Arraylen(getRequestContext().getRenderData().DATA.data) ).toBe(13);
});
it( “should list atleast 1 project by geolocation(santa ana office)”, function(){
url.lat = 33.6948545;
url.lng = -117.8604357;
var event = execute( event=“project:searchHandler.searchByLatLng”);
// debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});
it( “should list all tasks for a given project”, function(){
url.wbs1 = “4CAL060700”;
var event = execute( event=“project:projectHandler.getAllTasks”);
// debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data) ).toBeGTE(1);
});
it( “should get 1 task 4CAL060700 00001”, function(){
url.wbs1 = “4CAL060700”;
url.wbs2 = “00001”;
var event = execute( event=“project:projectHandler.view”);
debug( getRequestContext().getRenderData() );
expect( getRequestContext().getRenderData().DATA.data[1].WBS1 ).toBe(“4CAL060700”);
});
it( “should get 1 task 4CAL060700 00001 with full details”, function(){
url.wbs1 = “4CAL060700”;
url.wbs2 = “00002”;
var event = execute( event=“project:projectHandler.getFullDetails”);
debug( getRequestContext().getRenderData() );
expect( getRequestContext().getRenderData().DATA.data[1].WBS1 ).toBe(“4CAL060700”);
});
});
}

}
`

Here are the specs from bundle 2, specs 2 and 3 are getting the URL params from spec 6 above:

`
component extends=“coldbox.system.testing.BaseTestCase” {

// executes before all suites+specs in the run() method
function beforeAll(){
// do your own stuff here
// super.setup();

super.beforeAll();
}

// executes after all suites+specs in the run() method
function afterAll(){
super.beforeAll();
// do your own stuff here
}

function run(){
describe( title=“Project Search, searchHandler”, body=function(){

beforeEach(function(){
reset();
});

it( “should list atleast 1 project by geolocation(santa ana office)”, function(){
url.lat = 33.6948545;
url.lng = -117.8604357;
var event = execute( event=“project:searchHandler.searchByLatLng”);
// debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});
it( “should find projects whose project name starts with Riverside”, function(){
url.projecttname = “Riverside”;
url.projectnamelike = 1;
var event = execute( event=“project:searchHandler.searchProjects”);
debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});
it( “should find projects whose project name ends with Riverside with full details”, function(){
url.projecttname = “Riverside”;
url.projectnamelike = 3;
var event = execute( event=“project:searchHandler.searchProjectsFullDetails”);
debug( getRequestContext().getRenderData() );
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});

});
}

}
`

In addition to calling reset, you may also need to clear out any persistent scopes that you’ve modified between tests. Ideally you wouldn’t touch things like FORM or URL for this very reason. Your code should touch URL either-- everything should come from rc so you can cleanly mock the request, and then ‘reset()’ the entire thing.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad,

How do I clear RC before every spec. The URL parameters from each spec are being appended to the scope so by the time my last spec runs the RC contains more than 10 variables which cause my query to select different data.

I tried getRequestContext().clearCollection(private=false); in the beforeEach method but doesn’t work.

I believe the reset() method takes care of that. I was suggesting you manually clear the URL scope (with structclear()) or, better yet, not use URL directly at all.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

structClear(url) results in this error:

Element PROPERTIESSUMMARY is undefined in URL.

reset() is not doing it either, but looks like it should:

coldbox.system.testing.BaseTestCase

function reset( boolean clearMethods=false, decorator ){
structDelete( application, getColdboxAppKey() );
structClear( request );
return this;
}

And I have to use URL since its the only way to mock url patterns from my routes(atleast from what I know).

Looks like you’re using the default runner template which uses URL variables. Try just removing the specific items you add.

Still, this could be a red herring. The only real way to know why your test is failing is to put in some debugging to see why it’s not returning what you expect.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad,

Ok I replaced URL with getRequestContext().setValue() and now ALL MY TESTS PASSED. I also confirmed that reset() was doing what its suppose to do.

it( "should list atleast 1 project by geolocation(santa ana office)", function(){ getRequestContext().setValue("lat",33.6948545); getRequestContext().setValue("lng",-117.8604357); var event = execute( event="project:searchHandler.searchByLatLng"); // debug( getRequestContext().getRenderData() ); expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1); });

Does spec test look good? Do you see anything you would do differently?

is there a bug in reset()? which reset URL structure too.

typo****

reset() should reset URL structure/scope too, right?

No, the reset method is just there to reset the ColdBox request context. You shouldn’t be using the URl scope in your tests, and if you do, it’s up to you to “reset” it. What you have now looks fine. I’ll let Luis chime in if there’s any other pointers he has.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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