Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

Rspec Keywords

Feedback on my misuse of rspec keywords (and context in particular):

  • Context describes an execution context, or an arrangement of the system, not an action.
  • It helps to always think of context blocks in terms of “when …” and it is usual to begin contexts with a when.

The layout is like this:

  • describe some system/class/function
    • context “when condition A is true about the system”
      • it “behaves thusly”
    • context “when condition B is true about the system”
      • it “behaves thusly”

A classic example might be:

1
2
3
4
5
6
7
8
9
10
11
12
13
describe SomeController do
  describe "GET new" do
    context "when logged in" do
      it "renders this page"
    end
    context "when admin" do
      it "renders this other page"
    end
    context "when visitor" do
      it "redirects to login"
    end
  end
end

Comments