-
-
Notifications
You must be signed in to change notification settings - Fork 95
Description
In this PR, we toyed with the idea of having placeholders in scenario outline titles.
Why did this come up?
Currently, we distinguish between scenarios (aka "examples") of a scenario outline by appending a number to the title. This causes a problem when specific examples are rerun - if you rerun all examples except the first, the first example that is ran will be suffixed with " #1" even though it is actually the 2nd example in the feature file.
Conceptually it is actually the first, but in practice, that's not useful to users. See: Behat/Behat#1448
Options
- keeping it as is :)
Passing number results in another number #1 Passing number results in another number #2 Passing number results in another number #3 - appending the example values instead (was the main scope of that PR, btw):
Passing number results in another number (input: 2, output: 2) Passing number results in another number (input: 2.4, output: 2) Passing number results in another number (input: 2.5, output: 3) - replacing placeholders (assume the original title was
Passing <input> results in <output>:Concise, readable and simple. :)Passing 2 results in 2 Passing 2.4 results in 2 Passing 2.5 results in 3 - like 3, but adding numbers to duplicate titles (see also question 3 below), with title
Results in <result>:This would/may provide a backward-compatible upgrade path.Results in 2 #1 Results in 2 #2 Results in 3
Apparently, option 3 is already implemented in cucumber, and has been requested in the past.
Open Questions (for Option 3)
-
Should we expose placeholder replacement in
ExampleNode? As a behat user, I would have found that useful in the past, as a behat contributor, it would have been useful in Display outline values instead of index in junit output Behat#1459. -
We have
getTitleandgetOutlineTitle. What would be the best way to implement placeholder replacement? My current opinion:getTitle- this feels like it should return the definitive title, e.g. to be shown in reports and so on. In the ideal world, I think this should be the one replacing placeholders and adding numbers for deduplication.getOutlineTitle- Internally (e.g. even in gherkin), it seems that there shouldn't be a concept of a scenario outline - instead they should be flattened into regular scenarios. With that in mind, I think the "outline title" should be the original (parent?) title - since that parent is the "scenario outline".getOutlineTitleWithPlaceholders(additional method) - I would go for such a method if we want to be absolutely BC safe. That said, I do feel that the majority of end users would rather have the BC break than the current approach, but that's my hypothesis.
It's important to note that
getTitleis already used extensively and changing it might break things. -
Not a question per se, but we're considering numbering repeated titles, this would preserve the past behaviour and avoid duplication given titles with missing placeholders.
- That does beg the question of how an ExampleNode would find that its title has been duplicated elsewhere.
@acoulton On point 2, this approach could work, but I'm not too fond of it:
public function getTitle(?bool $raw = null): string {
if ($raw === null) {
@trigger_error('You must specify if you want the raw title or not, in the future this will change to FALSE', E_USER_DEPRECATED);
$raw = true;
}
return $raw
? $this->title
: $this->normaliseTitle($this->title); // normalise replaces placeholders and adds numbering
}