title: How to use fixture-context objects with async specs in ScalaTest?
body: <p>I'm trying to use <a href="http://www.scalatest.org/user_guide/sharing_fixtures#fixtureContextObjects" rel="noreferrer" title="future-context objects">fixture-context objects</a> with <a href="http://www.scalatest.org/user_guide/async_testing" rel="noreferrer" title="async testing">async testing</a> in ScalaTest.</p>
  
  <p>The naive approach of simply combining the two doesn't compile. For example:</p>
  
  <pre><code>import org.scalatest.AsyncWordSpec
  
  import scala.collection.GenTraversableOnce
  import scala.concurrent.{ExecutionContext, Future}
  import scala.math.Numeric.IntIsIntegral
  
  trait Adder[T] {
    implicit def num: Numeric[T]
    def add(number: T): Unit
    def result: Future[T]
  }
  
  object Foo {
    def doubleSum[T](adder: Adder[T], numbers: GenTraversableOnce[T])(implicit ec: ExecutionContext): Future[T] = {
      numbers.foreach(adder.add)
      val num = adder.num
      import num._
      adder.result.map(result =&gt; result + result)
    }
  }
  
  class FooSpec extends AsyncWordSpec {
  
    trait IntAdder {
      val adder = new Adder[Int] {
        override implicit val num = IntIsIntegral
        private var sum = Future.successful(num.zero)
        override def add(number: Int): Unit = sum = sum.map(_ + number)
        override def result: Future[Int] = sum
      }
    }
  
    "Testing" should {
      "be productive" in new IntAdder {
        Foo.doubleSum(adder, Seq(1, 2, 3)).map(sum =&gt; assert(sum == 12))
      }
    }
  }
  </code></pre>
  
  <p>This fails to compile with:</p>
  
  <pre><code>Error:(37, 11) type mismatch;
  found   : FooSpec.this.IntAdder
  required: scala.concurrent.Future[org.scalatest.compatible.Assertion]
            new IntAdder {
  </code></pre>
  
  <p>This is a legitimate error but I'm wondering what ways there are of solving this in a ScalaTest style.</p>
  
  <p>I want to keep the fixture-context object since that allows me to use the <a href="http://www.artima.com/scalazine/articles/stackable_trait_pattern.html" rel="noreferrer" title="stackable trait pattern">stackable trait pattern</a>.</p>