Specs2 - Scala-Syd presentation

Post on 10-May-2015

932 views 0 download

description

This presentation was given to the Scala Sydney user group on Sep. 14th, 2011.

Transcript of Specs2 - Scala-Syd presentation

Go functional!

tourimport IncredibleStringReverser._

class ReverserSpec extends Specification { "a reversed empty string must be empty" in { reverse("") must_== "" } "a reversed empty string must really *be empty*" in { reverse("") must be empty } "a reversed string must be reversed abc -> cba" in { reverse("abc") must be_==("cba") } "a longer string must also be reversed. Whoops!" in { reverse("abcdef") must be_==("xxxxx") }}

tour

"a reversed empty string must be empty" in { reverse("") must be empty}

tour

tour

Shame

Mutability

Concurrency

Acceptance

Why

The idea

User

DesignProgram

Go Functional!

But what

is it?!

Referential transparency

Immutabili

ty

behavior

pipelined

FPemerg

entbehavior

Processing data structures

OO

Why

The idea

User

DesignProgram

Starting point

instructions != expressions

Nesting

Precedence:+!^

FormattingText

Example

Text

Example

Example

Formatting

pbrendt, t(i)bt, bt(i)

acceptance

Context

doBefore

withDb.apply(e2)

Why

The idea

User

DesignProgram

Run

execute

levels

select

sequence

arguments

statistics

to text

to html

Laziness vs evaluation

Iterating

Traverse

A datastructure to

traversethe

accumulation

the mapping

Applicative magic?

Lots of instances:• State• List• Monad• Monoid

simple

composable Type inference is hard,Let’s go

shopping!

Reduceraggregation

“parallel” composition

mapping

specs2 reducers:• Levels• Statistics• Arguments• Text• Html

Why

The idea

User

DesignProgram

Trees

Text

Example 1

Example 2

SuiteDescript

ion

Test Descriptio

n 1

Test Descriptio

n 2

SuiteDescription

fChildren = TD1, TD2

TreeLoc

TreeLoc

<h1/>

<h2/> <h2/>

<body>

<h2>part 1</h2><h2>part 2</h2>

<h1>Title 1</h1>

</body>

Anti-XMLThe non-violent solution

Concurrency

a concurrent task

=> Promise[Seq[ExecutedFragment]]

2.9.0

inside!

Exceptions

Exceptions

Exceptions

Mocks

<h1/>

MutabilityBack fo

r

good

Nothing here!

Throws exception

ConfigurationPart of the flow

named parameters + defaults

nested ‘record’

ConfigurationImplicits

implicit arguments

default value

Watch out!

recursivity

SOE

val (a,b) = c

Match

Error

val in traits

NPE

lost expressions

Bug

Conclusion

• Reliability• Concurrency• Composition• Less mocks• val/vars

• DSL• Type inference• Learning curve• Gotchas