specs2

Play! framework: customize which tests are run

这一生的挚爱 提交于 2019-12-21 03:38:18
问题 I have a Play! 2 for Scala application, and I am using Specs2 for tests. I can run all tests with the test command, or a particular specification with test-only MyParticularSpec . What I would like to do is mark some particular specifications, or even single methods inside a specification, in order to do things like: running all tests that are not integration (that is, that do not access external resources) running all tests that do not access external resources in write mode (but still

Play 2.0 FakeApplication setup with test configuration

空扰寡人 提交于 2019-12-20 12:37:00
问题 I have a specs2 test which uses a FakeApplication and an embedded mongodb database. def inMemoryMongoDatabase(name: String = "default"): Map[String, String] = { val dbname: String = "play-test-" + scala.util.Random.nextInt Map( ("mongodb." + name + ".db" -> dbname), ("mongodb." + name + ".port" -> EmbeddedMongoTestPort.toString)) } override def around[T <% Result](t: => T) = { running(FakeApplication(additionalConfiguration = inMemoryMongoDatabase(), additionalPlugins = Seq("se.radley.plugin

Scala: How to test methods that call System.exit()?

微笑、不失礼 提交于 2019-12-19 05:58:15
问题 I have been developing a command-line tool which calls System.exit() ( don't want to use exceptions instead of ) on certain inputs. I am familiar with Java: How to test methods that call System.exit()? and its the most elegant approach. Unfortunately, it is not enough pure, due to I had to add the dependencies to system-rules, junit-interface Is there any common pattern for dealing with System.exit in specs2 which is more pure than my current approach which don't use specs2 ? import org.junit

Unable to test controller using Action.async

ぃ、小莉子 提交于 2019-12-19 05:17:36
问题 I'm trying to test controller, which is using new Action.async . Following documentation I have excluded part under controller I want to test to separate trait with type reference: trait UserController { this: Controller => def index() = Action { /* snip */ } def register() = Action.async(parse.json) { request => /* snip */ } } Documentation states that I'm supposed to test it as: object UsersControllerSpec extends PlaySpecification with Results { class TestController() extends Controller

specs2 After method runs before the example

南笙酒味 提交于 2019-12-13 16:34:05
问题 I have the following test: class Foo extends mutable.SpecificationWithJUnit { sequential "this example should run before the 'After' method" in new Context { bar must beSome } class Context extends mutable.BeforeAfter with mutable.Around { override def apply[T : AsResult](a: =>T): Result = { lazy val result = super[Around].apply(a) super[BeforeAfter].apply(result) } override def delayedInit(x: => Unit): Unit = around { try { before; x; Success() } finally { after }} @Resource var barReader :

Mocking default values for return types with mockito + specs2

╄→尐↘猪︶ㄣ 提交于 2019-12-13 06:50:35
问题 Given a mock: val myMock = mock[SomeClass] I am trying to set it up so that the mock returns default values for various types. E.g. for things that returns String , it would return "" . I discovered RETURNS_SMART_NULLS which looks like it works for basic return types like String. Here is how I am using it in Scala / Specs2: val myMock = mock[SomeClass].settings(smart = true) Now to the problem: since I am using Scala, my code / APIs do not return nulls but return Option values. So what I am

Could not initialize class persistence.common.neo4j.Neo4jSpringContext$ in sbt yet test works in IntelliJ IDEA?

别说谁变了你拦得住时间么 提交于 2019-12-12 20:31:42
问题 I wanted to see if all my test are passing after git merge , and noticed that sbt test failed. All of those tests are the ones that are using Spring context. As to not load Spring context for every test I created the following trait: import org.springframework.context.support.ClassPathXmlApplicationContext trait Neo4jSpringContext { val context = Neo4jSpringContext.context } object Neo4jSpringContext { val context = new ClassPathXmlApplicationContext("testNeo4jApplicationContext.xml") } and

slick & sqlite : Could not instantiate class tests.SqliteSpec: org.sqlite.JDBC

試著忘記壹切 提交于 2019-12-11 19:52:29
问题 I try to begin an app with scala, play, slick, specs2 & sqlite.here is a trait for sqlite integration: import scala.slick.driver.SQLiteDriver.simple._ import metier.Objets._ import scala.slick.lifted.ProvenShape import java.sql.Date package models { trait sqlite { val db = Database.forURL("jdbc:sqlite:rdvs.txt", driver = "org.sqlite.JDBC") //val db = Database.forDataSource(DB.getDataSource()) class Personnes(tag: Tag) extends Table[Rdv](tag, "RDV") { def id = column[Int]("ID", O.PrimaryKey, O

Testing: FakeApplication ignoring additionalConfiguration

耗尽温柔 提交于 2019-12-11 18:07:16
问题 I'm trying to add a test on a Play 2.0 w/Scala project: "Application" should { "return 404 on the index Action if web is disabled " in { running(FakeApplication(additionalConfiguration = Map(("enable.webInterface" -> "false")) )) { Config.IS_WEB_ENABLED must beFalse val result = controllers.Application.index()(FakeRequest()) status(result) must equalTo(NOT_FOUND) contentType(result) must beSome("text/html") charset(result) must beSome("utf-8") } } } The value Config.IS_WEB_ENABLED is defined

Error using Specs2 with FluentLenium Api

╄→尐↘猪︶ㄣ 提交于 2019-12-11 13:36:34
问题 I use Scala 2.10, Specs2 13.1-SNAPSHOT and the FluentLenium Api provided by Play2 Framework 2.1. I have this line of code in my IntegrationSpec file, finding a child element (according to FluentLenium spec): browser.find(".myClass").find("#mySubElement") must haveSize(1) That line leads to the following compilation error: error: type mismatch; found : org.fluentlenium.core.domain.FluentList[_ <: org.fluentlenium.core.domain.FluentWebElement] required: org.fluentlenium.core.domain.FluentList[