The end of last week was spent doing Test Driven Development with RSpec. The idea of test driven development is to test each feature in a project, fail that test, write code that makes that test pass, repeat. Each method, each feature should be tested to ensure it works correctly.
RSpec is one of the most popular testing frameworks in rails. It can create instances of your controllers, models and views and test them, it tests whether the routes are set up properly, it tests that the request and response is received from the server and tests regular Ruby classes…It’s pretty powerful tool to have.
We used expectations in the Coding Dojo console. Mainly, expect and to…meaning expect(page).to have_text(“The Dog”) which translates to expect the page to have the text “The Dog” on it, of course this after an action has been made. It’s pretty cool that it translate to plain English.
Then there’s the describe method which is used to list what the controllers and methods are supposed to do, for instance you can ‘describe’ a CodingController by saying that ‘it’ should show all coders. When describing Controller classes and methods, you should always put in require ‘rails_helper’ so it can find the controller or method you wish to describe. We also testing the models to make sure the validations and relationships were working properly.
We were introduced to Capybara which tests the actual user expectation when visiting a page for example you can declare statements like these ‘visit “/coding/new”, fill_in ‘New’, :with => “Tiffany”
And finally we testing for features of the page for example it “prompts the user fields”
After a few assignments, I cruised to the next section.