brian-watkins/elm-spec/2.0.0

NOTE: the latest version is 3.3.2

Spec

Functions for writing specs.

A spec is a collection of scenarios, each of which provides an example that illustrates a behavior belonging to your program. Each scenario follows the same basic plan:

  1. Configure the initial state of the world (and your program).
  2. Perform a sequence of steps.
  3. Check your xpectations about the new state of the world after the steps have been performed.

Here's a sample spec for a browser program called App:

Spec.describe "some part of my system"
[ Spec.scenario "the awesome path" (
    Spec.given (
      Spec.Setup.init (App.init testFlags)
        |> Spec.Setup.withView App.view
        |> Spec.Setup.withUpdate App.update
    )
    |> Spec.when "something happens"
      [ Spec.Markup.target << by [ id "some-button" ]
      , Spec.Markup.Event.click
      ]
    |> Spec.it "does the right thing" (
      Spec.Markup.observeElement
        |> Spec.Markup.query << by [ id "some-words" ]
        |> Spec.expect (Spec.Markup.text <| 
          Spec.Claim.isStringContaining "something awesome"
        )
    )
  )
]

Creating a Spec

type alias Spec model msg =
Spec model msg

Represents the spec.

type Scenario model msg

Represents a particular scenario in a spec.

describe : String -> List (Scenario model msg) -> Spec model msg

Specify a description and a list of scenarios that compose the spec.

scenario : String -> Plan model msg -> Scenario model msg

Create a scenario with a description and a plan.

Creating the Scenario Script

type Script model msg

Represents the setup and steps involved in a scenario.

given : Setup model msg -> Script model msg

Provide the Setup that represents the state of the world at the start of the scenario.

See Spec.Setup for functions to construct this representation.

String
-> List (Context model -> Command msg)
-> Script model msg
-> Script model msg

Specify a description and the steps involved in a scenario.

Each step is a function from Step.Context to Step.Command, but usually you will use steps that are provided by other modules, like Spec.Markup.Event.

You may provide multiple when blocks as part of a scenario.

Turn a Script into a Plan

type Plan model msg

Represents the full plan (setup, steps, expectations) involved in a scenario.

type Expectation model

Represents what should be the case about some part of the world.

Expectations are checked at the end of the scenario, after all steps of the script have been performed.

it : String -> Expectation model -> Script model msg -> Plan model msg

Specify an expectation to be checked once the scenario's steps have been performed.

List (Script model msg -> Plan model msg)
-> Script model msg
-> Plan model msg

Specify multiple expectations to be checked once the scenario's steps have been performed.

expect : Claim a -> Observer model a -> Expectation model

Provide an observer with a claim to evaluate.

Tag a Scenario

tagged : List String -> Scenario model msg -> Scenario model msg

Associate one or more tags with a scenario.

When you run the spec suite with specific tags specified, only the scenarios tagged with those tags will be executed.