Skip to content

Instantly share code, notes, and snippets.

@micrypt
Created October 1, 2011 21:08
Show Gist options
  • Select an option

  • Save micrypt/1256663 to your computer and use it in GitHub Desktop.

Select an option

Save micrypt/1256663 to your computer and use it in GitHub Desktop.
Squeryl + specs2 examples for a blog post > micrypt.com/2011/07/05/squeryl-specs2-testing-quick-start.html
"allow creation of new entries" >> setupData {
val datum = data.insert(new Datum(0, Some(1),Some(""), Some("ftp.example.org"), Some("username"), Some("password"), Some(new java.util.Date)))
datum.id must_== 1
}
class DatabaseSpec extends Specification { def is = sequential ^
"This is a specification to check the database schema"
package appname.unit
import org.specs2.mutable._
import org.specs2.specification.BeforeExample
import org.specs2.specification._
import org.squeryl._
import adapters.H2Adapter
import PrimitiveTypeMode._
import appname.schema._
import DBSchema._
class DatabaseUnitSpec extends Specification with BeforeExample{
def before = initialize
"Schema stored in database should" >> {
"allow creation of new entries" >> {
transaction {
val datum = data.insert(new Datum(0, Some(1),Some(""), Some("ftp.example.org"), Some("username"), Some("password"), Some(new java.util.Date)))
datum.id must_== 1
}
}
"allow retrieval of entries" >> {
transaction {
data.insert(new Datum(0, Some(1),Some(""), Some("ftp.example.org"), Some("username"), Some("password"), Some(new java.util.Date)))
val datum = data.where(a => a.id === 1).single
datum.id must_== 1
}
}
}
// Initialization & tear-down functions
def initialize = {
println("Setting up data.")
Class.forName("org.h2.Driver")
SessionFactory.concreteFactory = Some(()=>
Session.create(
java.sql.DriverManager.getConnection("jdbc:h2:~/example", "sa", ""),
new H2Adapter)
)
inTransaction {
drop
create
printDdl
}
}
}
"Schema stored in database should" >> {
"allow creation of new entries" >> {
val datum = data.insert(new Datum(0, Some(1),Some(""), Some("ftp.example.org"), Some("username"), Some("password"), Some(new java.util.Date)))
datum.id must_== 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment