Search code examples
ruby-on-railstestingrspecshouldaspecifications

rSpec vs Shoulda confusion


I started reading a book about rSpec as my basic intro to testing my Rails app. I started writing tests like:

it 'is valid with a name' do
  coaster = FactoryGirl.build(:coaster)
  expect(coaster).to be_valid
end

But then someone pointed me at Shoulda and can now write tests like:

it { should validate_presence_of(:name) }

Note: I realise the two tests posted are not the same, merely just examples of each type.

What I need some clarification of is, is Shoulda an alternative to rSpec or is Shoulda an addon to it?

Which way would others go about this? The Shoulda tests seem simpler and shorter overall.

Basically any thoughts and comments would be helpful.


Solution

  • Shoulda just adds additional matchers to RSpec.

    http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames