Created
December 15, 2008 03:41
-
-
Save takedasoft/35859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* myProjFullSpec.scala | |
* | |
* Specs API 調査版 | |
* http://specs.googlecode.com/files/scaladocs-1.4.1.rar | |
*/ | |
package takedasoft | |
import org.specs._ | |
import org.specs.matcher._ | |
import org.specs.specification._ | |
import java.io.File | |
/** | |
* 共通仕様 | |
*/ | |
abstract class MyProjectSpec extends Specification { | |
def cannot = fail("このルートはありえない") | |
doBeforeSpec { println("-- global prepare --") } | |
doAfterSpec { println("-- global cleanup --") } | |
val prepareFile = beforeContext( { println("-- prepare Real File --") } ) | |
val cleanupFile = afterContext( { println("-- cleanup Real File --") } ) | |
} | |
object TmpFileSpec2 extends MyProjectSpec { | |
"TmpFile" should { | |
doFirst { println("-- do it first --") } | |
doLast { println("-- do it last --") } | |
var tmp:TmpFile = null | |
doBefore { tmp = new TmpFile } | |
doAfter { tmp.destroy } | |
"一時ファイル名" in { | |
"接頭が _ST_ の21文字であること" in { | |
tmp.name must startWith("_ST_") | |
tmp.name.size must_==21 | |
} | |
"拡張子が .tmp であること" in { | |
tmp.name must endWith(".tmp") | |
} | |
} | |
}// end of "TmpFile" should | |
}// end of TmpFileSpec2 | |
object OtherSpec extends MyProjectSpec { | |
"RealFile"->-(prepareFile) should { | |
"が存在すること" >> { | |
fail("not implemented") | |
} | |
}// end of "RealFile" should | |
}// end of OtherSpec | |
/** | |
* API を読み進めるためにImplicitを排除してコアAPIを明記 | |
*/ | |
object NonImplicitSpec extends Specification { | |
//org.specs.specification.SpecificationStructure | |
val futsuu:SpecificationStructure = declare("NonImplicitSpec"); | |
//org.specs.specification.Sus | |
val futsuuSus:Sus = futsuu.specify("implicitしないテスト") | |
futsuuSus.should { | |
//org.specs.specification.Example | |
val kimokunai:Example = forExample("コードがきもくないこと") | |
kimokunai.in( | |
{ | |
//org.specs.specification.Expectable | |
val str:StringExpectable[String] = theString("TESTStr") | |
str.must_==/("testStr") | |
//org.specs.specification.Expectation | |
val expect:Expectation[String] = new Expectation("abcde") | |
// Specification < Matchers < StringMatchers | |
val required:Matcher[String] = beEqualToIgnoringCase("ABCDE") | |
expect.must( required ) | |
// 他に AnyMatchers, NumericMatchers, XmlMatchers など | |
// org.specs.matcher.Matchers を参照のこと | |
} | |
) | |
}// end of kimoiSus should | |
}// end of NonImplicitSpec | |
/* | |
* オリジナルのMatcherを使ったテスト | |
*/ | |
class Book(val name:String) {} | |
trait BookMatchers extends Matchers{ | |
case class same(book:Book) extends Matcher[Book] { | |
/** ( result, successString, errorString ) を返す */ | |
def apply( other: => Book ) = ( book.name.equalsIgnoreCase(other.name), | |
book.name + " is same to " + other.name, | |
book.name + " is not " + other.name ) | |
} | |
} | |
object BookSpec extends Specification with BookMatchers { | |
"Book" should { | |
"名前が同じであれば同じ本であること(大文字小文字を区別しない)" in { | |
new Book("Programing JRuby") must same (new Book("programing ruby")) | |
} | |
} | |
} | |
/** | |
* 細分した仕様を束ねる | |
*/ | |
object myProjFullSpec extends Specification { | |
"このシステムの全仕様は以下のとおり" isSpecifiedBy( | |
TmpFileSpec2, | |
OtherSpec, | |
NonImplicitSpec, | |
BookSpec | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment