Main Content

Ruby testing with RSpec - a new example

Archive - Originally posted on "The Horse's Mouth" - 2016-05-19 14:41:59 - Graham Ellis

If you're wanting to test your Ruby classes, I recommend writing a test suite using RSpec - fresh example from today's course [here].

* Write the tests first - that's "test driven development" and then write the code to ensure that all the tests pass.

* If you find fault in you code later, add another test to illustrate the fault and then correct it; running all the RSpec tests again wil ensure you haven't broken anything

* RSpec takes care of test set up, break down, checking and reporting - it's a complete test anagement system so that all you need to do is run the one enclsing program and if everything's good'll just be given a brief summary. Failures will be reported in an undestadable format.

* RSpec can be used with Selenium and / or watir-webdrivers to allow you to test a web site via Firefox or another browser - no need to sit there for hours to check that web site changes haven't damaged anything.

* Gherkin and Cucumber can also be used with RSpec to allow you to use those tools to define your system's behaviour prior for testing.