Skip to main content

Add RSpec::Its

Published: October 27, 2020

This is part of The Annotated Guide to a New Rails App, a list of recommendations to make developing your Rails app more productive and joyful.

In this article, we are talking about adding RSpec::Its.

When

Add Rspec::Its when you want to make it easier to test the attributes of an object.

Why

With RSpec::Its you can write

its(:size) { is_expected.to eq(1) }

instead of

specify { expect(subject.size).to eq(1) }

How

Add rspec-its to the Gemfile in the test group and run bundle.