5

I am looking for TDD resources that are specific to Rails.

I've seen the Rails Guide: The Basics of Creating a Rails Plugin which really spurred my interest in the topic.

I have the Agile Development with Rails book and I see there's some testing-related information there. However, it seems like the author takes you through the steps of building the app, then adds testing afterward. This isn't really Test Driven Development.

Ideally, I'd like a book on this, but a collection of other tutorials or articles would be great if such a book doesn't exist.

Things I'd like to learn:

  • Primary goal: Best Practices
  • Unit testing
  • How to utilize Fixtures
    • Possibly using existing development data in place of fixtures
      • What's the community standard here?
  • Writing tests for plugins
  • Testing with session data
    • User is logged in
    • User can access URL /foo/bar
  • Testing changes in data
    • Author updates post
    • Product status changes to back order
    • User buys product (behavior?)
      • User is logged in
      • User has valid address and valid credit card
      • Order record is made
      • Credit Card transaction history updated
      • Send email to user
  • Testing success of sending email
  • Testing AJAX
    • Possibly testing general jQuery functionality (Interface elements, etc)
  • RSpec
    • What place does RSpec have in a Rails app
  • The future of testing
    • Where is testing going? What things are on their way out?
    • What patterns will be used in Rails 3?

Thanks for any help!

maček
  • 76,434
  • 37
  • 167
  • 198
  • Check out this answer from a similar post: http://stackoverflow.com/questions/1386562/how-to-get-started-on-tdd-with-ruby-on-rails/6243865#6243865 – sivabudh Jun 05 '11 at 15:34

3 Answers3

2

The RSpec Book: Behaviour Driven Development with RSpec, Cucumber, and Friends. Focuses on BDD rather than TDD, but that's the whole point of RSpec and Cucumber. Not entirely specific to Rails, but has several chapters dedicated to it. Well written and up to date (though still in beta).

zetetic
  • 47,184
  • 10
  • 111
  • 119
  • How does BDD compare to TDD? Is their arguments that suggest one is better than the other? Or do they simply cover different things? – maček Apr 24 '10 at 00:47
  • I was going to suggest this too - really the state of the art in the Rails world. BDD and TDD are closely related, each just approaches the same problem from a different angle. rSpec is really a testing framework built on a DSL that produces human-readable "intentions". – Toby Hede Apr 24 '10 at 00:52
  • That's a good description. I'd say also that TDD approaches testing from an inside-out perspective, ie. that of the coder, whereas BDD approaches testing from an outside-in perspective -- the perspective of the stakeholder or customer. The output of the better BDD tools is darned close to a requirements specification that can be handed to a client. – zetetic Apr 24 '10 at 01:05
1

This is an older question, but I will add that Michael Hartl's Learn Rails by Example walks the user through TDD and covers most of the bullet points mentioned in the original question.

I'll also add that Everyday Rails Testing with RSpec is a great purchase, especially since the author makes free updates available to customers after they already bought the book, and he plans on updating again in light of Rails 4's release.

aceofbassgreg
  • 3,837
  • 2
  • 32
  • 42
1

Many of the points you mention are discussed in different episodes of Railscasts by Ryan Bates, including:

http://railscasts.com/episodes/275-how-i-test

http://railscasts.com/episodes/158-factories-not-fixtures-revised

http://railscasts.com/episodes?utf8=%E2%9C%93&search=cucumber

aceofbassgreg
  • 3,837
  • 2
  • 32
  • 42
Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52