Muki-SkyWalker / specs

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

Specification with generated Examples does not execute correctly using JUnitRunner #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
object TransSpec extends Specification with TransactionalSpecification {

  "a spec" should {
    //"dummy 1" in { 0 must_== 0 }
    "test transaction" in {
      withTransaction {
        trans => println("Doing the action")
      } afterCommit {
        changes => changes must contain("Commit")
      } afterUndo {
        changes => changes must contain("Undo")
      } afterRedo {
        changes =>  changes must contain("Redo")
      }
    }
    //"dummy 2" in { 0 must_== 0 }
  }
  "a spec 2 " should {
    "another test" in {
      0 must_== 0
    }
  }
}

Now for the oddity test on (1.6.2 and 1.6.2.2-SNAPSHOP) running the
TransTest (under IDEA 9.0.1) the following happens:

1) As is: "a spec 2" is run but "a spec" produces no tests

2) Commenting out "a spec 2" it works fine

3) Un-commenting "dummy 1" the specification gets executed, however the GUI
does show a test as pending.

4) Un-commenting "dummy 1" and "dummy 2" the specification gets executed
perfectly.

5) Using sharedVariables() makes the specification work correctly.

----  Code (self contained example) ---
package Acting

import org.specs.Specification
import org.junit.runner.RunWith
import org.specs.runner.{JUnit4, JUnitSuiteRunner}

@RunWith(classOf[JUnitSuiteRunner])
class TransTest extends JUnit4(TransSpec)

class Transaction {
  def commit() { println("Commiting")}
  def undo() { println("Undoing")}
  def redo() { println("Redoing")}
}

trait TransactionalSpecification {
  self: Specification =>

  class AfterCommit(action: Transaction => Any) {
    def afterCommit(after: Seq[Any] => Any) = {
      "commit" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        after(Seq("Commit"))
      }
      new AfterUndo(action, after)
    }
  }

  class AfterUndo(action: Transaction => Any, commitExample: Seq[Any] => Any) {
    def afterUndo(after: Seq[Any] => Any) = {
      "undo" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        after(Seq("Undo"))
      }
      new AfterRedo(action, commitExample)
    }
  }

  class AfterRedo(action: Transaction => Any, commitExample: Seq[Any] => Any) {
    def afterRedo(after: Seq[Any] => Any) = {
      "redo" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        trans.redo()
        after(Seq("Redo"))
      }
    }

    def afterRedoAsInCommit() = {
      "redo as in commit" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        trans.redo()
        commitExample(Seq("Commit","Redo"))
      }
    }
  }

  def withTransaction(action: Transaction => Any) = {
    new AfterCommit(action)
  }

  def runAndCommit(action: Transaction => Any) = {
    val trans = new Transaction()
    action(trans)
    trans.commit()
  }
}
object TransSpec extends Specification with TransactionalSpecification {

  "a spec" should {
    //"dummy" in { 0 must_== 0 }
    "test transaction" in {
      withTransaction {
        trans => println("Doing the action")
      } afterCommit {
        changes =>
         changes must contain("Commit")
      } afterUndo {
        changes =>
         changes must contain("Undo")
      } afterRedo {
        changes =>
         changes must contain("Redo")
      }
    }
  }
  "a spec 2 " should {
    "another test" in {
      0 must_== 0
    }
  }
}object TransSpec extends Specification with TransactionalSpecification {

  "a spec" should {
    //"dummy 1" in { 0 must_== 0 }
    "test transaction" in {
      withTransaction {
        trans => println("Doing the action")
      } afterCommit {
        changes => changes must contain("Commit")
      } afterUndo {
        changes => changes must contain("Undo")
      } afterRedo {
        changes =>  changes must contain("Redo")
      }
    }
    //"dummy 2" in { 0 must_== 0 }
  }
  "a spec 2 " should {
    "another test" in {
      0 must_== 0
    }
  }
}

Now for the oddity test on (1.6.2 and 1.6.2.2-SNAPSHOP) running the
TransTest (under IDEA 9.0.1) the following happens:

1) As is: "a spec 2" is run but "a spec" produces no tests

2) Commenting out "a spec 2" it works fine

3) Un-commenting "dummy 1" the specification gets executed, however the GUI
does show a test as pending.

4) Un-commenting "dummy 1" and "dummy 2" the specification gets executed
perfectly.

What am I missing?

Thomas

----  Code ---
package Acting

import org.specs.Specification
import org.junit.runner.RunWith
import org.specs.runner.{JUnit4, JUnitSuiteRunner}

@RunWith(classOf[JUnitSuiteRunner])
class TransTest extends JUnit4(TransSpec)

class Transaction {
  def commit() { println("Commiting")}
  def undo() { println("Undoing")}
  def redo() { println("Redoing")}
}

