Use subject
If you have several tests related to the same subject use subject{}
to
DRY them up.
- Bad
it { expect(assigns('message')).to match /it was born n Belville/ }
it { expect(assigns('message').creator).to match /Topolino/ }
- Good
subject { assigns('message') }
it { should match /it was born in Billiville/ }
RSpec has also the ability to use a named subject.
- Good
subject(:hero) { Hero.first }
it "carries a sword" do
expect(hero.equipment).to include "sword"
end