Scala 導入

以下をナニ。

  • Scala 2.10.1
  • sbt 0.12.3

とりあえず Scala は /usr/local/lib に置いて PATH をナニ。sbt は以下から .deb を download して導入。

ええと、以下から雛形取得して

$ git clone https://github.com/maedaunderscore/nascala-FrequentWords.git

とりあえず build.sbt を云々。例えば依存するライブラリとか scala のバージョンとか。修正完了したらとりあえず

$ ./sbt test

なのかどうなのか。
一応 success で終了してますね。これでプロジェクトの雛形はできたのかな。
む、HelloWorld な試験を試しに書いてみるか。

import org.specs2._

class HelloSpec extends Specification {
  def is =
    "test test" ^
    "'hello world' string should" ^
    "contain 11 characters" ! e1^
    "start with 'hello'" ! e2^
    "end with 'world'" ! e3^
    end

  def e1 = "hello world" must have size(11)
  def e2 = "hello world" must startWith("hello")
  def e3 = "hello world" must endWith("world")
}

で、試験実行。

$ ./sbt test
[info] Set current project to default-ac3df7 (in build file:/home/rms/tmp/scala_test/nascala-FrequentWords/)
[info] Compiling 1 Scala source to /home/rms/tmp/scala_test/nascala-FrequentWords/target/scala-2.10/test-classes...
[info] HelloSpec
[info] 
[info] test test
[info]   'hello world' string should
[info]   + contain 11 characters
[info]   + start with 'hello'
[info]   + end with 'world'
[info]  
[info] Total for specification HelloSpec
[info] Finished in 57 ms
[info] 3 examples, 0 failure, 0 error
[info] 
[info] Passed: : Total 3, Failed 0, Errors 0, Passed 3, Skipped 0
[success] Total time: 10 s, completed May 3, 2013 8:42:34 PM

とりあえず製造の用意はできた、のか?

追記

Mockito が使える模様。ふむ。

つうか、build.sbt に追記が必要なのか。
あと、html 文字列にしておけば、Jsoup.parse で Document 型にできるのか。これを Jsonp.connect(url).get() な mock に云々、ってのはありなのかな。このあたりの動作確認もしておきたい連休だったり (ぇ
あと、Source#fromFile で戻る BufferedSource 型は toString なメソドが定義されているようで、これが予想してる通り動くのであれば Jsoup.parse が使えますね。
ええと、

val doc = Jsoup.connect(url).timeout(0).get()

をナニしようとするのであれば

  • Jsoup.connect が戻すオブジェクトな mock を作る
  • さらにその mock な get が戻す mock を作る
    • メソドが戻すオブジェクトを規定してあげれば良い (?)

ということが必要なのかな。mock なオブジェクトを作るのは単純な話なはずなので、そのオブジェクトが String を引数に取る Jsonp.parse から戻る Document を戻せば良い、ということになるんだけど理解はあってるのかどうか。