trait TransactionalSpecification {
  self: Specification =>

  class AfterCommit(action: Transaction => Any) {
    def afterCommit(after: Seq[Any] => Any) = {
      "commit" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        after(Seq("Commit"))
      }
      new AfterUndo(action, after)
    }
  }

  class AfterUndo(action: Transaction => Any, commitExample: Seq[Any] => Any) {
    def afterUndo(after: Seq[Any] => Any) = {
      "undo" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        after(Seq("Undo"))
      }
      new AfterRedo(action, commitExample)
    }
  }

  class AfterRedo(action: Transaction => Any, commitExample: Seq[Any] => Any) {
    def afterRedo(after: Seq[Any] => Any) = {
      "redo" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        trans.redo()
        after(Seq("Redo"))
      }
    }

    def afterRedoAsInCommit() = {
      "redo as in commit" in {
        val trans = new Transaction()
        action(trans)
        trans.commit()
        trans.undo()
        trans.redo()
        commitExample(Seq("Commit","Redo"))
      }
    }
  }

  def withTransaction(action: Transaction => Any) = {
    new AfterCommit(action)
  }

  def runAndCommit(action: Transaction => Any) = {
    val trans = new Transaction()
    action(trans)
    trans.commit()
  }
}
object TransSpec extends Specification with TransactionalSpecification {

  "a spec" should {
    //"dummy" in { 0 must_== 0 }
    "test transaction" in {
      withTransaction {
        trans => println("Doing the action")
      } afterCommit {
        changes =>
         changes must contain("Commit")
      } afterUndo {
        changes =>
         changes must contain("Undo")
      } afterRedo {
        changes =>
         changes must contain("Redo")
      }
    }
  }
  "a spec 2 " should {
    "another test" in {
      0 must_== 0
    }
  }
}

Original issue reported on code.google.com by maill...@gmail.com on 15 Apr 2010 at 3:00

GoogleCodeExporter commented 9 years ago
I can't reproduce the issue with 1.6.2.2-SNAPSHOT and Eclipse. However I do 
have some 
issues with IDEA 9. Maybe it's worth creating an issue on the IDEA forum while 
I keep 
on investigating what could be wrong.

Original comment by etorrebo...@gmail.com on 20 Apr 2010 at 11:00

GoogleCodeExporter commented 9 years ago
Now I get it. IDEA uses another runner for specs and I guess that this is where 
the 
issue comes from. As a workaround it looks like you can run it as a JUnit test 
by 
creating a JUnit run configuration.

Original comment by etorrebo...@gmail.com on 22 Apr 2010 at 12:30

GoogleCodeExporter commented 9 years ago
I run them using JUnit run configuration. Actually what I do is Ctrl+Shift+F10 
on the
TransTest class. This makes an automatic JUnit configuration for it. I have 
trouble
with the specs runner.

Original comment by maill...@gmail.com on 22 Apr 2010 at 1:06

GoogleCodeExporter commented 9 years ago
Ok. I tried to reproduce the issue with the latest EAP (9.0.2), Scala plugin 
and specs 
1.6.5 and didn't get an issue. I'll try again with specs 1.6.2.2 to see if 
that's the 
difference.

Original comment by etorrebo...@gmail.com on 22 Apr 2010 at 1:31

GoogleCodeExporter commented 9 years ago
I tested with the latest IDEA 9.0.2, the latest Scala plugin and a JUnit 
configuration 
and things are working ok. Can you please try that out?

Original comment by etorrebo...@gmail.com on 22 Apr 2010 at 8:57

GoogleCodeExporter commented 9 years ago
I think I know what's the reason for the issue with the specs custom runner.

I am getting this exception when running a simple spec:

Exception in thread "main" java.lang.AbstractMethodError: 
org.jetbrains.plugins.scala.testingSupport.specs.Specs16Scala28Notifier.exampleC
ompleted(Ljava/lang/String;)V
    at org.specs.runner.NotifierRunner$$anonfun$reportExample$7.apply(NotifierRunner.scala:121)
    at org.specs.runner.NotifierRunner$$anonfun$reportExample$7.apply(NotifierRunner.scala:121)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:35)
    at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:35)
    at org.specs.runner.NotifierRunner.reportExample(NotifierRunner.scala:121)

so this may be only a recompilation error of the testing support plugin.

Original comment by etorrebo...@gmail.com on 22 Apr 2010 at 9:07

GoogleCodeExporter commented 9 years ago
I'm closing this issue for now hoping that you were able to get the appropriate 
support 
with the latest IDEA release.

Original comment by etorrebo...@gmail.com on 6 May 2010 at 4:42

GoogleCodeExporter commented 9 years ago
It is really working fine on IDEA 9.0.2. Sorry for not testing this again.

Original comment by maill...@gmail.com on 6 May 2010 at 12:45