Starting from Nothing: How do I Cuke "Posts"? (ie test first)
Would anyone care to share their workflow for a BDD/TDD approach using Cucumber and starting with an empty rails app? I am trying to learn how to pattern my desi开发者_如何学编程gn approach for writing tests first via cucumber.
An example scenario:
A Post model has a title and a body -- no relationships or anything fancy and is generated via the rails generate script.
What i'm hoping for is an answer that might shed light for people who are new to testing (aka ME) and not sure what steps one takes when writing a test first, then coding.
thanks.
I'm fairly new to Ruby, so please forgive anything which sounds C# or Java-esque.
First off, don't TDD Rails. Rails already has perfectly good test coverage. You can assume that it works. If using Rails gives you exactly the website that you need, congrats! You're done.
Otherwise, I'd start writing scenarios (with Cucumber) for the behaviour that you would like to be different, focusing on the most valuable behaviour first. Here's a blog post I wrote which might help you imagine how that works.
Once you have a scenario which describes some non-existent behaviour, you can start doing TDD (with RSpec), creating the web page first, then working from the outside layers closest to the page, starting with the controller and breaking out collaborating classes as and when they're needed. Once your scenario and your unit-tests pass, move onto the next thing that it doesn't do and should.
Hope this helps! I know from the example you give with "Posts" you're probably done already; however, I suspect that there's something more you want to do with it. Write a scenario for that, and good luck!
精彩评论