Top Banner
Test Driven Development - TDD with RSpec
31

TDD with RSpec

Jul 15, 2015

Download

Technology

Rachid Calazans
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: TDD with RSpec

Test Driven Development - TDD

with RSpec

Page 2: 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]

Page 3: TDD with RSpec

TDD, What is it?

Page 4: TDD with RSpec

• It's a software development process;

• Began in the 90s by Kent Beck;

• It’s the practise of test and design;

Page 5: TDD with RSpec

Is Simply That

Page 6: TDD with RSpec

Advantages

• Your project is covered by a suite of automated tests;

• Loss of fear of changing the code;

• Improvement in your code design;

Page 7: TDD with RSpec

How does it work?

Page 8: TDD with RSpec
Page 9: TDD with RSpec
Page 10: TDD with RSpec

RSpec, What’s it?

Page 11: TDD with RSpec

• 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;

Page 12: TDD with RSpec

How does it work?

Page 13: TDD with RSpec
Page 14: TDD with RSpec

The Basics

Page 15: TDD with RSpec

Some Methods to Help

• describe();

• context();

• it();

Page 16: TDD with RSpec

describe()

• As the name says, describe the

behaviour;

• Can receive any kind of object;

• Can pass a second parameter;

Page 17: TDD with RSpec

Example

Page 18: TDD with RSpec

context()

• Does the same thing as describe();

• But is used to describe the context;

Page 19: TDD with RSpec

Example

Page 20: TDD with RSpec

it()

• Specifies an example of code;

• Can or cannot define the expectations

from the object or the behaviour;

Page 21: TDD with RSpec

Example

Page 22: TDD with RSpec

Hooks

• before();

• after();

Page 23: TDD with RSpec

before() | after()

• Both accept the same parameters:

• - :all;

• - :each;

• - :suite;

Page 24: TDD with RSpec

Example

Page 25: TDD with RSpec

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;

• …

Page 26: TDD with RSpec

Nice, I enjoyed it! What else?

Page 27: TDD with RSpec

A lot of things… :)

Page 28: TDD with RSpec

Advantages

• Could use User stories;

• Build a nice documentation even when running the tests;

• Easy to understand and implement the tests;

Page 29: TDD with RSpec

Example of the documentation

When will run the tests just add:

- -format documentation

Voila

Page 30: TDD with RSpec

Thanks!

Page 31: TDD with RSpec

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