-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scenario-action and scenario-verification rules
- Loading branch information
Carl Markham
committed
Sep 29, 2024
1 parent
bbf9be7
commit b32797c
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { switchOrSeveritySchema } from '../schemas' | ||
import Schema from '../schema' | ||
import Rule from '../rule' | ||
import { RawSchema, AcceptedSchema } from '../types' | ||
import Document from '../document' | ||
|
||
export default class ScenarioAction implements Rule { | ||
public readonly name: string = 'scenario-action' | ||
|
||
public readonly acceptedSchema: AcceptedSchema = switchOrSeveritySchema | ||
|
||
public readonly schema: Schema | ||
|
||
public constructor(rawSchema: RawSchema) { | ||
this.schema = new Schema(rawSchema) | ||
} | ||
|
||
public async run(document: Document): Promise<void> { | ||
document.feature.children.forEach((child) => { | ||
if (!child.scenario) { | ||
return | ||
} | ||
|
||
const whens = child.scenario.steps.filter((s) => s.keyword.trim() === 'When') | ||
if (whens.length === 0) { | ||
document.addError(this.name, 'Scenario should contain a "When" to denote an action.', child.scenario.location) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { switchOrSeveritySchema } from '../schemas' | ||
import Schema from '../schema' | ||
import Rule from '../rule' | ||
import { RawSchema, AcceptedSchema } from '../types' | ||
import Document from '../document' | ||
|
||
export default class ScenarioVerification implements Rule { | ||
public readonly name: string = 'scenario-verification' | ||
|
||
public readonly acceptedSchema: AcceptedSchema = switchOrSeveritySchema | ||
|
||
public readonly schema: Schema | ||
|
||
public constructor(rawSchema: RawSchema) { | ||
this.schema = new Schema(rawSchema) | ||
} | ||
|
||
public async run(document: Document): Promise<void> { | ||
document.feature.children.forEach((child) => { | ||
if (!child.scenario) { | ||
return | ||
} | ||
|
||
const whens = child.scenario.steps.filter((s) => s.keyword.trim() === 'Then') | ||
if (whens.length === 0) { | ||
document.addError( | ||
this.name, | ||
'Scenario should contain a "Then" to denote verification of an action.', | ||
child.scenario.location, | ||
) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: Feature Description | ||
|
||
Scenario: Invalid | ||
Given the following feature file | ||
""" | ||
Feature: Invalid | ||
Scenario: Doing something | ||
Given I do something | ||
Then I should have done something | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"scenario-action": "error"} | | ||
Then there is 1 file with errors | ||
And the errors are | ||
| location | severity | rule | message | | ||
| {"line": 2, "column": 3} | error | scenario-action | Scenario should contain a "When" to denote an action. | | ||
|
||
Scenario: Valid | ||
Given the following feature file | ||
""" | ||
Feature: Valid | ||
Scenario: Doing something | ||
When I do something | ||
Then I should have done something | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"scenario-action": "error"} | | ||
Then there are 0 files with errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: Feature Description | ||
|
||
Scenario: Invalid | ||
Given the following feature file | ||
""" | ||
Feature: Invalid | ||
Scenario: Doing something | ||
When I do something | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"scenario-verification": "error"} | | ||
Then there is 1 file with errors | ||
And the errors are | ||
| location | severity | rule | message | | ||
| {"line": 2, "column": 3} | error | scenario-verification | Scenario should contain a "Then" to denote verification of an action. | | ||
|
||
Scenario: Valid | ||
Given the following feature file | ||
""" | ||
Feature: Valid | ||
Scenario: Doing something | ||
When I do something | ||
Then I should have done something | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"scenario-verification": "error"} | | ||
Then there are 0 files with errors |