6. The describe block
describe Game do
describe "#tick" do
end
end
Prefix instance methods with #
and class methods with .
7. The context block
describe Game do
describe "#tick" do
context "when given an empty world" do
end
end
end
Use contexts to find edge cases
Start contexts with when or with
8. The it block
describe Game do
describe "#tick" do
context "when given an empty world" do
it "returns an empty world" do
end
end
end
end
“Do or do not, there is no try” -
Yoda
9. Use RSpec Matchers
describe 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
end
end
10. Use RSpec Matchers
describe 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
end
end
12. 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 adjacent
cells
returns a world with one cell