views:

3322

answers:

6

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.

+6  A: 

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.

Tim K.
Don't paid screencasts go against the whole stackoverflow thing? $9?!?!?
davetron5000
I prefer the railscast versions. Free and better but alas not much RSpec love.
srboisvert
A: 

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

mugafuga
Webrat is for integration testing - it simulates click-throughs and such.
Tim K.
+3  A: 

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?
mwilliams
Great "motivational" video, though that won't help you at all solve real-world testing-problems as beginner. :(
Javier
+22  A: 

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.

srboisvert
1up for being so true. :(
Javier
Now several months later I would like to recommend both the Rails Prescriptions book from Noel Rappin and the RSpec/Cucumber beta book.
srboisvert
"Then you have to test that you are one of the developers using some weird predicate grammar" - +1 for the lulz, and the logo
Jeriko
"renamed Story Runner to Cucumber for reasons of clarity" rofl :)
Tim
+1  A: 

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!

Milan Novota
A: 

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.

Antti Tarvainen