Installing RSpec for Testing

Rails ships with Test::Unit as the default testing framework. Test::Unit is a fine choice, and demonstrates the concepts of testing in Rails quite well. Despite that, RSpec is quite popular among Ruby developers. An annual survey conducted by Hampton Catlin[47] shows that, of the developers polled, 69.4% prefer RSpec for testing.

While this is a good reason to become familiar with RSpec, it’s not the main reason we want to use it here. When we get to Writing Unit Tests for Angular Components, we’ll be using Jasmine for testing our JavaScript, and both Jasmine and RSpec share a similar syntax. Here’s an RSpec test:

 describe ​"a simple test"​ ​do
  it ​"should test something"​ ​do
  expect(number).to eq(10) ...

Get Rails, Angular, Postgres, and Bootstrap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.