Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringDocs causes autoBindSteps to map incorrectly #163

Open
tonirecio opened this issue Oct 6, 2022 · 3 comments
Open

stringDocs causes autoBindSteps to map incorrectly #163

tonirecio opened this issue Oct 6, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@tonirecio
Copy link

First of all, thanks to all of you for collaborating in the creation and maintenance of this great library.

I wanted to share with you a problem I'm experiencing with autoBindSteps.

Here is an example of a scenario from the Minesweeper game:

Scenario: Uncovering a cell with a mine - Losing the game
  Given the player loads the following mock data:
  """
  | * | o |
  """
  When the player uncovers the cell (1,1)
  Then the player should lose the game

As you can see I use a DocString in the Given to express more visually the representation of the cells.

It works well, but if I try to use autoBindSteps, doesn't find the related functions.

If I remove the DocString with a simple string, like this:

Scenario: Uncovering a cell with a mine - Losing the game
  Given the player loads the following mock data: *o

  When the player uncovers the cell (1,1)
  Then the player should lose the game

The autoBindSteps works well.

I think I am either doing something wrong, or there is some kind of issue in the code.

Can someone help me with this?

Thanks in advance!

@tonirecio
Copy link
Author

I created an example test to isolate the problem, and thanks to it, I saw that a repeated step caused my error. By changing the docString, the interface changed, and duplicates were no longer produced. That's why I related the problem to the docString. Mea culpa**, I'm so sorry.**

That said, now that I see that the error is mine, I would like to propose an improvement; when a scenario is duplicated and we are using autoBinSteps, I propose to show an error indicating this situation, instead of the current behavior, the message that appears in the console is precisely the opposite, related to the lack of steps.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Mar 28, 2024
@pplancq
Copy link
Contributor

pplancq commented Mar 28, 2024

I've just tested, and autoBindSteps doesn't detect the duplication of steps, and the error message indicates a missing step, which can mislead the user.

Step to reproduce the problem.

  1. in the file examples/typescript/specs/step-definitions/auto-binding/auto-step-binding-beverage-vending.steps.ts duplicate one of the steps
export const vendingMachineSteps: StepDefinitions = ({ given, and, when, then }) => {
  let vendingMachine: VendingMachine;

  given(/^the vending machine has "(.*)" in stock$/, (itemName: string) => {
    vendingMachine = new VendingMachine();
    vendingMachine.stockItem(itemName, 1);
  });

  /: steps duplicate
  given(/^the vending machine has "(.*)" in stock$/, (itemName: string) => {
    vendingMachine = new VendingMachine();
    vendingMachine.stockItem(itemName, 1);
  });

  and('I have inserted the correct amount of money', () => {
    vendingMachine.insertMoney(0.5);
  });

  when(/^I purchase "(.*)"$/, (itemName: string) => {
    vendingMachine.dispenseItem(itemName);
  });

  then(/^my "(.*)" should be dispensed$/, (itemName: string) => {
    const inventoryAmount = vendingMachine.items[itemName];
    expect(inventoryAmount).toBe(0);
  });
};
  1. see the error when running the tests
 FAIL  examples/typescript/specs/step-definitions/auto-binding/auto-step-binding-beverage-vending.steps.ts
  ● Test suite failed to run

    Scenario "Purchasing a beverage" has 4 step(s) in the feature file, but 3 step definition(s) defined. Try adding the following code:

    test('Purchasing a beverage', ({ given, and, when, then }) => {
        given(/^the vending machine has (.*) in stock$/, (arg0) => {

        });

        and('I have inserted the correct amount of money', () => {

        });

        when(/^I purchase (.*)$/, (arg0) => {

        });

        then(/^my (.*) should be dispensed$/, (arg0) => {

        });
    });

It might be interesting to see if they can put a more explicit error message.

@bencompton I think we should keep this issue open and tag it bug.

@bencompton bencompton added bug Something isn't working and removed Stale labels Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants