Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which testing method to go with? [Rails]

I am starting a new project for a client today.

I have done some rails projects before but never bothered writing tests for them. I'd like to change that starting with this new project. I am aware there are several testing tools, but am a bit confused as to which I should be using.

I heard of RSpec, Mocha, Webrat, and Cucumber. Please keep in mind I never really wrote any regular tests, so my knowledge of testing in general is quite limited.

How would you suggest I get started?

Thanks!


Thank you for all the responses! I posted a related question that may interest those who view this question in the future. You can find it here.

like image 777
Yuval Karmi Avatar asked Mar 14 '10 00:03

Yuval Karmi


2 Answers

I prefer using Rspec and Cucumber in conjunction. I also prefer Capybara over Webrat.

Rspec is wonderful for it's rails integration and structure. It's technically behavior testing, but in practice it ends up feeling like unit testing. It also allows you to group and define "specs", or rspec tests, in any structure you like with 'describe' blocks.

Cucumber is higher level. It is what you will translate your user stories into. For instance, you may decide that your users should be able to change their password, so you'll write something like this:

 Scenario: Change password
    Given I am logged in
    And I am on the change password page
    When I fill in "p4ssw0rd" for "old_password"
    And I fill in "newp4ssw0rd$$" for "new_password"
    Then my password should be "newp4ssw0rd$$"

If you are working with a QA dept, you can show your tests to them, and they'll instantly know the status of any given feature, and how the feature is supposed to work. Additionally, if you have enterprising testers, they can write tests themselves, even if they are not programmers in general.

like image 171
Josiah Kiehl Avatar answered Oct 09 '22 03:10

Josiah Kiehl


They all serve different function and if you really care about the quality of your software, you would use them all.

  • RSpec is more for unit testing. Unit Testing is testing the smallest part, usually your models methods.

  • WebRat is more for functionality testing as end user would test it from a browser. You are actually testing the interaction and test whether it returns the correct view/data.

  • Cucumber is more like for behaviour driven testing or end-to-end testing. It is more to test the business logic according to many different scenarios or data.

Of course you could use all of them together in conjunction. For example, I can use Cucumber to do end-to-end testing and it would involve functional testing using WebRat and Rspec as well. Hopefully this will get the idea for you to start off.

like image 25
Joshua Partogi Avatar answered Oct 09 '22 03:10

Joshua Partogi