RSpec Explained

describe

describe Cookie do
end

it

describe Cookie do
  it "tastes yummy" do
  end
end

should

describe Cookie do
  it "tastes yummy" do
    cookie = Cookie.new
    cookie.chips.should == 72
  end
end

matchers

describe Cookie do
  it "has approximately 70 chips" do
    cookie = Cookie.new
    cookie.chips.should be_within(5).of(70)
  end
end

be matchers

[].should be_empty

before and after

describe Counter do
  before do
    @data = [0,1,2,3]
  end
  it "counts data" do
    Counter.new(@data).count.should == 4
  end
  it "adds data too" do
    Counter.new(@data).sum.should == 6
  end
end

let

describe Counter do

  let(:data) { [0,1,2,3] }

  it "counts data" do
    Counter.new(data).count.should == 4
  end
  it "adds data too" do
    Counter.new(data).sum.should == 6
  end
end

subject

describe Counter do
  let(:data) { [0,1,2,3] }

  subject { Counter.new(data) }

  it { should be_a(Counter) }

  it { should_not be_nil }

  it "counts data" do
    subject.count.should == 4
  end

  it "adds data"do
    subject.sum.should == 6
  end

end

more

<< Previous: Bundler

Outline

[contents]

Rspec Slides - Code Like This

/

#