Question

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.

Was it helpful?

Solution

Shoulda just adds additional matchers to RSpec.

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

OTHER TIPS

The BDD style is exposed through expect, expect is more natural language assertions. First of all, notice that the expect require is just a reference to the expect value, whereas with the should require, the value is being executed. The should style extends each object with a should property which is called monkey patch in ruby. Here is a good article which explains and compares this two assertion mechanism.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top