anti-test


License

License

MIT
Categories

Categories

Ant Build Tools
GroupId

GroupId

com.al333z
ArtifactId

ArtifactId

anti-test_2.12
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

anti-test
anti-test
Project URL

Project URL

http://github.com/AL333Z/anti-test
Project Organization

Project Organization

com.al333z
Source Code Management

Source Code Management

http://github.com/AL333Z/anti-test

Download anti-test_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.al333z/anti-test_2.12/ -->
<dependency>
    <groupId>com.al333z</groupId>
    <artifactId>anti-test_2.12</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.al333z/anti-test_2.12/
implementation 'com.al333z:anti-test_2.12:0.1.0'
// https://jarcasting.com/artifacts/com.al333z/anti-test_2.12/
implementation ("com.al333z:anti-test_2.12:0.1.0")
'com.al333z:anti-test_2.12:jar:0.1.0'
<dependency org="com.al333z" name="anti-test_2.12" rev="0.1.0">
  <artifact name="anti-test_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.al333z', module='anti-test_2.12', version='0.1.0')
)
libraryDependencies += "com.al333z" % "anti-test_2.12" % "0.1.0"
[com.al333z/anti-test_2.12 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.2
org.typelevel : cats-core_2.12 jar 1.0.1
org.scalatest : scalatest_2.12 jar 3.0.1

Project Modules

There are no modules declared in this project.

What's this?

A POC about BDD, leveraging Functional Programming techniques.

Motivation

In the past we saw (and wrote) really bad code which used cucumber, with tons of global variables, null references, runtime surprises, etc..

This is our attempt to redeem ourselves.

Authors

How

The idea is to offer a DSL which is both lawful and readable.

  val failingScenario = for {
    x <- given("an int")(42)
    y <- and("a string")("bar")
    _ <- when("i'm grumpy")(())
    _ <- assert("i fail")(1 == 2)
  } yield ()

  val happyScenario = for {
    x <- given("an int")(42)
    y <- and("a string")("bar")
    _ <- when("i'm happy")(())
    _ <- assert("i succeed")(1 == 1)
  } yield ()

Looks like a Writer, but we need to also run effects F[_] on each step. So let's move to WriterT, and it's good. Except for failing scenarios, in which we lose the logs.

Let's introduce LoggerT, a WriterT which preserve and combine error logs. How?

  // leveraging a MonadError to combine also error logs
  def flatMap[U](f: V => LoggerT[F, L, U])(implicit
                                           monadErrorFL: MonadError[F, L],
                                           semigroupL: Semigroup[L]): LoggerT[F, L, U] =
    LoggerT {
      monadErrorFL.flatMap(run) { lv =>
        monadErrorFL.handleErrorWith(
          monadErrorFL.map(f(lv._2).run) { lv2 =>
            (semigroupL.combine(lv._1, lv2._1), lv2._2)
          }
        )(errorLog => monadErrorFL.raiseError(semigroupL.combine(lv._1, errorLog)))
      }
    }

Compromise.

Putting a MonadError constraint instead of just FlatMap, and forcing error to have type L. With a MonadError[F, L] in scope, we can combine logs with the current failure.

All the remaining parts are only about offering a nice syntax to the DSL.

Feedback required

The code is really minimal, but effective. Any feedback is more than appreaciated :)

Versions

Version
0.1.0
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1