Write simple rspec tests on one line for fun and profit

How you can change your simple RSpec tests to one liners

If you have a test set up that performs one assertion then you can condense your test into one line, this makes things way more readable and shortens your tests.

For example:

it "should return a response header with JSON in it" do
  response.header['Content-Type'].should include 'json'
end 

Can become:

it { response.header['Content-Type'].should include 'json' }

When you have lots of small tests like this it really helps to make your tests easier to read, which will in turn help you in keeping them up to date and sharing them with other people.


Recent posts View all

Web Dev

What does --no-owner mean in Postgres?

You have read a guide to doing Postgres exports or imports and seen --no-owner, this is what it means

Web Dev

What does --no-acl mean in Postgres?

You have read a guide to doing Postgres exports or imports and seen --no-acl, this is what it means