-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend support for 'rule' sections in features
- Loading branch information
Markus Mueller
committed
Mar 18, 2021
1 parent
06cf438
commit 88faaeb
Showing
14 changed files
with
423 additions
and
99 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
examples/typescript/specs/features/extended-rules-auto-step-binding.feature
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: Vending machine | ||
|
||
Rule: Dispenses items if correct amount of money is inserted | ||
|
||
Scenario: Selecting a snack | ||
Given the vending machine has "Maltesers" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Maltesers" | ||
Then my "Maltesers" should be dispensed | ||
|
||
Scenario Outline: Selecting a beverage | ||
Given the vending machine has "<beverage>" in stock | ||
And I have inserted the correct amount of money | ||
When I select "<beverage>" | ||
Then my "<beverage>" should be dispensed | ||
|
||
Examples: | ||
| beverage | | ||
| Cola | | ||
| Ginger ale | | ||
|
||
Rule: Returns my money if item is out of stock | ||
|
||
Scenario: Selecting a snack | ||
Given the vending machine has no "Maltesers" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Maltesers" | ||
Then my money should be returned | ||
|
||
Scenario: Selecting a beverage | ||
Given the vending machine has no "Cola" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Cola" | ||
Then my money should be returned |
34 changes: 34 additions & 0 deletions
34
examples/typescript/specs/features/extended-rules-definition.feature
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: Vending machine | ||
|
||
Rule: Dispenses items if correct amount of money is inserted | ||
|
||
Scenario: Selecting a snack | ||
Given the vending machine has "Maltesers" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Maltesers" | ||
Then my "Maltesers" should be dispensed | ||
|
||
Scenario Outline: Selecting a beverage | ||
Given the vending machine has "<beverage>" in stock | ||
And I have inserted the correct amount of money | ||
When I select "<beverage>" | ||
Then my "<beverage>" should be dispensed | ||
|
||
Examples: | ||
| beverage | | ||
| Cola | | ||
| Ginger ale | | ||
|
||
Rule: Returns my money if item is out of stock | ||
|
||
Scenario: Selecting a snack | ||
Given the vending machine has no "Maltesers" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Maltesers" | ||
Then my money should be returned | ||
|
||
Scenario: Selecting a beverage | ||
Given the vending machine has no "Cola" in stock | ||
And I have inserted the correct amount of money | ||
When I select "Cola" | ||
Then my money should be returned |
40 changes: 40 additions & 0 deletions
40
examples/typescript/specs/step-definitions/extended-rules-auto-step-binding.steps.ts
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,40 @@ | ||
import { StepDefinitions, loadFeature, autoBindStepsWithRules } from '../../../../src'; | ||
import { VendingMachine } from '../../src/vending-machine'; | ||
|
||
export const vendingMachineSteps: StepDefinitions = ({ given, and, when, then }) => { | ||
let vendingMachine: VendingMachine; | ||
|
||
const myMoney = 0.50; | ||
|
||
given(/^the vending machine has "([^"]*)" in stock$/, (itemName: string) => { | ||
vendingMachine = new VendingMachine(); | ||
vendingMachine.stockItem(itemName, 1); | ||
}); | ||
|
||
given(/^the vending machine has no "([^"]*)" in stock$/, (itemName: string) => { | ||
vendingMachine = new VendingMachine(); | ||
vendingMachine.stockItem(itemName, 0); | ||
}); | ||
|
||
and('I have inserted the correct amount of money', () => { | ||
vendingMachine.insertMoney(myMoney); | ||
}); | ||
|
||
when(/^I select "(.*)"$/, (itemName: string) => { | ||
vendingMachine.dispenseItem(itemName); | ||
}); | ||
|
||
then(/^my money should be returned$/, () => { | ||
const returnedMoney = vendingMachine.moneyReturnSlot; | ||
expect(returnedMoney).toBe(myMoney); | ||
}); | ||
|
||
then(/^my "(.*)" should be dispensed$/, (itemName: string) => { | ||
const inventoryAmount = vendingMachine.items[itemName]; | ||
expect(inventoryAmount).toBe(0); | ||
}); | ||
}; | ||
|
||
const feature = loadFeature('./examples/typescript/specs/features/extended-rules-auto-step-binding.feature', {collapseRules: false}); | ||
|
||
autoBindStepsWithRules([feature], [ vendingMachineSteps ]); |
85 changes: 85 additions & 0 deletions
85
examples/typescript/specs/step-definitions/extended-rules-definition.steps.ts
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,85 @@ | ||
import { loadFeature, defineRuleBasedFeature } from '../../../../src'; | ||
import { DefineStepFunction } from '../../../../src/feature-definition-creation'; | ||
import { VendingMachine } from '../../src/vending-machine'; | ||
|
||
const feature = loadFeature('./examples/typescript/specs/features/extended-rules-definition.feature', {collapseRules: false}); | ||
|
||
defineRuleBasedFeature(feature, (rule) => { | ||
let vendingMachine: VendingMachine; | ||
|
||
const myMoney = 0.50; | ||
|
||
const givenTheVendingMachineHasXInStock = (given: DefineStepFunction) => { | ||
given(/^the vending machine has "([^"]*)" in stock$/, (itemName: string) => { | ||
vendingMachine = new VendingMachine(); | ||
vendingMachine.stockItem(itemName, 1); | ||
}); | ||
}; | ||
|
||
const givenTheVendingMachineHasNoXInStock = (given: DefineStepFunction) => { | ||
given(/^the vending machine has no "([^"]*)" in stock$/, (itemName: string) => { | ||
vendingMachine = new VendingMachine(); | ||
vendingMachine.stockItem(itemName, 0); | ||
}); | ||
} | ||
|
||
const givenIHaveInsertedTheCorrectAmountOfMoney = (given: DefineStepFunction) => { | ||
given('I have inserted the correct amount of money', () => { | ||
vendingMachine.insertMoney(myMoney); | ||
}); | ||
}; | ||
|
||
const whenISelectX = (when: DefineStepFunction) => { | ||
when(/^I select "(.*)"$/, (itemName: string) => { | ||
vendingMachine.dispenseItem(itemName); | ||
}); | ||
}; | ||
|
||
const thenXShouldBeDespensed = (then: DefineStepFunction) => { | ||
then(/^my "(.*)" should be dispensed$/, (itemName: string) => { | ||
const inventoryAmount = vendingMachine.items[itemName]; | ||
expect(inventoryAmount).toBe(0); | ||
}); | ||
} | ||
|
||
const thenMyMoneyShouldBeReturned = (then: DefineStepFunction) => { | ||
then(/^my money should be returned$/, () => { | ||
const returnedMoney = vendingMachine.moneyReturnSlot; | ||
expect(returnedMoney).toBe(myMoney); | ||
}); | ||
} | ||
|
||
rule("Dispenses items if correct amount of money is inserted", (test) => { | ||
|
||
test('Selecting a snack', ({ given, and, when, then }) => { | ||
givenTheVendingMachineHasXInStock(given); | ||
givenIHaveInsertedTheCorrectAmountOfMoney(given); | ||
whenISelectX(when); | ||
thenXShouldBeDespensed(then); | ||
}); | ||
|
||
test('Selecting a beverage', ({ given, and, when, then }) => { | ||
givenTheVendingMachineHasXInStock(given); | ||
givenIHaveInsertedTheCorrectAmountOfMoney(given); | ||
whenISelectX(when); | ||
thenXShouldBeDespensed(then); | ||
}); | ||
}); | ||
|
||
rule("Returns my money if item is out of stock", (test) => { | ||
|
||
test('Selecting a snack', ({ given, and, when, then }) => { | ||
givenTheVendingMachineHasNoXInStock(given); | ||
givenIHaveInsertedTheCorrectAmountOfMoney(given); | ||
whenISelectX(when); | ||
thenMyMoneyShouldBeReturned(then); | ||
}); | ||
|
||
test('Selecting a beverage', ({ given, and, when, then }) => { | ||
givenTheVendingMachineHasNoXInStock(given); | ||
givenIHaveInsertedTheCorrectAmountOfMoney(given); | ||
whenISelectX(when); | ||
thenMyMoneyShouldBeReturned(then); | ||
}); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.