DevOps Zone is brought to you in partnership with:

I’m a passionate web application developer and Ruby on Rails enthusiast. I love building stunning web applications and working with interesting people. I feel comfortable developing on the frontend as well as on the backend and I have a firm grasp of JavaScript and HTML5. In general I like being involved in many aspects of a product and to figure out perfect technical solutions for everybody’s satisfaction. Clemens is a DZone MVB and is not an employee of DZone and has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

How to Set Up RSpec

07.18.2013
| 2009 views |
  • submit to reddit


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 Clemens Helm, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)