Running single scenarios in Behat

A simple way to run a work-in-progress scenario in Behat.

Running tagged tests

Behat is a “php framework for autotesting your business expectations” and as any test suite it packs a degree of flexibility to run specific tests (“scenarios” in Gherkin terms) that represent a group of related features.
Where Codeception allows running a single test method in a test case like this:

codecept run tests/some-suite/SomeTest.php:someTest

Behat allows running all scenarios, or features, tagged in a specific way like this:

behat --tags someTag

If I had the 4 scenarios below in a some-feature.feature file:

Feature: different users can see different stuff

Background:
    Given the site is pre-filled
    And there is a user for each role

@visitor
Scenario: visitors can see public posts
    Given I am a visitor
    When I visit '/'
    Then I should see 'Public Post'

@visitor
Scenario: visitors cannot see subscriber posts
    Given I am a visitor
    When I visit '/'
    Then I should not see 'Subscriber Post'

@subscriber
Scenario: visitors cannot public posts
    Given I am a subscriber
    When I visit '/'
    Then I should see 'Public Post'

@subscriber
Scenario: visitors cannot see subscriber posts
    Given I am a subscriber
    When I visit '/'
    Then I should see 'Subscriber Post'

Running behat --tags visitor will run the first two scenarios while running behat --tag @subscriber will run the last two.

Running a single scenario

Running a single scenario, like the one I’m working on, is then as easy as tagging it:

Feature: different users can see different stuff

Background:
    Given the site is pre-filled
    And there is a user for each role

@visitor
Scenario: visitors can see public posts
    Given I am a visitor
    When I visit '/'
    Then I should see 'Public Post'

@visitor
Scenario: visitors cannot see subscriber posts
    Given I am a visitor
    When I visit '/'
    Then I should not see 'Subscriber Post'

@subscriber
Scenario: subscribers can see public posts
    Given I am a subscriber
    When I visit '/'
    Then I should see 'Public Post'

@subscriber
Scenario: subscribers can see subscriber posts
    Given I am a subscriber
    When I visit '/'
    Then I should see 'Subscriber Post'

@subscriber @current
Scenario: subscribers cannot see premium posts
    Given I am a subscriber
    When I visit '/'
    Then I should not see 'Premium Post'

I like to use the current tag but that really is a matter of preference as long as the tag name is used in the command like

behat --tags current

This is especially useful when running all the scenarios and all the features might take a long time.
Once the scenario is no more the current one it’s a matter of removing the current tag and moving on.

I appreciate your input