• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Applying RSpec Best Practises
 

Applying RSpec Best Practises

on

  • 700 views

Kevin McKelvin

Kevin McKelvin
Rubyfuza 2013

Statistics

Views

Total Views
700
Views on SlideShare
612
Embed Views
88

Actions

Likes
0
Downloads
11
Comments
0

1 Embed 88

http://lanyrd.com 88

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Applying RSpec Best Practises Applying RSpec Best Practises Presentation Transcript

    • Applying RSpec Best Practices Kevin McKelvin Rubyfuza 2013
    • Ground Rules• Tests must support OO principles• Tests must be technical documentation for the code
    • The Example Conway’s Game of LifeDeterministicZero Player Game
    • Be descriptive it “should work!” do end
    • The describe block describe Game do end Describe a Ruby Constant
    • The describe block describe Game do describe "#tick" do end end Prefix instance methods with # and class methods with .
    • The context blockdescribe Game do describe "#tick" do context "when given an empty world" do end endend Use contexts to find edge cases Start contexts with when or with
    • The it blockdescribe Game do describe "#tick" do context "when given an empty world" do it "returns an empty world" do end end endend “Do or do not, there is no try” - Yoda
    • Use RSpec Matchersdescribe Game do describe "#tick" do context "when given an empty world" do it "returns an empty world" do empty_world = World.new second_world = subject.tick( empty_world) second_world.empty?.must.equal true end end endend
    • Use RSpec Matchersdescribe Game do describe "#tick" do context "when given an empty world" do it "returns an empty world" do empty_world = World.new second_world = subject.tick( empty_world) second_world.must.be_empty end end endend
    • RSpec Settings.rspec --color --profile --format d
    • Running Your SpecsGame #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 TDDSupport Object Oriented best-practices SOLID Law of Demeter
    • Remember TDDDon’t test your framework
    • Remember TDDAvoid integration testing where possible
    • Remember TDDBe 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