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

Providing steps definitions basic implementation when running a new feature. #58

Open
danielfoxp2 opened this issue Jul 2, 2016 · 4 comments

Comments

@danielfoxp2
Copy link

danielfoxp2 commented Jul 2, 2016

I am trying to learn Elixir. Having some kind of obsessive-compulsive disorder I want to do it in a certain way. This includes cucumber. I look around and found your port of it. Great, made my day and I really appreciate the effort and the work done. So, before anything, thank you.

But I am missing some things that I take for granted, like the features and step_definitions directories, the suggestion of implementation of steps when running a feature without steps definitions, and others little things. In this issue, I will ask about one of this things and make a suggestion/request for another one.

I only have used cucumber.js and SpecFlow, but I already saw original ruby cucumber and all these three work very similar in this regards (i.e. directories names and places and features without step definition implemented).

I looked in the code but, as a beginner, it was hard for me to understand and have the confidence to change it. But, if you let me, I thought a way that I could help and so I created the things below.

Let me know if it's valid or if it's out of concern for White-Bread now and future. Thank you again.

Feature: Steps definitions automatically created

  As a developer using white_bread to specify behaviors of my app
  I want that the step definitions template to be created automatically
  So that I optimize use of time and minimize work done in unimportant tasks focusing 
  in write the specifications and the code needed to comply the acceptance criteria

  Scenario: Execution of a new feature that hasn't any step definition
    Given I create a feature file with two scenarios
    And each scenario has three steps
    When I execute White-Bread for this feature
    Then I should see it fails because no step definitions exist for this feature
    And I should see a possible initial implementation of these steps definitions
    And I should be asked if I want that White-Bread creates these steps definitions

  Scenario: Creation of steps definitions initial implementation 
    Given I executed a feature that has zero step definition implemented
    And I am asked if I want that White-Bread creates these steps definitions
    When I answer yes
    Then a step definition file is created
    And the initial implementation is inserted in the new step definition file
    And I should be informed that the steps definitions were successfully created
    And I should be informed where the file was created

  Scenario: Adding new step in a feature that already has steps definitions implemented
    Given I am editing a feature to add a new step
    When I execute the White-Bread for this feature
    Then I should see the status of the previous steps till the new step
    And I should see the feature fails because the new step is non-implemented
    And I should see the suggested implementation of the new step
    And I should not be asked if I want to automatically create the new step

In SpecFlow, inside Visual Studio, I am able to use the IDE to generate the steps automatically or just copy the steps definitions to clipboard. In cucumber.js, we can see the steps definitions suggestions in the console and we can copy to clipboard too, but manually. With Elixir, I am thinking in use some kind of SpecFlow variation.

The actual behavior of White-Bread when it comes to run features that do not have steps definitions implemented is a kind of misinformation since it shows that the feature passes. So my user story described above can address this misinformation issue too, which is a serendipity welcome gain.

You have your reasons, of course, but why you choose not to follow the behavior of cucumber for ruby when it comes to names and places of directories (i.e. Having a features directory and inside of it the steps definitions directory - named steps_definitions - where all implementation of each step in a feature is placed)?

I am really sorry for any mistake that I probably made writing this. English is another language that I am trying to learn.

Some sources to exemplify myself, I don't know if it is needed hehe...
https://blog.codecentric.de/en/2013/08/cucumber-setup-basics/
https://www.custardbelly.com/blog/blog-posts/2014/01/08/bdd-in-js-cucumberjs/

Cheers.

@danielfoxp2
Copy link
Author

Oh, I forgot to ask/suggest, but did you have tried to reach out cucumber team to show your work and perhaps get some help? I think it would be good to have feedback and even code from them. @aslakhellesoy in this link shows that they are very nice and could join in this effort. It would be very cool have them here to help take White-Bread beyond and maybe even become an official implementation.

Cheers.

@meadsteve
Copy link
Collaborator

Hi @danielfoxp2. Firstly thank you for taking the time to raise an issue. I really appreciate it.

White bread already uses a features directory. Is there something I could do to make this clearer?
Would it help if I added a command like?

