Git Product home page Git Product logo

asciidoctor-gherkin-extension's Introduction

asciidoctor-gherkin-extension

You can use this extension to include your gherkin feature files in asciidoc in the form of sections, paragraphs, lists and tables.

The conversion is based on a simple, customizable erb template.

Usage

The following feature

simple.feature
Feature: A simple feature
  This is the feature description.

  Background: Background
    Given a simple background step.

  Scenario: Scenario title
    Given a simple scenario step
    When I render the asciidoctor content to html
    Then my feature gets nicely formatted in html.

can be included via the gherkin block macro :

gherkin::./simple.feature[]

and gets rendered into a 3rd level section with subsections :

Corresponding intermediate asciidoc source
=== A simple feature

This is the feature description.

==== Background

[.step-list]
* *Given* a simple background step.

==== Scenario title

[.step-list]
* *Given* a simple scenario step
* *When* I render the asciidoctor content to html
* *Then* my feature gets nicely formatted in html.

If the 3rd level section doesn’t match the section level at the point where you want to include your feature file, you can adjust the section level via the :leveloffset: attribute.

:leveloffset: -1
gherkin::./simple.feature[]
:leveloffset: +1

Or just create your own template.

See the integration tests for a complete maven example.

Formatting tables

You can add some asciidoctor formatting to tables, e.g. column widths, header style, etc.

For example, the following gherkin table

  Given a complex background step with table with header
    #cols=".<2,.^5,^.>3",options="header"
    #cells=h,h,h
    | Header Cell 1            | Header Cell 2          | Header Cell 3 |
    #cells=,m,
    | Cell 1 Row 1             | Cell 2 Row 1 monospace | Cell 3 Row 1  |
    | Cell 1 Row 2 with *bold* | Cell 2 Row 2           | Cell 3 Row 2  |

renders as asciidoctor equivalent :

[.step-list]
* *Given* a complex background step with table with header
+
[cols=".<2,.^5,^.>3",options="header"]
|====
h| Header Cell 1 h| Header Cell 2 h| Header Cell 3
| Cell 1 Row 1 m| Cell 2 Row 1 monospace | Cell 3 Row 1
| Cell 1 Row 2 with *bold* | Cell 2 Row 2 | Cell 3 Row 2
|====

If the first comment of the first row starts with "cols=", then the content of the comment gets placed between brackets right before the table.

Row comments starting with "cells=" get split on "," and become cell formatters.

Custom templates

You can use the template attribute to specify a custom erb template. The attribute value is used as a relative file path, resolved using the docdir attribute as base directory. The template receives a hash called feature containing the feature elements (scenarios, steps, examples, docstrings etc.).

Here is an example of a custom template rendering a table with one row per scenario :

mytemplate.erb
.<%= feature['name'] %>
|====
<%if feature.key?('scenarios') %><% feature['scenarios'].each do |scenario| %>| <%= scenario['name'] %>
<% end %>
<% else %>
| Nothing to show.
<% end %>
|====

assuming you place this template in the same directory as your asciidoc file, the following asciidoc content

gherkin::./simple.feature[template=mytemplate.erb]

//or this : (template is the first positional attribute)

gherkin::./simple.feature[mytemplate.erb]

would render like

Table 1. My feature title

Scenario title1

Scenario title2

Character Encoding

You can use attributes to define the encoding for reading the template file and the feature file.

You can define these attributes either in the block macro or at the document level.

template-encoding

Used to read the custom template file if specified.

encoding

Used to read the feature file.

Defining feature encoding
gherkin::./simple.feature[encoding=UTF-8]

asciidoctor-gherkin-extension's People

Contributors

domgold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

asciidoctor-gherkin-extension's Issues

Add converter from AsciiDoc to Gherkin

To complement the existing converter (Gherkin to AsciiDoc), it would be helpful to be able to convert from AsciiDoc to Gherkin. Supporting this complementary converter would allow spec definitions to be written in AsciiDoc and converted into executable tests, either once or as part of the automated build pipeline. It would also encourage us to think about the best semantic structure for defining features and related stories in AsciiDoc.

Asciidoctor output becomes garbled with empty Background

Description

According to the https://cucumber.io/docs/gherkin/reference it is possible to have no text after the tag background. The example below is taken from the just mentioned website.

Feature: Multiple site support
  Only blog owners can post to a blog, except administrators,
  who can post to all blogs.

  Background:
    Given a global administrator named "Greg"
    And a blog named "Greg's anti-tax rants"
    And a customer named "Dr. Bill"
    And a blog named "Expensive Therapy" owned by "Dr. Bill"

Result
asciidoctor output results in e.g.

====

This indicates an empty section text. In for example a pdf the output becomes garbled and unreadible.

Expected Result
When no text after tag Background is present, then put the text e.g. "==== Background" in the output.

Workaround:
Always add text after the tag Background.

Background: The background
   Given a global administrator named "Greg"
    And a blog named "Greg's anti-tax rants"

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.