2017 © Pedro Peláez
 

library behat-spec

Behat and PhpSpec integration

image

rmiller/behat-spec

Behat and PhpSpec integration

  • Monday, February 27, 2017
  • by mr_r_miller
  • Repository
  • 6 Watchers
  • 47 Stars
  • 20,172 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 5 Forks
  • 7 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

BehatSpec

Scrutinizer Code Quality Build Status, (*1)

What

Integration between Behat and PhpSpec., (*2)

  • Creates specs for any missing classes encountered when running behat
  • Adds examples for any missing methods encountered when running behat
  • Executes the phpspec run command after this to add the described class/method

Why

This is useful when rather than using the Behat context to run an application through its UI, it is instead used to implement the domain model. For more information on this way of using Gherkin features to drive domain modelling read Everzet's post on Modelling by Example, (*3)

When running a feature with a Context that contains a new class that does not exist or a method you will get a fatal error. If using PhpSpec the next step would be to start specifying that class using the describe command. This set of extensions provides integration between Behat and PhpSpec so that instead of a fatal error you can choose to run the describe command for the missing class automatically., (*4)

It also uses my ExemplifyExtension so that you can automatically add examples for missing methods in a similar way., (*5)

After describing a class or method in this way the phpspec run command can be used to automatically create the class or model. Since this is the typical next step in most cases, this extension automates that by asking you if you would like to do that next., (*6)

An Example

So to use an example from the blog post linked above:, (*7)

/**
 * @Given a product named :name and priced £:price was added to the catalogue
 */
public function aProductNamedAndPricedWasAddedToTheCatalogue($name, Money $price)
{
    $aProduct = Product::namedAndPriced($name, $price);
    $this->catalogue->add($aProduct);
}

Running the feature relating to this context would result in a fatal exception normally. Instead you get a simple error and the offer to create a spec for the missing class:, (*8)

Product not found, (*9)

The spec is created followed by an offer to run phpspec run:, (*10)

Spec created, (*11)

Which asks to create the class:, (*12)

Created Product?, (*13)

Product created, (*14)

Running Behat again will result in a similar process for the namedAndPriced method. Where an example for the method will be added to the spec and the method added to the class., (*15)

How

Installation

This package provides an extension for PhpSpec and an extension for Behat. Both need to be enabled for the full functionality., (*16)

Requires:, (*17)

  • Behat 3.0+
  • PhpSpec 3.0+
  • PHP 5.6+

Require the extension:, (*18)

$ composer require --dev rmiller/behat-spec:^0.5

In order to use BehatSpec with PHPSpec 2.0 series, use 0.3.* version series:, (*19)

$ composer require --dev rmiller/behat-spec:0.3.*

To get the phpspec run command running, you need to use latest phpspec >2.1. Otherwise that functionality will silently fail., (*20)

Configuration

Activate the Behat extension by specifying its class in your behat.yml:, (*21)

# behat.yml
# ...
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\BehatExtension:
        path:  bin/phpspec #default value is bin/phpspec
        config:  path/to/phpspec.yml #optional

Activate the PhpSpec extension by specifying its class in your phpspec.yml:, (*22)

# phpspec.yml
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~

Additional configuration can be provided for the running of the phpspec run command:, (*23)

It defaults to bin/phpspec for the path of phpspec and to run after the describe command. These can be overridden as follows:, (*24)

# phpspec.yml
rerunner:
    path: vendor/bin/phpspec
    commands: [describe, exemplify, your_own_fancy_command]
    config: path/to/phpspec.yml #optional

extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~

Some Details

This package pulls together some other PhpSpec and Behat extensions which can also be used standalone:, (*25)

PhpSpec

Behat

The Versions

27/02 2017

dev-master

9999999-dev https://github.com/richardmiller/BehatSpec

Behat and PhpSpec integration

  Sources   Download

MIT

The Requires

 

bdd specbdd storybdd

17/02 2017

dev-fix-exemplify-tests

dev-fix-exemplify-tests https://github.com/richardmiller/BehatSpec

Behat and PhpSpec integration

  Sources   Download

MIT

The Requires

 

bdd specbdd storybdd

27/01 2017

0.5.0

0.5.0.0 https://github.com/richardmiller/BehatSpec

Behat and PhpSpec integration

  Sources   Download

MIT

The Requires

 

bdd specbdd storybdd

24/01 2017

0.4.0

0.4.0.0 https://github.com/richardmiller/BehatSpec

Behat and PhpSpec integration

  Sources   Download

MIT

The Requires

 

bdd specbdd storybdd

24/01 2017

0.4.1

0.4.1.0 https://github.com/richardmiller/BehatSpec

Behat and PhpSpec integration

  Sources   Download

MIT

The Requires

 

bdd specbdd storybdd