mix white_bread.new_feature my_cool_feature 

I added your feature above to a file called features/test.feature then ran mix white_bread.run and the output was:

Default context module not found in features/contexts/default_context.exs.
Create one [Y/n]?
y

then

loading features/contexts/default_context.exs
Execution of a new feature that hasn't any step definition ---> failed
Creation of steps definitions initial implementation ---> failed
Adding new step in a feature that already has steps definitions implemented ---> failed
3 scenario failed for Steps definitions automatically created
  - Execution of a new feature that hasn't any step definition --> undefined step: I create a feature file with two scenarios implement with

given_ ~r/^I create a feature file with two scenarios$/, fn state ->
  {:ok, state}
end

  - Creation of steps definitions initial implementation --> undefined step: I executed a feature that has zero step definition implemented implement with

given_ ~r/^I executed a feature that has zero step definition implemented$/, fn state ->
  {:ok, state}
end

  - Adding new step in a feature that already has steps definitions implemented --> undefined step: I am editing a feature to add a new step implement with

given_ ~r/^I am editing a feature to add a new step$/, fn state ->
  {:ok, state}
end

So it gives the code for the first undefined steps but not all of them. I agree it would be better to create all of them so I've created #59.

As for step definitions I instead used the terminology contexts which I took from another cucumber implementation behat (http://docs.behat.org/en/v3.0/guides/4.contexts.html). I prefer context as it fits better with how I talk about them:

I'm testing feature A in the context of my http API.
I'm testing features A & B in the context of my command line tool.

Do you think there's anything I could do to make the relationship between contexts and step definitions clearer?

I'm currently working on V3 of this tool so now is a good time for any breaking changes to happen.

@danielfoxp2
Copy link
Author

Thanks for your fast reply and action.

About the feature directory: Yes, White-Bread already has it. There is no need to make it clearer and the new command suggestion is not needed too. In fact, your suggestion comes, I think, because my text was not well formed (sorry hehe). I should've explained that I noted the feature directory exist and my focus was on step_definitions directory.

With your explanation about the inspiration coming from behat, now I have a better understanding. But maybe some work on docs would be cool. A .gif or short video showing the simplest configuration in place and white_bread running an example feature could worth a thousand words hehe.

Now about the step definition implementation:
Well, I don't know what I did yesterday that gave me passing feature even if there weren't any implementation for scenarios. Today I replicate the same result that you described above.

In my case, White-Bread is showing every parsed line. Is it normal? Yesterday, after all lines parsed the output was that all feature had passed, today the message shows it failed and the first implementation suggestion (like you described).

loading features/contexts/default_context.exs

02:52:47.536 [debug] Parsing line: "feature: Testing"

02:52:47.536 [debug] Parsing line: "As something "

02:52:47.536 [debug] Parsing line: "I want to do one thing"

02:52:47.536 [debug] Parsing line: "So that I can feel complete"

02:52:47.536 [debug] Parsing line: "Scenario: First Scenario"

02:52:47.536 [debug] Parsing line: "Given I am serious"

02:52:47.538 [debug] Parsing line: "When I make a joke"

02:52:47.538 [debug] Parsing line: "Then nobody laugh"
...

I don't know if I will be able to contribute to #59 because my actual lack of skill, but this feature it is a good thing to White-Bread have.

To make context and step definitions relation clearer, I think that #59 could address it by creating not just only the console output but the context file with those steps definitions implemented if the user wanted it so as this scenario describe it:

Scenario: Creation of steps definitions initial implementation 
    Given I executed a feature that has zero step definition implemented
    And I am asked if I want that White-Bread creates these steps definitions
    When I answer yes
    Then a step definition file is created
    And the initial implementation is inserted in the new step definition file
    And I should be informed that the steps definitions were successfully created
    And I should be informed where the file was created

Thank you again. Do you think this issue can be closed or is better to wait till #59?

Cheers.

@lang100
Copy link

lang100 commented Jan 16, 2017

i totally agree with @mgwidmann,
i dont think its normal to get all these parse lines logs.
is there any way to config it to run without all the logs of the parsed lines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants