Platinum Partner
ruby,architects,devops,tutorial,tips and tricks,tools & methods,rspec

How to Set Up RSpec



Set up RSpec for Ruby applications

For all Ruby applications you can use the rspec gem. The gem is a collection of 3 other gems:

You can also include one or more of these gems separately. For instance, if you want to use Bogus for mocking, like we did in last week’s episode, you can just add rspec-coreand rspec-expectations to your Gemfile, because you don’t need rspec-mocks.

If you run rspec from your project’s root directory without any argument, it will expect your specs to be in the ./spec directory and your classes to be in the ./lib directory. Although you can work around this assumption, I recommend you to stick to them: They are applied in almost all Ruby projects.

Set up RSpec for Rails applications

These rspec gem will work for every Ruby application you create, so you could also use it with your Rails applications. However, there is a more convenient option: The rspec-railsgem is the easiest way of setting up RSpec for Rails. It will provide you with convenient generators that get called when you generate resources like models or controllers. Watch the screencast to see it in action!

Up next: Setting up Cucumber

Next week we’ll set up our Ruby and Rails applications with Cucumber. In the meantime check out our other episodes on RSpec. You can find a list of them below in the “Further info” section.

Further info:

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}