Search code examples
symfonybehat

Behat stopped generating regular expressions for method stubs


I've started working with Behat for behavioural testing.

I managed to set behat up for my Symfony2 project, started writing scenarios. I was happy with Behat giving me method stubs with regexp to fill in that'd correspond to the steps in my scenarios.

However, after a while, Behat stopped generating regular expressions and is giving me stub methods like this:

/**
 * @Given I am on the page :arg1  <-- this is what I get
 */
public function iAmOnThePage($arg1)
{
    throw new PendingException();
}

I'd rather have it work like befor, e.g.:

/**
 * @Given /^I open "([^"]*)"$/ <--- I'd expect this
 */
public function iOpen($arg1, $sessionName=null)
{
    $this->getSession($sessionName)->visit($arg1);
}

I must have messed somtehing up as I went, but have no idea why the default behaviour changes all of a sudden.

Any suggestions?


Solution

  • Did you update your version of Behat ? In version 3 it's with the :arg and in v2.5 it's with the regex expressions.

    If you like the old way of working you can follow the manual .

    Implementing the SnippetAcceptingContext interface tells Behat that your context is expecting snippets to be generated inside it. Behat will generate simple pattern snippets for you, but if regular expressions are your thing, Behat can generate them instead if you implement Behat\Behat\Context\CustomSnippetAcceptingContext interface instead and add getAcceptedSnippetType() method returning string "regex":

    public static function getAcceptedSnippetType()
    {
        return 'regex';
    }