tdd with rspec

31
Test Driven Development - TDD with RSpec

Upload: rachid-calazans

Post on 15-Jul-2015

67 views

Category:

Technology


0 download

TRANSCRIPT

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: [email protected]

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