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 #    ...
The context blockdescribe Game do describe "#tick" do    context "when given an empty world" do    end  endend     Use con...
The it blockdescribe Game do describe "#tick" do    context "when given an empty world" do      it "returns an empty world...
Use RSpec Matchersdescribe Game do describe "#tick" do    context "when given an empty world" do      it "returns an empty...
Use RSpec Matchersdescribe Game do describe "#tick" do    context "when given an empty world" do      it "returns an empty...
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    ...
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.bette...
Upcoming SlideShare
Loading in...5
×

Applying RSpec Best Practises

508

Published on

Kevin McKelvin
Rubyfuza 2013

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
508
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Applying RSpec Best Practises"

  1. 1. Applying RSpec Best Practices Kevin McKelvin Rubyfuza 2013
  2. 2. Ground Rules• Tests must support OO principles• Tests must be technical documentation for the code
  3. 3. The Example Conway’s Game of LifeDeterministicZero Player Game
  4. 4. Be descriptive it “should work!” do end
  5. 5. The describe block describe Game do end Describe a Ruby Constant
  6. 6. The describe block describe Game do describe "#tick" do end end Prefix instance methods with # and class methods with .
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. RSpec Settings.rspec --color --profile --format d
  12. 12. 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
  13. 13. Remember TDDSupport Object Oriented best-practices SOLID Law of Demeter
  14. 14. Remember TDDDon’t test your framework
  15. 15. Remember TDDAvoid integration testing where possible
  16. 16. Remember TDDBe the first consumer of your public API
  17. 17. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×