Giter VIP home page Giter VIP logo

expecty's Introduction

Expecty - Power Assertions for Scala

Expecty brings power assertions as known from Groovy and Spock to the Scala language. It is a micro library that aims to do one thing well.

License and Credits

Expecty was originally written by Peter Niederwieser, author of Spock.

Expecty is licensed under the Apache 2 license.

Setup

libraryDependencies += "com.eed3si9n.expecty" %% "expecty" % "0.12.0" % Test

Code Examples

Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_212).
Type in expressions for evaluation. Or try :help.

scala> import com.eed3si9n.expecty.Expecty.assert
import com.eed3si9n.expecty.Expecty.assert

scala> case class Person(name: String = "Fred", age: Int = 42) {
     |   def say(words: String*) = words.mkString(" ")
     | }
defined class Person

scala> val person = Person()
person: Person = Person(Fred,42)

scala> // Passing expectations

scala> assert(person.name == "Fred")

scala> assert(person.age * 2 == 84)

scala> assert(person.say("Hi", "from", "Expecty!") == "Hi from Expecty!")

scala> // Failing expectation

scala> val word1 = "ping"
word1: String = ping

scala> val word2 = "pong"
word2: String = pong

scala> assert(person.say(word1, word2) == "pong pong")
java.lang.AssertionError: assertion failed

assert(person.say(word1, word2) == "pong pong")
       |      |   |      |      |
       |      |   ping   pong   false
       |      ping pong
       Person(Fred,42)

  at com.eed3si9n.expecty.Expecty$ExpectyListener.expressionRecorded(Expecty.scala:35)
  at com.eed3si9n.expecty.RecorderRuntime.recordExpression(RecorderRuntime.scala:39)
  ... 36 elided

scala> assert(person.age * 2 == 73, "age is not right")
java.lang.AssertionError: assertion failed: age is not right

assert(person.age * 2 == 73, "age is not right")
       |      |   |   |
       |      42  84  false
       Person(Fred,42)

  at com.eed3si9n.expecty.Expecty$ExpectyListener.expressionRecorded(Expecty.scala:35)
  at com.eed3si9n.expecty.RecorderRuntime.recordExpression(RecorderRuntime.scala:39)
  ... 36 elided

Further Examples

Have a look at ExpectySpec.scala and other specs in the same directory.

expecty's People

Contributors

pniederw avatar eed3si9n avatar xuwei-k avatar bsl-zcs avatar dcsobral avatar philippus avatar sethtisue avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.