Zabba
Zabba

Reputation: 65467

How to get started with testing?

I've been reading a lot lately about RSpec, Shoulda, Cucumber, Test::Unit, FactoryGirl, Fixtures etc. etc. But I'm still confused as to what kind of testing each of them is used for. The kinds of testing for Model, Controller, View, Helper.

I don't know where to begin. Could someone help give an "ordering" to the way I should start? For example, should I learn Test::Unit, then RSpec then Cucumber?

Upvotes: 0

Views: 87

Answers (2)

Tiago Cardoso
Tiago Cardoso

Reputation: 2097

I'd suggest you to read 'The Art of Unit Testing', by Roy Osherove. I strongly recommend you to read Parts 1 and 4.

Although focused on Unit Testing (duh) there are some well-explained concepts that really helped me to understand better the world of testing. It's not a complicated / boring book, I enjoyed reading it even without any previous testing knowledge. Hope you enjoy it too.

Rgds

Upvotes: 2

Spyros
Spyros

Reputation: 48606

I had the same question :) Rspec is used for unit testing. This means that you test your models, controllers and maybe even views to see whether they perform things as you intended them to.

Notice that tests do not enforce behavior, they just test it. Take a look at this example :

describe "A new User" do
    let(:user) { Factory(:user) }

    it "is not valid if first_class is not either [Magician, Fighter, Ranger]" do
        user.first_class = 'warrior'
        user.should_not be_valid
    end
end

This is a model spec that uses a Factory(check for factory girl for more) and defines that if first_class is not one of the 3 above and is something like "warrior", the test should fail. After you create this test, you add to your model the validation :

validates :first_class, :presence => true, :inclusion => %w(Fighter Ranger Magician)

And now the test passes :)

After checking rspec, you should take a look at Cucumber which is actually a scenario testing gem. There, you specify whole scenarios that are matched against regular expressions. Check the very nice railscast from railscasts.com for a very nice introduction to cucumber.

Hope that gives you some insight :)

Upvotes: 1

Related Questions