package cucumber

  1. Overview
  2. Docs
Cucumber BDD for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

cucumber-1.0.4.tbz
sha256=33f76b60aed4aa8789c9cce8647dac6bf60ea9f3071a8096dda456e20f5c8734
sha512=72aa34e95e05740f4205c3468c614dc8691e491ceed3d508cdc64d75549faff48e5587b4629bc515e4d43d7f4c55e00790898171213dd2d504f52253228ace93

Description

Cucumber BDD for OCaml using the gherkin-c library to parse

Published: 03 Apr 2023

README

Cucumber.ml

This implements the core Cucumber feature file language, Gherkin, and associated library for specifying the execution of those scenarios for the OCaml programming language.

libgherkin.so

Libgherkin.so is the C library that Cucumber.ml uses to parse the feature files. This uses a git submodule to bring the gherkin-c library into the current project. This means that you will need to init the submodule after you checkout the repository like so:

git submodule init
git submodule update

or clone the repository with --recursive. This will bring the gherkin-c library into the lib directory.

Building

This project uses Dune as its build system. To build the Cucumber library run:

dune build 

This will build and install the Cucumber library into your Opam repository and make it available to ocamlfind.

Overall Structure

Cucumber.ml is a library that is used to create an executable runtime of step definitions. This means that the library assumes that, once execute is called, the library will read the command line arguments for feature files. The user of the library does not need to specify command line options as the library will read them itself to determine what feature files and other things to run.

open Cucumber.Lib

type world = { foo : bool }

let man_state curr_state next_state = 
    match curr_state with
  | Some x ->
     print_endline ("my state is " ^ (string_of_bool x.foo));
     (Some { foo = next_state }, Cucumber.Outcome.Pass)
  | None ->
     print_endline "I have no state";
     (Some { foo = next_state }, Cucumber.Outcome.Pass)
     
(* users can use the pipeline operator *)
let foo = 
  empty
  |> set_dialect Cucumber.Dialect.En
  |> _After
       (fun str ->
         print_endline "After step";
       )
  |> _Before
       (fun str ->
         print_endline "Before step";
       )
  |>
    _Given
      (Re.Perl.compile_pat "a simple (\\w+)")
      (fun state group args ->
        print_endline "Given";
        pass_with_state { foo = true})
  |>
    _When
      (Re.Perl.compile_pat "I run my test")
      (fun state group args ->
        print_endline "When";
        man_state state false)
  |>
    _Then
      (Re.Perl.compile_pat "I should receive the test results")
      (fun state group args ->
        print_endline "Then";              
        man_state state true)            

(* or they can use a list then use a fold function to build up the run 
eg Base.List.fold bar ~init:empty ~f:(fun accum stepdef -> stepdef accum)
*)
let bar = [
    _Given
      (Re.Perl.compile_pat "a simple DocString")
      (fun state group args ->
        print_endline "Given";
        man_state state true);
    _When
      (Re.Perl.compile_pat "I run my test")
      (fun state group args ->
        print_endline "When";
        man_state state false);
    _Then
      (Re.Perl.compile_pat "I should receive the test results")
      (fun state group args ->
        print_endline "Then";              
        man_state state true)
  ]
          
let () =
  execute foo

Feature: Test Example

Scenario: A passing scenario
 Given a simple true
 When I run my test
 Then I should receive the test results

See the test/test.ml and test/test.feature files for more information.

Once the executable has been built (see the Makefile for an instance of building the test module), you can run the tests. For instance,

dune exec -- cucumber test/test.feature

This will report back using the compact notation for Cucumber (dots for pass, F or fail, P for pending, and U for undefined).

Dependencies (4)

  1. cmdliner >= "1.1"
  2. base >= "v0.15.1"
  3. re >= "1.9.0"
  4. dune >= "3.2"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.