Entries from 2011-09-01 to 1 month

Specs2を試す(9)

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Shared+examples Declare arguments specの最初にarg(ほにゃらら=true)をくっつけることで、specの実行やレポートの挙動を返ることができる。コード1 は args(sequen…

Specs2を試す(8)

Single step Given/When/Then の3つのステップは GivenThen で1つにまとめることができる。 import org.specs2._ import specification._ class GivenThenSpec extends Specification { def is = "given the name: ${eric}, then the age is ${18}" ! new Gi…

Specs2を試す(7)

ScalaCheck values Given/When/Then シーケンスで scalacheck の generator を使う方法。 import org.scalacheck._ import org.scalacheck.Gen._ import org.scalacheck.Prop._ import org.specs2._ import org.specs2.specification.gen._ class GivenWhenT…

Specs2を試す(6)

Given/When/Then Given/When/Then というスタイルでspecを書くこともできる。 // コード1 import org.specs2._ import org.specs2.specification._ import org.specs2.execute._ class GivenWhenThenSpec extends Specification { def is = "A given-when-th…

Specs2を試す(5)

Pending until fixed 一時的にテストを実行したくないときは pendingUntilFixed が使える。 // テスト1 import org.specs2._ class HelloWorldSpec2 extends Specification { def is = "This is a specification to check the 'Hello world' string" ^ p^ "T…

Scalaでtrコマンドっぽいの

trコマンドみたいなことやりたかったんだけど、そのものズバリ的なものないですかね。 def transform[A](dict: List[(A, A)], xs: List[A]): List[A] = { def replace(t: (A, A), xs: List[A]): List[A] = xs.map { case x if x == t._1 => t._2 case x => x…

Specs2を試す(4)

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Declare+examples Result // コード1 "this is my specification" ^ "and example 1" ! e1^ "and example 2" ! e2 def e1 = success def e2 = success 上の例の "and…

Specs2を試す(3)

Unit specification Unit specification はshould/inブロックを使ってFragments(Fragmentのリスト)を作る。 Acceptance Specification は org.specs2.Specification を継承しているのに対し、 Unit specification は org.specs2.mutable.Specification を継…

Specs2を試す(2)

Acceptance specification 参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Specification+structureAcceptance specification では、一つ一つの'frgment'を^でつなぎ、 'fragmentのリスト(flagments)'を作るという…

Specs2を試す(1)

sbtのバージョンは0.10 Scalaのバージョンは2.9.1 インストール githubから持ってきてpublish-local(localのivyリポジトリにpublish)することにした。 $ git clone git://github.com/etorreborre/specs2 $ sbt > publish-local sbtの設定 http://etorreborre…

Scala実践プログラミング

Scala実践プログラミング―オープンソース徹底活用作者: 小笠原啓,尾崎智仁,関隆,水島宏太,今井敬吾出版社/メーカー: 秀和システム発売日: 2011/06メディア: 単行本購入: 2人 クリック: 134回この商品を含むブログ (20件) を見る部分的にすごい気合入ってて面…

Pythonでsqliteを使う

標準で使える!ステキ! 使いかたは簡単で、 connectする cursorオブジェクトを取得 cursor.executeでクエリを発行。プレースホルダとかも使える。 commitしたりcloseしたり # モジュールをインポート >>> import sqlite3 # 接続 >>> conn = sqlite3.connect…

シェルコマンドの実行結果をEmacsのバッファに吐き出す

見つけた lewang/e-sink - GitHub https://github.com/lewang/e-sink cloneします。 $ git clone git://github.com/lewang/e-sink.git e-sinkはe-sink.elとe-sink.plから構成されています。 e-sink -- e-sink.el `-- e-sink.pl 設定 e-sinkはemacsclientを使…

Scalaの名前付き引数

おお...あるの初めて知った...なぜ今まで知らなかった... scala> def hello(name: String) = println("Hello " + name) hello: (name: String)Unit // 普通の呼び出し scala> hello("toshi") Hello toshi // 名前付きで呼び出し scala> hello(name="toshi") …