{"id":290,"date":"2012-05-08T09:06:48","date_gmt":"2012-05-08T00:06:48","guid":{"rendered":"http:\/\/lab.synergy-marketing.co.jp\/blog\/?p=290"},"modified":"2018-11-14T16:34:00","modified_gmt":"2018-11-14T07:34:00","slug":"scala-implicit-conversion-shouldmatchers","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/05\/08\/scala-implicit-conversion-shouldmatchers\/","title":{"rendered":"Scala \u6697\u9ed9\u7684\u578b\u5909\u63db\u306e\u4f7f\u3044\u3069\u3053\u308d (ShouldMatchers\u7de8)\u3000"},"content":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u99ac\u5834\u3067\u3059\u3002<\/p>\n

\u524d\u56de\u306f\u3001\u3053\u3046\u3044\u3046\u6697\u9ed9\u7684\u578b\u5909\u63db\u306f\u306f\u307e\u308b\u3001\u3068\u3044\u3046\u60b2\u3057\u3044\u4e8b\u4f8b\u3092ScalaQuery\u3092\u4f8b\u306b\u8aac\u660e\u3057\u307e\u3057\u305f\u3002
\n\u305f\u3060\u3001\u540c\u3058Scala\u306eDSL\u3067\u6697\u9ed9\u7684\u578b\u5909\u63db\u3092\u591a\u7528\u3057\u3066\u3044\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3082\u3001\u3059\u3093\u306a\u308a\u53d7\u3051\u5165\u308c\u3089\u308c\u3066\u3044\u308b\u3082\u306e\u3082\u3042\u308b\u306e\u3067\u3059\u3002\u305d\u308c\u304c\u3000ShouldMatchers<\/a>\u3067\u3059\u3002<\/p>\n

ShouldMatchers\u3068\u306f<\/h2>\n

ShouldMatchers\u306fScala\u306eUnitTest\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30afScalaTest<\/a>\u3067\u63d0\u4f9b\u3055\u308c\u308btrait\u3067\u3001\u30c6\u30b9\u30c8\u5185\u306e\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u3092\u8868\u73fe\u3059\u308bDSL\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001Stack\u3092\u30c6\u30b9\u30c8\u3059\u308b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5358\u4f53\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n

[scala]
\nimport org.scalatest.FunSuite
\nimport scala.collection.mutable.Stack<\/p>\n

class ExampleSuite extends FunSuite with ShouldMatchers{<\/p>\n

test("Stack\u304b\u3089pop\u3059\u308b\u3068\u6700\u5f8c\u306bpush\u3057\u305f\u5024\u304c\u53d6\u5f97\u3067\u304d\u3001Stack\u304b\u3089\u306f\u524a\u9664\u3055\u308c\u308b"){
\n val stack = new Stack[Int]
\n stack.push(1)
\n stack.push(2)
\n val oldSize = stack.size
\n val result = stack.pop()<\/p>\n

result should be(2)
\n stack should be (Stack(1))
\n }<\/p>\n

}
\n[\/scala]<\/p>\n

\"should\" \u3068\u3044\u3046\u5358\u8a9e\u3092\u4f7f\u3063\u3066\u3044\u308b\u6587\u3067\u3001<\/p>\n