Muki-SkyWalker / specs

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

Nested specs cause duplicate execution #172

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Multiple levels of nesting cause some tests to be executed twice.  This causes 
problems for tests with side effects.  See the attached file.

Expected output:
1
2
3

Actual output:
1
2
3
2
3
2
3

This seems to happen starting with 1.6.6.

Original issue reported on code.google.com by dloftesn...@gmail.com on 19 Jan 2011 at 11:20

Attachments:

GoogleCodeExporter commented 9 years ago
Eric, this particular issue was problematic in that our mock expectations were 
failing because things were run multiple times. We ended up rolling back to 
1.6.5 and things were fine. Hopefully you can add our example to your 
regression tests. Use mocks and check that things were only called once or 
twice.

class Foo {
  def bar(i: Int) = i
  def baz(s: String) = s
}

val foo = mock[Foo]

foo.bar(1)
foo.baz("1")

got {
    one(foo).bar(1)
    one(foo).baz("1")
}

Original comment by ste...@gmail.com on 20 Jan 2011 at 12:13

GoogleCodeExporter commented 9 years ago
I still don't know what's causing this, but I have a small idea.

Based on that idea, you can try the following workaround:

class TestSpec extends Specification {
  "A test specification" should {
    "be able to support nested examples" in {
      "as seen here" in {
        this mustNot beNull
        println("1")
      }
      "as seen here also" in {
        "other tests" in {
          this mustNot beNull
          println("2")
        }
        "and some more" in {
          println("3")
          this mustNot beNull
        }
      }
      // add one last "simple" (not nested) example here
      "as seen here" in {
        this mustNot beNull
        println("4")
      }
    }
  }
}

Original comment by etorrebo...@gmail.com on 20 Jan 2011 at 4:10

GoogleCodeExporter commented 9 years ago
Eric, we're not going to rewrite thousands of lines of tests. Instead, we're 
staying on 1.6.5 until this is fixed.

I'll get you a regression test that fails in 1.6.6.

Thanks. :-)

Original comment by ste...@gmail.com on 20 Jan 2011 at 6:04

GoogleCodeExporter commented 9 years ago
>> Eric, we're not going to rewrite thousands of lines of tests

Yes indeed :-).

I think this issue is fixed now in the latest SNAPSHOT (1.6.8-SNAPSHOT).

For the following specification:

import org.specs._

class TestSpec extends Specification {
  "A test specification" should {
  doFirst(println("first"))
  doLast(println("last"))
  doBefore(println("before"))
  doAfter(println("after"))
    "be able to support nested examples" in {
      "as seen here" in {
        this mustNot beNull
        println("1")
      }
      "as seen here also" in {
        "other tests" in {
          this mustNot beNull
          println("2")
        }
        "and some more" in {
          println("3")
          this mustNot beNull
        }
      }
    }
  }
}

The output is:

first
before
1
after
before
2
after
before
3
after
last

Thanks for confirming the fix.

Original comment by etorrebo...@gmail.com on 22 Jan 2011 at 6:00