9i4gqq
Last Updated: February 25, 2016
·
1.247K
· slawosz
C544188078900e5d5976689949177f11

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
Say Thanks
Respond