Created
October 1, 2011 21:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DatabaseSpec extends Specification { def is = sequential ^ | |
| "This is a specification to check the database schema" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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