|
Troubleshooting
Pitfalls and errors that you can avoid
Featured This page lists tips on errors you may encounter while using specs.
NoSuchMethodErrorYou may have dependencies issues. Please check the version numbers of all the libraries you're using: dependencies Strange compilation errorThe following spec would raise a compilation error: "My Thing" should {
"do something" {
...possibly long setup...
something must ... other // matcher
}This would generate: > "message without in" { "value" must beEqual("anotherValue") }
> error: type mismatch;
> found : org.specs.specification.Result[java.lang.String]
> required: Int
> "message without in" { "value" must beEqual("anotherValue") }This is because there is a missing "in" after the example description, so everything inside the accolade is expected to be an Int used to access one character of "do something" (see issue 22 ) Skipped exampleThis example would appear as "skipped" in the reports: "my example" in {
doSomething() // appears as skipped
}The example shows as 'skipped' because it is a warning that it is not specifying any expectations. We're taking the view here that expecting a piece of code not to throw an exception is a sign that your example is incomplete as a specification of the intended behavior. However if that's really what you mean, you can declare that by using isExpectation: "my example" in {
doSomething().isExpectation // appears as passed if no exception is thrown
}If you don't like this default behavior you can override it by changing your specs configuration: http://code.google.com/p/specs/wiki/RunningSpecs#Override_specs_default_behavior The objects to compare have the same toString valueFor example you're comparing List("1") to List(1) using must_==. After the fix for issue 141 you will get a warning saying Values have the same string representation but possibly different types like List[Int] and List[String]. My specification is leaking some resourcesThis may be a case like issue 150 where specs is executing examples in isolation by cloning the specification but not always calling doAfter to clean the resources. You can read more here and there. | |
I was surprised when an example with no expectations was ignored.
"my example" in { doSomething() // example is ignored! This works, though: doSomething() must be_==(()) }This behavior is indeed the default behavior and is meant at warning you that an example is not specifying any expectations. This can be overriden by changing your specs configuration: http://code.google.com/p/specs/wiki/RunningSpecs#Override_specs_default_behavior
You can also declare any piece of code to be an expectation in itself with:
doSomething.isExpectation
Just adding new error message to make the issue more searchable:
scala> "message without in" { "value" must beEqual("anotherValue") } <console>:12: error: type mismatch; found : org.specs.specification.Result[java.lang.String] required: Int "message without in" { "value" must beEqual("anotherValue") } ^