Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cornichon

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cornichon

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Cornichon

A cornichon is a fancy gherkin (WIKI)

Cornichon allows you to write pseudo-Gherkin features that will transpile to valid Gherkin. In the process, you can programatically insert content into those features before running your cucumber tests. Now, you can write your acceptance tests to be more configurable, flexible, reusable, dynamic and greatly increase your test coverage!

Installation

Add this line to your application's Gemfile:

gem 'cornichon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cornichon

Quick Start

Add the following files to your project

your_project/
  features/
    cornichon/
      templates/
        quick_start.cornichon
      presenters/
        quick_start.rb
# features/cornichon/templates/quick_start.cornichon

Feature: A very quick start

Scenario: You're never gonna keep me down
  Given I've been knocked down {{several}} times
  Then I get up again
# features/cornichon/presenters/quick_start.rb

def several
  # return a random number between 2 .. 100
  2 + rand(99)
end

Then simply run

bundle exec cornichon

And voilà! you should have a brand new feature file in features/cornichon/features. Now run your cucumber tests!

Usage

Simple values

use {{double braces}} to insert a method value

Template:

# features/cornichon/templates/joke.cornichon

Scenario: A classic pub joke
  Given A {{person}} walks into a bar
  Then expect consequences

Presenter:

# features/cornichon/presenters/joke.rb

def person
  ['Englishman', 'Irishman', 'Scotsman', 'Welshman'].sample
end

Sample Output:

# features/cornichon/features/joke.feature

Scenario: A classic pub joke
  Given A Scotsman walks into a bar
  Then expect consequences

Nested values

use {{dot.separated.keys}} to specify values within a nested hash

Tables

use [[double square brackets]] to insert a table from an array of hashes (or a single hash for a single row table)

Template:

# features/cornichon/templates/nursery_rhyme.cornichon

Scenario Outline: A classic nursery rhyme
  Given I was born on a "<day>"
  Then I should "<expectation>"
  Examples:
  [[mondays_child]]
  

Presenter:

# features/cornichon/presenters/nursery_rhyme.rb

def mondays_child
  [
    {
      'day' => 'Monday'
      'expectation' => 'be fair of face'
    },
    {
      'day' => 'Tuesday'
      'expectation' => 'be full of grace'
    },
    {
      'day' => 'Wednesday'
      'expectation' => 'be full of woe'
    },
    {
      'day' => 'Thursday'
      'expectation' => 'have far to go'
    },
    {
      'day' => 'Friday'
      'expectation' => 'be loving and giving'
    },
    {
      'day' => 'Saturday'
      'expectation' => 'work hard for a living'
    },
    {
      'day' => 'Sunday'
      'expectation' => 'be bonnie and blithe and good and gay'
    }
  ]
end

Sample Output:

# features/cornichon/features/nursery_rhyme.feature

Scenario Outline: A classic nursery rhyme
  Given I was born on a "<day>"
  Then I should "<expectation>"
  Examples:
  | day       | expectation                           |
  | Monday    | be fair of face                       |
  | Tuesday   | be full of grace                      |
  | Wednesday | be full of woe                        |
  | Thursday  | have far to go                        |
  | Friday    | be loving and giving                  |
  | Saturday  | work hard for a living                |
  | Sunday    | be bonnie and blithe and good and gay |

The + sign

use {{+a plus sign}} to refer to the last instance of a key (rather than calling the method again) You may need to use this if your methods do not return the same value on every call

Template:

# features/cornichon/templates/reply.cornichon

Scenario: Being polite
  Given my name is {{name}}
  When someone asks me my name
  Then I would say 'My name is {{+name}}'

Presenter:

# features/cornichon/presenters/reply.rb

def name
  ['Sarah', 'Thomas', 'Michael', 'Jane', 'Fred', 'Kirsty'].sample
end

Sample Output:

# features/cornichon/features/joke.feature

Scenario: Being polite
  Given my name is Jane
  When someone asks me my name
  Then I would say 'My name is Jane'

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 13 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc