Skip to content

Instantly share code, notes, and snippets.

@daneko
Created April 1, 2012 23:00
Show Gist options
  • Select an option

  • Save daneko/2279295 to your computer and use it in GitHub Desktop.

Select an option

Save daneko/2279295 to your computer and use it in GitHub Desktop.
Scala ide for eclispe + specs2
http://scala-ide.org/ ← プラグインを入れる
http://www.assembla.com/wiki/show/scala-ide/Setup ← eclipse.iniの設定
http://blog.weblade.in/archives/1905 ← sbtでEclipseプロジェクトを作っている
→参考にした超適当シェルスクリプトを添付(mk-sbt-eclipse.sh)
mk-sbt-eclipse.sh hoge で作ったhogeプロジェクトの下に.projectができるのでimport
http://scala-ide.org/docs/user/testingframeworks.html
spces2の使い方がちょっと出ているので実際に動かしてみる
https://gist.github.com/1139288 ←環境設定とかはこっち
特に
SBT_OPTS="-Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m"
の文字コード指定がないとmacのターミナルで文字化ける
-> build.sbt に書けるかも? zshrcに書いちゃった
// jenkins
// sbt plugin install
$ cd /tmp
// https://github.com/harrah/xsbt/wiki/Getting-Started-Setup
$ wget http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar
$ cat << EOS >> sbt
java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar `dirname $0`/sbt-launch.jar "$@"
EOS
$ sudo mv sbt-launch.jar /usr/local/bin
$ sudo mv sbt /usr/local/bin
$ sudo chmod 755 /usr/local/bin/sbt
// 一度jenkinsで動作するか確認
$ sudo -u jenkins sbt clean reload update compile test // とか
フリースタイル
https://wiki.jenkins-ci.org/display/JENKINS/sbt+plugin
※ jarを指定する
※ sbtflagは -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M とか追記
#!/bin/sh
mkdir $1
cat << _EOS_ >> $1/build.sbt
name := "$1"
version := "1.0"
scalaVersion := "2.9.2"
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "latest.integration" % "test",
"org.specs2" %% "specs2-scalaz-core" % "latest.integration" % "test",
"junit" % "junit" % "latest.integration" % "test",
"org.hamcrest" % "hamcrest-all" % "latest.integration" % "test",
"org.pegdown" % "pegdown" % "latest.integration" % "test"
)
// Read here for optional dependencies:
// http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html#Dependencies
testOptions in Test += Tests.Argument("junitxml", "html", "console")
resolvers ++= Seq(
"snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"
)
_EOS_
cd $1
sbt update
mkdir project/plugins
cat << _EOS_ >> project/plugins/build.sbt
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "latest.integration")
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
_EOS_
sbt update
sbt eclipse
# ideaの場合 なぜかsrcディレクトリ以下が作られないので
#sbt gen-idea
#mkdir -p src/main/java
#mkdir -p src/main/scala
#mkdir -p src/test/java
#mkdir -p src/test/scala
cat << _EOS_ >> .hgignore
syntax: regexp
^.idea/
^.idea_modules/
^out/
^target/
.*/target/
.*\.class$
_EOS_
// このへんEclipseのTemplateみたいな感じにするのがいいかもしれない
import org.specs2._
import org.specs2.runner.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class HelloSpecs2 extends Specification {
def is =
"This is a specification to check the 'Hello world' string" ^
p ^
"The '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" )
}
import org.specs2.mutable._
import org.specs2.specification._
import org.specs2.runner.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class HelloSpecs2 extends Specification {
"The 'Hello world' string" should {
"contain 11 characters" in new c1 {
"Hello world" must have size (11)
}
"start with 'Hello'" in {
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
"Hello world" must endWith("world")
}
}
trait c1 extends Scope {
// ここでの処理は beforeみたいな扱いになる
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment