Developer Update 1/10/2017 – Alex (For end of Sprint 10)
This was the first sprint that the 2017 – 2018 team undertook. I was required to develop the unit tests for the backdrops controller. The backdrop controller acts between the view and model layers. It takes the input from the user and then passes useful commands to the backdrop section of the model. It is envisaged that every component (model, view and controller) have unit tests to test functionality.
I found developing unit tests for the backdrops controller to be very challenging. Before starting to develop the tests, I learned about Rspec which is a testing tool for testing Ruby code. I installed the ‘rspec-core’ gem onto my virtual machine for testing.
The tests needed to be broad and cover all the possible paths through the controller. For example, for the ‘create’ method in the backdrops_controller.rb class, there needed to be a test for whether the success message was flashed to the user and whether the page redirected to the edit_backdrop_oath. The method also needed to be tested for bad input. Tests for whether the danger message flashed to the user and whether the ‘new’ backdrop view was renders needed to be added also.
I found developing the tests very challenging. To overcome this, I did more background research into controller specs using resources such as Relish (https://relishapp.com/rspec/rspec-rails/docs/controller-specs). I also completed an Rspec tutorial on medium.com (https://medium.com/craft-academy/introduction-to-ruby-and-rspec-135da4051802). This tutorial taught me how to use the ‘describe’, ‘it’ and ‘expect’ keywords for the tests. I used ‘describe’ blocks to testing methods and ‘it’ blocks for individual tests. 25/27 tests were failing though. I sought help from Thong and we got the majority of the tests to pass (3/27 failures).
Unfortunately, 3 of the 27 tests are still not working as intended. The danger message test for and invalid backdrop in the ‘create’ method tests is returning nil when it should be not nil (line 78). The same is true for the danger message test for the ‘destroy’ method test (line 219). The redirect to edit_backdrop_path is also not working properly (line 224). I am trying to get this fixed by the end of Sprint 11.