I'm trying to use the MultipleFixtureWordSpec to enable me to pass
different types of things to my tests, as in the example in the
scaladoc[1]. But I'm running into compilation problems and I'm not
sure the documentation is correct. The example given is
import org.scalatest.fixture.MultipleFixtureWordSpec
class MyWordSpec extends MultipleFixtureWordSpec {
// A test that takes a String fixture
implicit def withStringFixture(testFunction: String => Unit):
FixtureParam => Unit =
testFunction("howdy")
// The "with-fixture" method for tests that take a List[Int] fixture
implicit def withListFixture(testFunction: List[Int] => Unit):
FixtureParam => Unit =
configMap => testFunction(List(configMap.size))
"Tests in a MultipleFixtureWordSpec" should {
// A test that takes a String fixture
"take a string fixture" in { (s: String) =>
assert(s === "howdy")
}
// A test that takes a List[Int] fixture
"take a list fixture" in { (list: List[Int]) =>
assert(list.size === 1)
}
// A test that takes no fixture
"take no fixture" in { () =>
assert(1 === 1)
}
}
}
But even that doesn't compile on Scala 2.7.7. Instead, I get the
following error
[error] /home/rwallace/Development/MRVN/src/test/scala/com/atlassian/marvin/CommandParserSpec.scala:63:
type mismatch;
[error] found : Unit
[error] required: (MyWordSpec.this.FixtureParam) => Unit
[error] testFunction("howdy")
[error] ^
Which makes sense based on the type of testFunction and the fact that
we just invoke it. However, if I change withStringFunction to
implicit def withStringFixture(testFunction: String => Unit):
FixtureParam => Unit =
configMap => testFunction("howdy")
Everything seems to work just fine. So it seems the implicit
conversion "to FixtureParam => Unit from supertrait FixtureWordSpec"
isn't in scope. Is that correct or am I missing something? I looked
in the source and there don't seem to be any tests or examples for
MultipleFixtureWordSpec so this may have gone unnoticed.
Thanks,
Rich
[1] http://www.scalatest.org/scaladoc/doc-1.0/org/scalatest/fixture/MultipleFixtureWordSpec.html