UseCase "Group examples"
Component 415887
Jump to navigation
Jump to search
|
Content
Group by initial state/context
context() before(:each|:all) do # :each re-creates context before each example # :all could be useful for sharing instance variables for e.g. opening a network connection ... end end
An alternative for setting up instance variables is subject()
Explicit
describe ... do subject {} specify|it|example { subject.should be_happy } end
Delegated
describe ... do subject {} specify|it|example { should be_happy } end
Implicit
describe User do specify|it|example { should be_happy } end
context() after(:each|:all) do # runs even if an example fails, good for restoring global state end it() do ... end end
context() around(:each) do # support APIs that require a block end it() do ... end end