-
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 background-setup-only rule (#64)
* add background-setup-only rule * add background-setup-only rule
- Loading branch information
Showing
17 changed files
with
111 additions
and
15 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,35 @@ | ||
import { switchOrSeveritySchema } from '../schemas' | ||
import Schema from '../schema' | ||
import Rule from '../rule' | ||
import { RawSchema, AcceptedSchema } from '../types' | ||
import Document from '../document' | ||
|
||
export default class BackgroundSetupOnly implements Rule { | ||
public readonly name: string = 'background-setup-only' | ||
|
||
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.background) { | ||
return | ||
} | ||
|
||
child.background.steps.forEach((step): void => { | ||
if (!['Given', '*'].includes(step.keyword.trim())) { | ||
document.addError( | ||
this.name, | ||
`Background should only be used for set up. Found "${step.keyword.trim()}".`, | ||
step.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
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 @@ | ||
Feature: Background Setup Only | ||
|
||
Scenario: Invalid | ||
Given the following feature file | ||
""" | ||
Feature: Invalid | ||
Background: One | ||
Given I set something up | ||
Then something should be set up | ||
And I confirm it was set up | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"background-setup-only": "error"} | | ||
Then there is 1 file with errors | ||
And the errors are | ||
| location | severity | rule | message | | ||
| {"line": 4, "column": 5} | error | background-setup-only | Background should only be used for set up. Found "Then". | | ||
| {"line": 5, "column": 5} | error | background-setup-only | Background should only be used for set up. Found "And". | | ||
|
||
Scenario: Valid | ||
Given the following feature file | ||
""" | ||
Feature: Valid | ||
Background: One | ||
Given I set something up | ||
Scenario: | ||
When I do something | ||
Then something has been done | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"background-setup-only": "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
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
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
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
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
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
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