Muki-SkyWalker / specs

Automatically exported from code.google.com/p/specs
Other
0 stars 0 forks source link

matching in doBeforeSpec throws PathException #103

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When matching in doBeforeSpec more than once, a PathException will be thrown.

For example following spec:

object DoBeforeSpecMatchingIntegrationSpecs extends Specification{
  doBeforeSpec {1 mustBe 1; 1 mustBe 1}
  "Foo" should{
    "bar" in{
      1 mustBe 1
    }
  }
}

fails with:

org.specs.specification.PathException: TreePath(List(0, 1, 1))not found for
example 2

Original issue reported on code.google.com by saynomoo@gmail.com on 23 Dec 2009 at 1:13

GoogleCodeExporter commented 9 years ago
The affected version is: 1.6.2.SNAPSHOT, from 2009.12.19

Original comment by saynomoo@gmail.com on 23 Dec 2009 at 1:16

GoogleCodeExporter commented 9 years ago
Can I ask 2 questions to help me understand the context and the possible 
solution?

- What are you trying to achieve with those 2 expectations? That your spec 
setup was 
correct? At the moment, in specs, any expectation (1 mustBe 1) has to be 
related to 
an example. So there are 2 anonymous examples being created for each of your 
expectations in the doBeforeSpec. And I guess that their execution doesn't go 
well 
due to their unusual location.

- Did you had this error on earlier versions? If not, that may be related to my 
fix 
for issue 102

Thx.

Original comment by etorrebo...@gmail.com on 23 Dec 2009 at 7:31

GoogleCodeExporter commented 9 years ago
The expectations in the setup verify that our integration specs environment was 
setup
correctly. For some specs the setup is done per example, for some only once in a
specification. As a workaround, I guess we could wrap the examples with one 
extra
example. Then the setup would be related to the (artificial) top example.

I think the problem did not exist in version 1.5.0, but I'm not 100% sure. I can
confirm that after the holidays.

Original comment by saynomoo@gmail.com on 23 Dec 2009 at 10:36

GoogleCodeExporter commented 9 years ago
You may see a commit saying that the issue is fixed. Unfortunately I did 
further 
testing and there are still issues when the spec has 2 sus. So I need more work 
on it 
(which may be delayed by Xmas). Sorry for that,... but Merry Christmas!

Original comment by etorrebo...@gmail.com on 24 Dec 2009 at 3:10

GoogleCodeExporter commented 9 years ago
I tried a better fix. You should find it in the next snapshot when it's 
deployed.

Original comment by etorrebo...@gmail.com on 24 Dec 2009 at 2:31

GoogleCodeExporter commented 9 years ago
The doBeforeSpec seems to work now correctly. There is still one problem, 
though.

When running doFirst in a suite, a similar error occurs. For example here the
FailingSuite fails:

object FailingSuite extends SpecsFileRunner("**/*.scala",
"DoBeforeSpecMatchingIntegrationSpecs")
object DoBeforeSpecMatchingIntegrationSpecs extends Specification{
  "Foo" should{
    doFirst {1 mustBe 1; 1 mustBe 1}
    "bar" in{
      1 mustBe 1
    }
  }
}

causing: 
Exception in thread "main" org.specs.specification.PathException: 
TreePath(List(0, 1,
1))not found for example 2

Original comment by saynomoo@gmail.com on 28 Dec 2009 at 12:44

GoogleCodeExporter commented 9 years ago
Yes, my fault. I'm going to extend the fix I did to beforeSpec and hopefully 
that 
should work ok for your spec.

Original comment by etorrebo...@gmail.com on 29 Dec 2009 at 7:33

GoogleCodeExporter commented 9 years ago
Yesterday's snapshot fixes the last of our problems related to the 
PathException. Thanks!

Original comment by saynomoo@gmail.com on 31 Dec 2009 at 8:13

GoogleCodeExporter commented 9 years ago
Great. Happy New Year!

Original comment by etorrebo...@gmail.com on 31 Dec 2009 at 10:59

GoogleCodeExporter commented 9 years ago
I still see this bug on 1.6.2.2, but it may be a different use case. I am using 
Liftweb and this is the smallest spec that reproduces the bug:

package code {
package snippet {

import org.specs._
import org.specs.runner.JUnit3
import org.specs.runner.ConsoleRunner
import net.liftweb._
import http._
import net.liftweb.util._
import net.liftweb.common._
import org.specs.matcher._
import org.specs.specification._
import Helpers._
import lib._

class SideBarTestSpecsAsTest extends JUnit3(SideBarTestSpecs)
object SideBarTestSpecsRunner extends ConsoleRunner(SideBarTestSpecs)

object SideBarTestSpecs extends Specification {

  val session = new LiftSession("", randomString(20), Empty)

// Comment this this override and the bug does not happen

  override def executeExpectations(ex: Examples, t: =>Any): Any = {
    S.initIfUninitted(session) {
      super.executeExpectations(ex, t)
    }
  }

  "this " should {
    "pass" in {
      1 mustEqual 1
    }

    "fail" in {
      2 mustEqual 2
    }

  }

}

}
}

If you have just one  "in" clause, you do not get the error.

"Could not run test code.snippet.SideBarTestSpecs: 
org.specs.specification.PathException: TreePath(List(0, 0, 1))not found for 
fail"

I am running the test under sbt if it makes ay difference.

Thanks

Original comment by di...@fmpwizard.com on 11 Nov 2010 at 2:54

GoogleCodeExporter commented 9 years ago
Can you please try to use a SpecificationContext with aroundExpectations: 

http://code.google.com/p/specs/wiki/DeclareSpecifications#Specification_context

Thanks.

Original comment by etorrebo...@gmail.com on 11 Nov 2010 at 9:06

GoogleCodeExporter commented 9 years ago
Also see 
http://www.assembla.com/wiki/print/liftweb/Unit_Testing_Snippets_With_A_Logged_I
n_User

Original comment by aa...@updtr.com on 2 Jan 2011 at 9:56

GoogleCodeExporter commented 9 years ago

Original comment by etorrebo...@gmail.com on 31 Mar 2011 at 8:05