Given, When, Then in Rspec
There is a wide known convention for test unit: Given, When, Than.
Here is how to write nice example in Rspec:
Instead:
it 'should perform successfull request' do
# given
resource = Factory(:resource)
#when
get :show, id: resource.id
#than
response.should be_successfull
end
Use rspec magic:
context 'successfull response' do
let(:resource) { Factory(:resource)
before { get :show, id: resource.id }
specify { response.should be_successfull }
end
Written by Sławosz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Convention
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#