Skip to content

HOWTO dev TDD_BDD_workflow

steveoro edited this page Jan 16, 2021 · 1 revision

HOW-TO: TDD / BDD work-flow

Use RSpec as main testing framework

Use Cucumber & Capybara for feature & front-end specs.

Use Rubocop is used to check and to enforce a minimum quality in coding style (it does a basic static analysis of the Ruby code).

Installation for these gems is bundle-driven; so, as long as the project directory is cloned, the bundle is updated, with a possible Rails pre-loader running in the background (either Zeus for Rails <5 or Spring), all specs should result executable as well as anything else.

Having a Rails preloader with even a basic Guard installation allows you to test & run continuously while writing the specs and its associated code.

The preloader loads all the development & test environment to speed-up the execution of any rails & rake command.

Guard simply watches for file modifications under the directories for which is told to watch for and immediately launches the corresponding test whenever that file changes (by being saved).

The specs are run by Guard inside the preloaded environment and chosen according to Regular Expressions matching the file name and its directory structure.

The paths that have to be watched can be specified inside the Guardfile, which should be placed in the project root.

Refer to Guard & Zeus/Spring setup and usage for more info.

The typical development flow should be something like:

  1. Write the specs describing the code you wish you had.
  2. See the specs fail in the Guard console (running as soon as you hit "save file").
  3. Write the code to make the specs pass.
  4. Goto (1) until "profit". 😄

Step-by-step best-practice workflow on an already configured machine

  1. (make sure the DB server is up and running, when in doubt)
  2. Open another console and cd to the project root.
  3. Wait for the bundle to update/check itself (if bundle gets run automatically).
  4. When in doubt, type a rvm list gemsets to verify that the gemset currently being used is the correct one.
  5. Launch zeus start or spring start (depending on what you're using) and leave that console open. (For Spring you can actually use the same console for running also Guard.)
  6. Open another console tab in the same directory (typically, CTRL-SHIFT-T for a new Tab); type a cd . so that rvm is forced to set again the Gemset used.
  7. Launch guard and leave the console open.
  8. Open and setup another console in the same project directory, ready to accept any rake task that you may need to execute.
  9. Start coding with your favorite editor. 👷

Refer also to Dev environment setup details & Best practices in order to improve your development effectiveness.

Clone this wiki locally