Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use RSpec or shoulda with Rails?

I am setting up a rails app and I just finished making some unit tests and my friend said that apparently fixtures are no longer cool and people are now using RSpec or shoulda. I was wondering what the actual benefits are to use these other toolkits. Any information at all is appreciated.

-fREW

like image 456
Frew Schmidt Avatar asked Sep 21 '08 01:09

Frew Schmidt


People also ask

Why is RSpec used?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.

Is RSpec BDD or TDD?

RSpec is a Behavior-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

What is RSpec in Ruby on Rails?

RSpec is a framework that allows us to do that. The "R" stands for Ruby, and "Spec" is short for Specification. A specification is a detailed requirement that our code should meet. Or more formally, it's an executable example that tests whether a portion of code exhibits the expected behavior in a controlled context.

Is RSpec a DSL?

DSL defines methods to group examples, most notably describe , and exposes them as class methods of RSpec. They can also be exposed globally (on main and instances of Module ) through the Configuration option expose_dsl_globally .


1 Answers

I personally prefer Shoulda to RSpec. I find that Shoulda has less magic syntax than RSpec. My problem with RSpec is that yeah it's very readable when I read it aloud, but when I get to writing it, hmmmm, I'm never sure how a given assertion should be written. Prag Dave explains the problem better than me. He also likes Shoulda and has a few examples.

like image 194
webmat Avatar answered Oct 09 '22 07:10

webmat