applying rspec best practises

Post on 19-Jan-2015

467 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Kevin McKelvin Rubyfuza 2013

TRANSCRIPT

Applying RSpec Best Practices

Kevin McKelvinRubyfuza 2013

Ground Rules

Tests must support OO principles

Tests must be technical documentationfor the code

••

The ExampleConway’s Game of Life

DeterministicZero Player Game

Be descriptive

it “should work!” do

end

Describe a Ruby Constant

The describe block

describe Game do

end

The describe block

describe Game do describe "#tick" do

end

Prefix instance methods with #and class methods with .

end

The context blockdescribe Game do describe "#tick" do

end

Use contexts to find edge cases

end

context "when given an empty world" do

end

Start contexts with when or with

The it blockdescribe Game do describe "#tick" do

end

“Do or do not, there is no try” -Yoda

end

context "when given an empty world" do

endend

it "returns an empty world" do

Use RSpec Matchersdescribe Game do describe "#tick" do

endend

context "when given an empty world" do

endend

it "returns an empty world" do

empty_world = World.new second_world = subject.tick( empty_world)

second_world.empty?.must.equal true

Use RSpec Matchersdescribe Game do describe "#tick" do

endend

context "when given an empty world" do

endend

it "returns an empty world" do

empty_world = World.new second_world = subject.tick( empty_world)

second_world.must.be_empty

RSpec Settings

--color --profile --format d

.rspec

Running Your Specs

Game #tick when given an empty world returns an empty world when given a world with one cell returns an empty world when given a world with three adjacentcells returns a world with one cell

Remember TDD

Support Object Oriented best-practices

SOLIDLaw of Demeter

Remember TDD

Don’t test your framework

Remember TDD

Avoid integration testing where possible

Remember TDD

Be the first consumer of your public API

ResourcesRSpec: http://rspec.info/The RSpec Book: http://pragprog.com/book/achbd/the-rspec-bookBetter Specs:http://www.betterspecs.orgMustard: https://github.com/ryanb/mustard

top related