Here is an example from the scala.rx doc:
package tutorial.webapp
import rx.core.{Rx, Var}
import rx._
import rx.ops._
import scala.concurrent.Promise
import scala.concurrent.duration._
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scala.concurrent.ExecutionContext.Implicits.global
/**
* Created by IDEA on 29/10/15.
*/
object RxAddtionalOps extends JSApp {
#JSExport
override def main(): Unit = {
mapDemo
filterDemo
asyncDemo
async2
timer1
}
def delay1: Unit = {
val a = Var(10)
val b = a.delay(250 millis)
a() = 5
println(b())
eventually{
println(b)
}
}
}
I got this error on sbt when compiling:
[error] /Users/kaiyin/personal_config_bin_files/workspace/scalajsHandson/src/main/scala/tutorial/webapp/RxAddtionalOps.scala:43: not found: value eventually
[error] eventually{
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 1 s, completed 30 oct. 2015 11:15:07
Where does the eventually function come from? Am I missing any imports?
It's defined in utest, which is a author's framework for tests. Since it's a test dependency it doesn't come bundled with scalarx. BTW, the very same functionality presented in scalatest.
Related
I want to verify the order of sequence calls, but it didn't work as I expected.
import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest._
import org.specs2.mock.Mockito
class Test extends TestKit(ActorSystem("testSystem"))
with WordSpecLike
with BeforeAndAfterAll
with PrivateMethodTester
with `enter code here`Mockito
{
val m = mock[java.util.List[String]]
m.get(0) returns "one"
there was two(m).get(2) //do not throw any error, why???
}
I'm using
scala 2.11.7,
specs2-core 3.6.6,
specs2-mock 3.6.6,
scalatest 2.2.4
thx
I don't think you can mix Specs2 and ScalaTest.
You shuld remove import org.scalatest._ and use import org.specs2.mutable.SpecificationLike instead.
import akka.testkit.TestKit
import akka.actor.ActorSystem
import org.specs2.mock.Mockito
import org.specs2.mutable.SpecificationLike
class Test extends TestKit(ActorSystem("testSystem"))
with Mockito
with SpecificationLike
{
"it" should{
"raise error" in {
val m = mock[java.util.List[String]]
m.get(0) returns "one"
there was two(m).get(2)
}
}
}
Now you can see that sbt test returns something like.
[error] The mock was not called as expected:
[error] Wanted but not invoked:
[error] list.get(2);
[error] -> at Test$$anonfun$1$$anonfun$apply$1$$anonfun$apply$3.apply(Test.scala:14)
[error] Actually, there were zero interactions with this mock. (Test.scala:14)
I'm new to scala but I'm trying to add some tests to a simple file. The problem is that when I try to import the object into the test I get "error: not found: value"
PerfectNumberImperative.scala
package perfectImperative
package object perfectImperative{
def main(args: Array[String]){
perfectImperative(args(0).toInt)
}
def perfectImperative(input: Int): Boolean = {
var evaluation = (for (possibleFactor <-1 to input if (input % possibleFactor == 0)) yield possibleFactor).sum == input*2
return evaluation
}
}
PerfectNumberSpec.scala
import org.scalatest.FlatSpec
import perfectImperative._
class PerfectNumberSpec extends FlatSpec {
it should "return true for 6" in {
assert(perfectImperative.perfectImperative(6))
}
}
[error] C:\Users\Daniel\PerfectNumbersScala\src\test\scala\PerfectNumberSpec.scala:2: not found: object perfectImperative
[error] import perfectImperative._
[error] ^
[error] C:\Users\Daniel\PerfectNumbersScala\src\test\scala\PerfectNumberSpec.scala:6: not found: value perfectImperative
[error] assert(perfectImperative.perfectImperative(6))
[error] ^
[error] two errors found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Sep 16, 2015 2:30:38 AM
I would appreciate if someone could point me in the right direction.
Test
package com.utrecht.numbersequences
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
class NumberSequencesTests extends FunSuite with BeforeAndAfter with MockitoSugar {
test("testCity") {
NumberSequences.city_("utrecht")
assert("utrecht" === NumberSequences.city())
}
}
Code
package com.utrecht.numbersequences
import scala.collection.immutable.Stream.consWrapper
object NumberSequences {
var _city: String = null
def city_=(_city:String) = this._city = _city
def city = this._city
}
Outcome
value not a member of object
not enough arguments for method apply: (index: Int)Char in class StringOps
test
[info] Compiling 1 Scala source to C:\path\to\developme
nt\scalaNumberSequences\target\scala-2.10\test-classes...
[error] C:\path\to\development\scalaNumberSequences\src
\test\scala\com\utrecht\numbersequences\NumberSequencesTest.scala:32: value city
_ is not a member of object com.utrecht.numbersequences.NumberSequences
[error] NumberSequences.city_("utrecht")
[error] ^
[error] C:\path\to\development\scalaNumberSequences\src
\test\scala\com\utrecht\numbersequences\NumberSequencesTest.scala:33: not enough
arguments for method apply: (index: Int)Char in class StringOps.
[error] Unspecified value parameter index.
[error] assert("utrecht" === NumberSequences.city())
[error] ^
[error] two errors found
[error] (test:compile) Compilation failed
[error] Total time: 1 s, completed Aug 10, 2014 5:52:16 PM
NumberSequences.city_=("utrecht")
//OR
NumberSequences.city = "utrecht"
but not:
NumberSequences.city_("utrecht") // city_ is not a method existing in the object
i am following a tutorial to create a Producer Consumer with actors
i made three files i.e Master.scala, Counter.scala and Parser.scala
i am getting not found value in two of my files(Counter.scala and Parser.scala)
Parser.scala
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor._
case object Processed
class Parser(counter: ActorRef) extends Actor {
val pages=Pages(100000, "enwiki.xml")
override def preStart{
for(page<-pages.take(10))
counter ! page
}
def receive={
case Processed if pages.hasNext => counter ! pages.next
case _ => context.stop(self)
}
}
Counter.scala
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor._
class Counter extends Actor {
val counts = HashMap[String,Int]().withDefaultValue(0)
def receive={
case Page(title, text)=>
for (word<-Words(text))
counts(word) += 1
sender ! Processed
}
}
Errors
[error] /home/ahsen/SbtPrctc/ProducerConsumer/src/main/scala/Counter.scala:6: not found: value HashMap
[error] val counts = HashMapString,Int.withDefaultValue(0)
[error] ^
[error] /home/ahsen/SbtPrctc/ProducerConsumer/src/main/scala/Counter.scala:8: not found: value Page
[error] case Page(title, text)=>
[error] ^
[error] /home/ahsen/SbtPrctc/ProducerConsumer/src/main/scala/Counter.scala:9: not found: value Words
[error] for (word<-Words(text))
[error] ^
[error] /home/ahsen/SbtPrctc/ProducerConsumer/src/main/scala/Parser.scala:7: not found: value Pages
[error] val pages=Pages(100000, "enwiki.xml")
[error] ^
i am sure i am doing some stupid mistake bt please help me out
If you want to use the Java HashMap you need to import java.util.HashMap. However, I believe in your case you want to use the Scala scala.collections.mutable.Map (which you also need to import, and change HashMap to Map).
Also, please properly indent your code in your questions, and also mark the stack traces as code. It makes it much easier for respondents to read your questions.
As you know, play! introduced Gzip encoding in 2.2.0 version.
Unfortunately, after updating project and updating play, it doesn't work.
[error] ...\app\Global.scala:4: object filters is not a member of package play
[error] import play.filters.gzip.GzipFilter
[error] ^
[error] ...\app\Global.scala:8: not found: type GzipFilter
[error] object Global extends WithFilters(new GzipFilter) with GlobalSettings {
[error] ^
[error] two errors found
[error] (compile:compile) Compilation failed
It doesn't work even if I create project form console play new TEST.
However in C:\play-2.2.0\framework\src\play-filters-helpers\src\main\scala\play\filters\gzip I have both Gzip.scala and GzipFilter.scala.
My \app\Global.scala looks like that:
import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.filters.gzip.GzipFilter
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Global extends WithFilters(new GzipFilter) with GlobalSettings {
override def onStart(app: Application) {
Logger.info("Application has started")
}
override def onStop(app: Application) {
Logger.info("Application shutdown")
}
override def onError(request: RequestHeader, ex: Throwable) = Future { InternalServerError("{}") }
override def onBadRequest(request: RequestHeader, error: String) = Future { BadRequest("{}") }
override def onHandlerNotFound(request: RequestHeader) = Future { NotFound("{}") }
}
What am I doing wrong? Has anyone made that working?
In Build.scala, just add "filters" to your app dependencies
val appDependencies = Seq(
jdbc, cache, filters, ...
)
or, if you are doing it with build.sbt
libraryDependencies ++= Seq(
jdbc, cache, filters, ...
)