CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb
This project wrote unit tests for the Menu.rb model in Expertiza.
Project Introduction
The menu model is used to create the top bar menu in expertiza. It does this by obtaining and organizing Menu_Items based on the current users Role. Before this project there were no unit tests for menu.rb. This project seeked to bring the unit test coverage above %90.
Team
Barrett Bryson (bbryson)
Komal Kangutkar (kmkangut)
RSpec File
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific test can be run by calling in the expertiza directory:
rspec -fd ./spec/models/menu_spec.rb
Design
In total we wrote 29 tests that covered all of the functions in both menu and its internal node class. We created a 6 menu items for testing using the given factories as well as 1 role used to test the menu constructor. We stubbed menu item to always return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested by menu item not menu. The double temp is used to only test the functionalities of menu.
Many of the functions in menu return a menu node. The simplest, get_item, takes the node id and returns the node object. All following functions use this to test that the correct node is returned. However to prevent circular logic, the get_item test only checks the id of the returned node.
While testing we found in error in the existing menu.rb code in the line shown below. The second line shows the change that we made. This allowed the code to be more robust and prevent noMethodErrors from nilClasses.