Setup for Specs suite - org.specs.specification.PathException

35 views
Skip to first unread message

Gregg Carrier

unread,
Mar 7, 2011, 12:29:32 PM3/7/11
to specs-users
I have a suite of specs that run functional tests against a database-
backed web service. I need to do some setup work - namely clearing out
the database - exactly one time before the entire test suite runs.

Initially I had all of my examples in one file, but that was starting
to get extremely unwieldy. Now if I do the setup in each of my
separate Specs classes, there's a race condition to delete the
database rows.

My most recent approach has been to write a Context that looks like
this:
object ProjectSpecContext extends Specification {
val setup = new SpecContext {
beforeSpec(doDeleteAll)
}
}

Then in each of my Specs classes, I added a line like:
ProjectSpecContext.setup(this)

Is this the correct approach?

I am actually OK with each Spec class running sequentially after the
setup, though ideally, they would be able to run in parallel after the
setup task is run exactly once. Right now they are running in
parallel, and many of my examples run successfully. However, a great
many specs throw the following exception:

org.specs.runner.UserError: org.specs.specification.PathException:
TreePath(List(0, 1, 1))not found for example 2
at org.specs.specification.SpecificationExecutor
$class.executeExample(SpecificationExecutor.scala:52)
at
org.specs.specification.BaseSpecification.executeExample(BaseSpecification.scala:
58)
at
org.specs.specification.BaseSpecification.executeExample(BaseSpecification.scala:
58)
at org.specs.specification.ExampleLifeCycle$$anonfun
$executeExample$1.apply(ExampleLifeCycle.scala:117)
at org.specs.specification.ExampleLifeCycle$$anonfun
$executeExample$1.apply(ExampleLifeCycle.scala:117)
at scala.Option.map(Option.scala:74)


Any help on what this exception means or general advice on how to
accomplish what I am trying to would be greatly appreciated. Thanks!

Gregg

etorreborre

unread,
Mar 7, 2011, 4:06:26 PM3/7/11
to specs-users
Yes Gregg you did the right thing and there's a bug somewhere.

However I'm wondering if the easiest thing in your case is to have a
static object somewhere do the setup once and for all for all suites:

object Database {
var isSet = false
// this might require some synchronisation if the execution
// is truly concurrent among specifications
def setup = if (!isSet) {
// do your cleanup
isSet = true
}
}

and in each spec you just write:

class MySpec extends Specification {
Database.setup
// rest of the spec
}

Do you think that would work?

Eric.

Gregg Carrier

unread,
Mar 7, 2011, 6:04:31 PM3/7/11
to specs...@googlegroups.com
Hi Eric -

Thanks - yes that may well work for my case. I'll give it a try.

Is there a straightforward way to control the ordering of Specs? I am running mine as JUnit tests in a Maven/Surefire environment. I have setSequential in my Spec classes, so the examples are run in order within a certain Spec. But I would just like to specify the order of the Spec classes themselves. Can I create a parent Spec that defines the order of its children or something along those lines?

Thanks again. I really do enjoy using the framework. Cheers!

Gregg

--
You received this message because you are subscribed to the Google Groups "specs-users" group.
To post to this group, send email to specs...@googlegroups.com.
To unsubscribe from this group, send email to specs-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/specs-users?hl=en.


etorreborre

unread,
Mar 7, 2011, 6:29:42 PM3/7/11
to specs-users
> Can I create a parent Spec that defines the order of its children or something along those lines?

Yes I was thinking you could do this but I forgot to write it
down :-).

Gregg Carrier

unread,
Mar 8, 2011, 11:24:32 AM3/8/11
to specs...@googlegroups.com
Can you point me to an example of how to set this sort of thing up? Thanks!

Gregg

Gregg Carrier

unread,
Mar 8, 2011, 12:39:26 PM3/8/11
to specs...@googlegroups.com
Never mind - found it - RTFM, Gregg ;)

In case it helps someone else...

From the manual:
object bigSpec extends Specification {
 
"this big specification".isSpecifiedBy(
                  basicFunctionalitiesSpec
,
                  advancedFunctionalitiesSpec
,
                  extensionsSpec
)
}
Reply all
Reply to author
Forward
0 new messages