Apr 13 2009
∞
rspec example organization
If I find myself writing it blocks that contain the word “if” I like to refactor into sub-describe blocks:
describe User do
it "should be cool if wearing pants" do
# ...
end
end
# VS...
describe User do
describe "wearing pants" do
before(:each) do
# wearing pants setup
end
it "should be cool" do
# ...
end
end
describe "not wearing pants" do
before(:each) do
# not wearing pants setup
end
it "should not be cool" do
# ...
end
end
end
Yes… the second way is more verbose, but in the long run it will help organize your specs specifically and your thoughts in general.