10

Can someone recommend a good, up-to-date tutorial for a complete beginner on one of the major testing frameworks for Ruby, such as Rspec or Shoulda? I'd like to find something that doesn't assume any knowledge about the framework or about testing in general. For example, if the tutorial explained the distinction between TDD and BDD, that would be about the level I'm looking for.

39 accepted

There is no such thing as an up-to-date tutorial in the Rails & RSpec world. By the time one comes out they will have changed testing paradigms, merged with Merb and blogged about it 1000 times and renamed Story Runner to Cucumber for reasons of clarity. I'm pretty sure if you want to understand RSpec you have to be one of the developers. Then you have to test that you are one of the developers using some weird predicate grammar that would make Noam Chomsky say "wah?" Don't worry though. Once you figure it out I hear it is very intuitive. The latest versions of rails have whizzed right by me and I am expecting a sonic boom any minute now. Which gives me an idea for a rails logo people can actually use...

Semi-serious kidding aside, I hear you. Testing is the worst documented area of rails.

7

I would check out Peepcode's stuff:

RSpec Basics

RSpec Controllers and Tools

RSpec User Stories

RSpec Mocks and Models

If your understanding is pretty basic of TDD/BDD you might want to check out their Test-First Development screencast too.

4

Here's a great video from Gregg Pollack of Rails Envy:

How I Learned to Love Testing

  • Why would you test your code?
  • When do you test your code?
  • The path to developer enlightenment
  • Test Driven Development (TDD)
  • Behavior Driven Development (BDD)
  • Where'd RSpec come from?
  • Running Autotest with Growl
  • Live screencast of BDD with Rspec
  • What are stubs and mocks?
  • How to start testing your code?
2

I have asked similar question couple of months ago without any significant success. Nevertheless, I tried hard and now I'm able to write at least some basic tests for the application I'm working on. The thing I found out is that you don't need to be religious about testing in any way. Not from the beginning, at least. The point here is not to drown in all the "big concepts" around testing and to take it easy at the start. I wrote a short motivation blog post about it, too. If you want some more practical, step-by-step tutorial, have a look at this. Good luck!

1

If you are willing to pay for a book, you may want to check out The RSpec Book by David Chelimsky et al. which is now in beta. Be warned that many of the chapters are still missing.

1

For anyone arriving to this page from Google and looking for up-to-date answers, I would advise to have a look at railstutorial.org.

As the name says, it is a Rails tutorial but the author does a really good job of baking in good version control and testing practices from the start on.

See his first mention of Rspec in the book: http://railstutorial.org/chapters/static-pages#sec:first_tests

0

For Ruby I hear webrat is the best because it doesn't use a browser so it's fast too, however it won't help you test javascript.

http://agilewebdevelopment.com/plugins/webrat