Skip to content

Instantly share code, notes, and snippets.

import scala.actors._
import Actor._
for (i <- 1 to 500) actor {
println("Starting actor... " + i)
Thread.sleep(5000L)
}
import scala.actors._
import Actor._
case object DoIt
val worker = actor {
loop {
react {
case DoIt => println("Time for work at " + new java.util.Date())
}
JettyTestServer.start
val baseUrl = "/twitter"
implicit val reportError = new ReportFailure {
def fail(msg: String): Nothing = TwitterAPISpecs.this.fail(msg)
}
for {
login <- get("/account/verify_credentials.xml", httpClient, Nil)
!@ "Failed to log in"
message <- login.post("/statuses/update.xml", "status" -> "test_msg1")
!@ "Couldn't post message"
xml <- message.xml
} {
// Specs' xml matcher
xml must \\(<text>test_msg1</text>)
}
get("/account/verify_credentials.xml")
! (401, "Login should fail with Unauthorized status")
override def theHttpClient = {
val theClient = buildBasicAuthClient(userName, password)
theClient.getParams.setAuthenticationPreemptive(true)
theClient
}
trait XmlResponse {
self: TestResponse =>
def xmlMatch(f: Elem => Unit)
(implicit errorFunc: ReportFailure): TestResponse = {
if (this.asInstanceOf[SelfType].code != 200)
errorFunc.fail("Response status is not 200!")
xml match {
case Full(xml) => f(xml); this
case _ => errorFunc.fail("Response contains no XML!")
}
for {
message <- post("/statuses/update.xml", "status" -> "test_msg1")
!@ "Couldn't post message" if message.xml must notBeEmpty
xml <- message.xml
} {
xml must \\(<text>test_msg1</text>)
}
post("/statuses/update.xml", "status" -> "test_msg1")
\\(<text>test_msg1</text>)
\\(<screen_name>vdichev</screen_name>)
get("/statuses/public_timeline.xml") \\(<text>test_msg1</text>)
get("/statuses/user_timeline.xml") \\(<text>test_msg1</text>)
get("/statuses/home_timeline.xml") \\(<text>test_msg1</text>)