How to learn TDD with Ruby?

后端 未结 7 1033
情深已故
情深已故 2020-12-24 02:07

I have been using ruby exclusively for about a month and I really love it. However, I am having an incredibly hard time using, or even learning TDD. My brain just doesn\'t f

相关标签:
7条回答
  • 2020-12-24 02:42

    Try RubyKoans.

    0 讨论(0)
  • 2020-12-24 02:45

    One test at a time. That's the only secret, the rest is just practice, although you'll need to do a lot of practice ;-)

    You already have enough to get started: Ruby has the test/unit library, which is quite sufficient to start with.

    Try Googling for Ruby test/unit and Ruby TDD. A couple of useful starting points I found are here and here.

    I'd start the practice with a completely new project, preferably a sideline one where you're able to progress slower at first. Be really strict - all code should be written as a result of a failing test. Remember the third part of the "red-green-refactor" mantra - you'll soon get into trouble without it (trust me, I've been there).

    Once you feel you're starting to become comfortable with the technique (one sign may be that you notice that you don't really have a code-test-debug cycle any more) then start looking at some alternatives: rspec is the main one, but there are others (riot, minitest is the Ruby 1.9 default, if you're on 1.8.x)

    0 讨论(0)
  • 2020-12-24 02:46

    I still recommend TDD by Example by Kent Beck. It's an easy read and gives you all the basics.

    0 讨论(0)
  • 2020-12-24 02:50

    I agree with the answers about reading "TDD by Example" by Kent Beck and about having a real project where you force yourself to do it.

    You may also find Back to Basics: Writing Unit Tests First useful as a Ruby-related reference.

    0 讨论(0)
  • 2020-12-24 02:54

    I personally found the Peepcode RSpec screencast very helpful, they give you a nice idea of what to test plus they get you started with RSpec quickly. It took me a while to get started on TDD, but it's worth it!

    0 讨论(0)
  • 2020-12-24 02:57

    It's tricky getting your head around TDD (and BDD) but the book RSpec Book - BDD helped me a lot. Behaviour driven development is not exactly the same thing as TDD, but it is close and you have to think in a similar way.

    0 讨论(0)
提交回复
热议问题