The Four-Phase Test is a testing pattern, applicable to all programming languages and unit tests (not so much integration tests).
It takes the following general form:
test do setup exercise verify teardown end
There are four distinct phases of the test. They are executed sequentially.
During setup, the system under test (usually a class, object, or method) is set up.
user = User.new(password: 'password')
During exercise, the system under test is executed.
During verification, the result of the exercise is verified against the developer's expectations.
During teardown, the system under test is reset to its pre-setup state.
This is usually handled implicitly by the language (releasing memory) or test framework (running inside a database transaction).
The four phases are wrapped into a named test to be referenced individually.
Our style guide advises we "Separate setup, exercise, verification, and teardown phases with newlines."
it 'encrypts the password' do user = User.new(password: 'password') user.save user.encrypted_password.should_not be_nil end
Go forth and test in phases.