Cucumber: Creating first feature file

in #development8 years ago

What is a feature?

Think of it as an small subset of related functionality, working pieces that like lego play a role in a more bigger project.
If you remember the project we are going to be working on, a feature pretty much will handle the CRUD of a coin. On the other hand we can have a feature that gather information about coin.

To be able to continue in this journey I will be working on a product that will help me track my coins collection and will allow me to get more information about each coin.
I would like to have something to enter few words and upload few pictures of my coin.
I would like some sort of fetch data that will look into more details of that coin.
Every coin will have some data elements like:
country: USA
value: 10 cents
metal(s): gold
market value: $300 USD
Year: 1835

To this point there are many missing technological decisions, assumptions and the developer syndrome ( I know it I'm a developer). So what am I talking about, well usually developers want to get into coding as soon as possible. They might reflect past experiences usually bad ones that are time and tight budget related. They most likely want to hurry up and get a working product/piece/prototype or whatever to make the client happy. I fully understand it at this point but remember the client want something that he is not totally sure on how to get it.

The best practice so far is to start retrieving the client requirements and try to make them as clear as possible and also try to transmit that knowledge to the collaborators in the project.

Stop to think about what we know so far

The client wants some sort of input mechanism to enter / type few details about the coin and then load it / save it somewhere with much more details and info that was gathered.

Did you notice that I actually cheat on that requirement?

I'm using some words that are simple and easy for the client to understand, but knowing my development background I guess you might thought something like this:

I need to create a form that lets the user type in a search field the words related with the coin and save the results in a database maybe MySQL once all the required fields where filled.

At this point you are not following the TDD process, we need to clarify the requirements and test it, to make sure it is what the client really meant.

How do we do that?

Common language, Acceptance Tests ( Automated Acceptance Tests ) and living documentation, all provided by Cucumber.

# Author: raserrano
Feature: User can add coin

  Scenario: User add coin with basic attributes
    Given basic attributes of coin are added
    When the coin is going to be saved
    Then coin has been stored


I come up with this feature and I will go a head and show it to my client to see what is the feedback.

  • What are the basic attributes?
  • How many attributes can I use for the coin?
  • Where is the coin saved?
  • How are you storing the coin?

Those are very valid question and I believe there should be more. We will not change the feature just yet, because I want to have a working piece of software (That's what the develop will think).

I will present you the steps I made to have this feature working and not bother much about the coding. This will explain why is important to have client feedback and develop what he needs and not what we think he needs.

Given("basic attributes of coin are added") do
  @coin = "{name:''}"
end

When("the coin is going to be saved") do
  `echo #{@coin} >> coin.js`  
end

Then("coin has been stored") do
  `cat coin.js`
end

As you can see in this example I'm creating the 'software' agreed upon the requirements documented in the feature file, and that does not mean they are correct or work for all the cases. For now I'll just share the results of running the tests or living documentation. In the next post we will improve the code for other use cases that we are missing or have not think of yet.

Selection_055.png

The changes performed in this post are located in the level1 branch and will be merged into develop
My idea is that you could enjoy all the history of the progress in develop branch.

Feel free to leave comments, questions and if you like you can send me PR in Github.


Github repository to checkout the progress
https://github.com/raserrano/cucumber-tdd

Cucumber related posts:

Sort:  

You just planted 0.14 tree(s)!


Thanks to @raserrano

We have planted already 3467.85 trees
out of 1,000,000


Let's save and restore Abongphen Highland Forest
in Cameroonian village Kedjom-Keku!
Plant trees with @treeplanter and get paid for it!
My Steem Power = 19234.76
Thanks a lot!
@martin.mikes coordinator of @kedjom-keku
treeplantermessage_ok.png

Congratulations @raserrano! You have received a vote as part of @raserrano donation to this project.
I will be able to help more #minnows

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.081
BTC 61240.63
ETH 1620.29
USDT 1.00
SBD 0.42