Giter VIP home page Giter VIP logo

viacep-cucumber's Introduction

viacep-cucumber

This is my personal project created to apply my programming knowledge. In this project, I validate the ViaCEP public API using cucumber and ruby technologies.

Characteristics

  • It has Gherkin syntax in the features files.
Feature: Search for address

 The ViaCEP public API allows to search for a address using a
 8 digit zip code (e.g., '01001000'). Also the return format
 must be defined, it can be JSON, XML, Querty...

 Scenario: User informs valid zip code
  Given a zip code search
  And a value of <zipcode>
  And the return format of "json"
  When I search for the address
  Then I validate the street value matches with <street>

  Examples:
   | zipcode  | street             |
   | 41205017 | Rua Tancredo Neves |
   | 01001000 | Praça da Sé        |
   | 91420270 | Rua São Domingos   |

# ...

/features/search_for_address.feature

  • It has step definitions written in Ruby.
Given(/^a zip code search$/) do
 @base_url = 'https://viacep.com.br/ws/'
end

And(/^a value of ([^"]*)$/) do |zipcode|
 unless(zipcode_isValid?(zipcode))
   raise RuntimeError, 'The zip code is alphanumeric or does not have 8 digits'
 end

 @zipcode = zipcode
end

# ...

/features/step_definitions/search_for_address_steps.ruby

When (/^I search for the address$/) do
 response = HTTParty.get("#{@base_url}/#{@zipcode}/#{@return_format}/")
 if(response.code == 200)
  @street = response.parsed_response['logradouro']
 else
  # ...
 end 
end

/features/step_definitions/search_for_address_steps.ruby

Running the project

You can run the following script in the directory of the project to execute it (I do recommend to use the CMDER shell):

cucumber features\search_for_address.feature --publish-quiet

The --publish-quiet option is to disable a LOG message from the Cucumber framework

In case of success, the shell of your choice should output something like this:

$ cucumber features\search_for_address.feature --publish-quiet
Feature: Search for address
 The ViaCEP public API allows to search for a address using a
 8 digit zip code (e.g., '01001000'). Also the return format
 must be defined, it can be JSON, XML, Querty...

 Scenario: User informs valid zip code                   # features/search_for_address.feature:7
  Given a zip code search                                # features/search_for_address.feature:8
  And a value of <zipcode>                               # features/search_for_address.feature:9
  And the return format of "json"                        # features/search_for_address.feature:10
  When I search for the address                          # features/search_for_address.feature:11
  Then I validate the street value matches with <street> # features/search_for_address.feature:12

  Examples:
   | zipcode  | street             |
   | 41205017 | Rua Tancredo Neves |
   | 01001000 | Praça da Sé        |
   | 91420270 | Rua São Domingos   |

3 scenarios (3 passed)
15 steps (15 passed)
0m2.256s

$

Acknowledgments

That is pretty much it. Did you like my project? Star it and connect with me on my LinkedIn profile.

References

ViaCEP API document

ViaCEP Ruby gem

Creating Ruby basic structure

Adding Cucumber dependecies

Defining step definition

Check if a String is numeric

HTTParty gem

CMDER shell

Executing .feature file

viacep-cucumber's People

Contributors

tiagocbarbosa avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.