Closed bkarlovitz closed 8 years ago
Why Shoulda over expect.to
syntax?
The main reason is that I think it's reads nicer.
Here's an example: to check an association with the expect.to
syntax, you do something like
describe Standard do
context 'Associations' do
it 'has many codes' do
assc = described_class.reflect_on_association(:codes)
expect(assc.macro).to eq :has_many
end
end
end
When there are lots of associations to check, this can get wordy. I like my tests to provide well-written, easy-to-read documentation. The Shoulda gem lets me write the above as
describe Standard do
context 'Associations' do
it { should have_many(:codes) }
end
end
There are many other cases where the Shoulda matchers are just better English than more basic RSpec.
Note: I could have also written the Shoulda test as
describe Standard do
context 'Associations' do
it { is_expected.to have_many(:codes) }
end
end
I actually prefer the word "expect" over "should" in tests, but old habits can be hard to break...
OTOH, 'should' has to monkeypatch all of the objects involved, which can lead to weird errors: http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
All of this is pretty academic, though; it's not like everything's gonna go up in flames if we choose one or the other :P
(It will totally go up in flames)
Off the top of my head, I don't think that Shoulda is calling RSpec's should
. But I might be wrong... I'll double-check.
I updated the gemfile to include libraries necessary for using rspec and cucumber.
I also set things up by running these commands in the terminal:
Note: I am using the Shoulda gem in the RSpec tests. I updated the Gemfile accordingly.