Rspec is the testing library that is built for test driven development from the ground up.
Ruby test unit tutorial.
I m going to use test unit as most people are still using ruby 1 8.
Rspec is a unit test framework for the ruby programming language.
The primary differences are that minitest drops the gui tools that test unit contained and minitest unit has replaced test unit s assert not functions with corresponding refute functions.
To illustrate some of the concepts we should first have something to test.
Minitest is a complete testing suite for ruby supporting test driven development tdd behavior driven development bdd mocking and benchmarking.
I had quickly put together three guides last sunday on testunit minitest and rspec.
For the purposes of unit testing a mailer fixtures are used to provide an example of how the output should look.
1 tests 4 assertions 0 failures 0 errors let s analyze what happened here.
Test unit 1 2 3 is the same version as bundled in ruby 1 8.
As in other languages ruby provides a framework in its standard library for setting up organizing and running tests called test unit.
In order to test that your mailer is working as expected you can use unit tests to compare the actual results of the mailer with pre written examples of what should be produced.
What this means is that tests written in rspec focus on the behavior of an application being tested.
Rspec now has built in support for mocking but the api is not yet stable.
Rspec is different than traditional xunit frameworks like junit because rspec is a behavior driven development tool.
Test unit is a xunit family unit testing framework for ruby.
If you re new to minitest then you can take a look at our tutorial on getting started with minitest.
It s small fast and it aims to make tests clean and readable.
Different types of tests what kinds of things to test.
Testapp ruby test unit book test rb here s the output of running the successful test case testapp ruby test unit book test crud rb loaded suite test unit book test started.
Finished in 0 0625 seconds.
In addition to covering the technical aspects of using rspec it also covers best practices for using them so you get the most out of your test suite.
Unit testing is a great way to catch errors early in the development process if you dedicate time to writing appropriate and useful tests.
The testing ruby applications with rspec screencast introduces the core rspec libraries through the development of a small cli card game.