Test Driven Development - TDD
with RSpec
About me
• Rachid Calazans de Viveiros
• Working at Piggo
• Graduated in Systems Analysis -
CESMAC - 2011
• Post-Graduated in Mobile Application
Development for Technology
(CESAR.edu - PE)
• Addicted to Tests
• Facebook: rachid.calazans
• E-mail: rachidcalazans@gmail.com
TDD, What is it?
• It's a software development process;
• Began in the 90s by Kent Beck;
• It’s the practise of test and design;
Is Simply That
Advantages
• Your project is covered by a suite of automated tests;
• Loss of fear of changing the code;
• Improvement in your code design;
How does it work?
RSpec, What’s it?
• Was born in 2005 by Steven Baker, Dave Astels
and Aslak Hellesoy;
• It’s a popular test framework in Ruby world;
• Behaviour Driven Development - BDD;
How does it work?
The Basics
Some Methods to Help
• describe();
• context();
• it();
describe()
• As the name says, describe the
behaviour;
• Can receive any kind of object;
• Can pass a second parameter;
Example
context()
• Does the same thing as describe();
• But is used to describe the context;
Example
it()
• Specifies an example of code;
• Can or cannot define the expectations
from the object or the behaviour;
Example
Hooks
• before();
• after();
before() | after()
• Both accept the same parameters:
• - :all;
• - :each;
• - :suite;
Example
Expectations
Has a lot of types:
• be / be_nil;
• be_true / be_false;
• be_instance_of / be_an_instance_of;
• be_a / be_an / be_kind_of;
• eq / eql / equal / ==;
• change;
• …
Nice, I enjoyed it! What else?
A lot of things… :)
Advantages
• Could use User stories;
• Build a nice documentation even when running the tests;
• Easy to understand and implement the tests;
Example of the documentation
When will run the tests just add:
- -format documentation
Voila
Thanks!
References
• http://tableless.com.br/tdd-por-que-usar/
• http://agiledata.org/essays/tdd.html
• http://searchsoftwarequality.techtarget.com/definition/test-driven-development
• http://en.wikipedia.org/wiki/Test-driven_development
• http://betterspecs.org/br/
• http://rspec.info/
• http://blog.teamtreehouse.com/an-introduction-to-rspec
• http://pivotallabs.com/testing-strategies-with-rspec/
• rspec-quickguide
• Cucumber e Rspec - Construa aplicações Ruby com testes e especificações

TDD with RSpec

Editor's Notes

  • #5 TDD é o desenvolvimento de software orientado a testes; Kent Beck escreve em Smalltalk sua primeira biblioteca de testes, o SUnit; A ideia inicial dele era facilitar a execução de testes de software, automatizando essa tarefa que muitas das vezes era feita manualmente; TDD não é considerado apenas uma prática de teste, mas sim uma prática de design.
  • #6 - O fluxo do TDD se dá o nome de Red-Green-Refactor;
  • #12 BDD é uma extensão do TDD; - Em BDD, um desenvolvedor, algum profissional do setor de qualidade ou até mesmo o cliente podem esclarecer os requisitos quebrando-os em exemplos específicos.