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
/** | |
* This doesn't compile | |
* type mismatch; | |
* found : Iterable[T] | |
* required: CC[T] | |
* def dropOne: CC[T] = xs.drop(1) | |
*/ | |
object o { | |
implicit def extend[T, CC[T] <: Iterable[T]](xs: CC[T]) = new ExtendedIterable(xs) | |
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 test | |
import org.specs.mock.Mockito | |
import org.scalatest.WordSpec | |
import org.specs.specification._ | |
/** | |
* DefaultExampleExpectationsListener provides default behavior for specs creation of | |
* examples and expectations. | |
* |
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
// a Map can be used as a PartialFunction | |
List("Darth Vador", "Eric", "Frankenstein") collect Map("Eric" -> "good", "Darth Vador" -> "very evil", "Frankenstein" -> "evil") must_== List("very evil", "good", "evil") |
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
/** | |
* An answer from Jason Zaugg on the scala-internals mailing list | |
* | |
* Implicit parameters can have defaults. | |
*/ | |
scala> implicit def OptionalImplicit[A <: AnyRef](implicit a: A = null) = Option(a) | |
OptionalImplicit: [A <: AnyRef](implicit a: A)Option[A] | |
scala> implicitly[Option[Ordering[Int]]] |
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
/** | |
* An example showing why changing a parameter to "call by name" may break clients of an API. | |
* As usual, side-effects are the main issue here,... | |
*/ | |
/** "before" api */ | |
def registerDatabaseState(state: DatabaseState) = // store an event with the current state of the database | |
/** | |
* "after" api. Storing the event may not happen based on the configuration for example |
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
[INFO] Compiling 152 source files to C:\projects\specs\specs-2.9.0\target\test-classes at 1296871592783 | |
[INFO] java.lang.reflect.InvocationTargetException | |
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
[INFO] at java.lang.reflect.Method.invoke(Method.java:597) | |
[INFO] at org_scala_tools_maven_executions.MainHelper.runMain(MainHelper.java:161) | |
[INFO] at org_scala_tools_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26) | |
[ERROR] Caused by: java.lang.AssertionError: assertion failed | |
[INFO] at scala.Predef$.assert(Predef.scala:85) |
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
"" size | |
1 | |
error: scala.this.Predef.augmentString("").size of type Int does not take parameters | |
"" size |
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
// a trait defining a transformation method | |
trait A { | |
case class Other(s: String) | |
def toOther(s: String) = Other(s) | |
} | |
// the same trait with the method defined as implicit | |
trait AB extends A { | |
override implicit def toOther(s: String) = super.toOther(s) | |
} |
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
// base functionality | |
trait A { | |
case class Other(s: String) { | |
def in: String = "in" | |
} | |
def toOther(s: String) = Other(s) | |
} | |
// base functionality with an implicit | |
trait AB extends A { | |
override implicit def toOther(s: String) = super.toOther(s) |
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
/** | |
* For those examples using Around may not be very different from a simple method call with a call-by-name | |
* parameter. | |
* | |
* The only difference is that the http object is a named context that you can compose with other setups, like a Before setup: | |
* | |
* http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Composing+contexts | |
*/ | |
class AcceptanceSpec extends Specification { def is = |