Posts Tagged tdd

TDD on Rails #4: RSpec, Authlogic, Factory_girl and resource_controller

So well, I decided to use RSpec, Authlogic, Factory_Girl and resource_controller on my new application! But I’ve encountered some problems making all these working together. I mean I did not find any good tutorial showing how to do it step by step, so there it is!

Read the rest of this entry »

, , , , ,

23 Comments

TDD on Rails #3 – Fixtures

Yet a little post here… maybe I should gather more information and experience and write bigger post… But that will do for now… I think that in the end, I’ll try to find time to write a big article about TDD on rails, with my whole experience… I’ll just let it documented here.

Next step for my TDD application: using fixtures. Fixtures permit you to populate you database before running some tests. For example, you want to see if your User.find_admin stuff works the way you want, then you’ll just populate your database with a couple of Admin users and check if your method retrieves them from the database correctly.

Rails ships with its out of the box fixtures solution called fixtures. But reading some articles, search through the github projects and learning how the default fixtures implementation works made me realize that it can be a pain… And there is some fixtures replacement, here is a non exhaustive list:
- fixjour
- replacefixtures
- machinist
- object_daddy
- factory_girl
- …

And much more. That disconcerting, so much options. I quickly read the github (if github hosted) readme file and even before reading this prediction I choosed factory_girl because of its simplicity.

What do I mean with simplicity? INHO you should have a good idea of what the plugin/gem/code is doing giving a quick look at the github project home. Fixtures are something quite simple and the fixture replacement should quite simples too. And factory_girl caught my attention excatly because of this: clear, clean, easy to understand and to use.

, , , ,

No Comments

TDD on Rails #1

Back here, talking about my journey learning Ruby and Rails.

What would be Rails without TDD? And what is TDD? BDD? Test Driven Development and Behaviour Driven Development… Well, I won’t explain these 2 concept here, there is Pliny of articles about it: http://en.wikipedia.org/wiki/Test-driven_development

So I began learning about TDD and BDD and what is the common way to do this in Rails… RSpec is the answer!

As I’ve been working with traditional Java/J2EE/RUP way of life, when I first read: write your test first, I thought: what the fuck? And my first steps (beside learning how works RSpec) were:

- Create a test! Done! It fails! Great!!
- Write some code (a rails model)! Done! The test succeeded! Great!!!
- Think about what must be the behaviour of the model! Great!!
- Write the code before the test! DAMN!!!!

So It’s gonna be hard… Bad habits.. But This is the way to go, trust me!

, ,

No Comments