<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kmkangut</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kmkangut"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Kmkangut"/>
	<updated>2026-07-17T05:49:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1878_Integrate_Suggestion_Detection_Algorithm&amp;diff=120046</id>
		<title>CSC/ECE 517 Fall 2018/E1878 Integrate Suggestion Detection Algorithm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1878_Integrate_Suggestion_Detection_Algorithm&amp;diff=120046"/>
		<updated>2018-11-14T04:53:38Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Test plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC-517 Fall 2018 - E1878 Integrate suggestion detection algorithm in Expertiza Project. This Wiki page explains how we are planning to integrate the suggestion detection algorithm in Expertiza project.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
# Ameya Dhavalikar&lt;br /&gt;
# Komal Kangutkar&lt;br /&gt;
# Prashanthi Kanniappan Murthy&lt;br /&gt;
# Vibhav Nandavaram Abbai Srivaths&lt;br /&gt;
===Background information===&lt;br /&gt;
====Expertiza====&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an Open Source project based on the [http://rubyonrails.org/ Ruby on Rails] framework, supported by National Science Foundation. It is the software to create reusable learning objects through peer review. It is a project where students can submit and peer review learning objects(articles, code, websites, etc). The users of this software include students and professors. Expertiza is used by select professors and students in North Carolina State University, for example. It supports team projects, reviews of projects/teammates, submission URLs, Wiki pages and certain document types. Instructors can create projects and the students can bid for the projects. The students can be assigned teams for a particular project or they may form their own team with fellow classmates.&lt;br /&gt;
====Suggestion detection algorithm====&lt;br /&gt;
Peer-review systems like Expertiza utilize a lot of students’ input to determine each other’s performance. In the same time, we hope students could also gain knowledge from the reviews received thus improve their own performance. In order to make this happen, we would like to have everyone give quality reviews instead of generic ones. Currently, we have a few classifiers that could catch useful components of review comments, such as if it contains suggestions, etc. These classifiers are already ported into web services that we’d like to be integrated into Expertiza.&lt;br /&gt;
====Problem statement====&lt;br /&gt;
#When a student submits a review, we would like to call this web service with the student’s review as the input. We would then want to tell the student whether their reviews contain suggestions or not, so they can make improvements based on the results of the webservice. &lt;br /&gt;
#We would also like to evaluate how much time this API is taking and if possible work a way out to improve it. We don’t want the system to be terribly slow.&lt;br /&gt;
==Files modified==&lt;br /&gt;
# app/views/response/response.html.erb&lt;br /&gt;
# app/views/submitted_content/_self_review.html.erb&lt;br /&gt;
==Design document==&lt;br /&gt;
==Wireframes==&lt;br /&gt;
====Current State====&lt;br /&gt;
In its current state, the student directly writes their review in  segmented text boxes under instructor specified questions with no further checks about the relevance of the review they have written as shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Before.jpg]]&lt;br /&gt;
====Expected State====&lt;br /&gt;
We plan to implement buttons next to each text box so that the student can check their review for volume, sentiment, suggestion, praise and criticism metrics. The rationale for including buttons right next to each text box, is so that the student gets to test only the written matter that they wish to check, and not the entirety of their review.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:After.jpg]]&lt;br /&gt;
===Test plan===&lt;br /&gt;
&lt;br /&gt;
Test: ViewSuggestionMetricsForReviewSegment&lt;br /&gt;
 Feature: As a Student,&lt;br /&gt;
          I want to view a popup displaying the suggestion metrics for the segment of the review I am writing&lt;br /&gt;
          So that I can use it to improve the relevance of the review segment provided&lt;br /&gt;
 Scenario: Display Suggestion Metrics on Empty Review Segment&lt;br /&gt;
           Given the Student has not entered any text in the review segment&lt;br /&gt;
           When the Student clicks the Analyze button for the segment&lt;br /&gt;
           Then a popup will show that the user has not entered any text for suggestion metrics analysis.&lt;br /&gt;
&lt;br /&gt;
 Scenario: Display Suggestion Metrics on Review Segment with Text&lt;br /&gt;
           Given the Student has entered any form of text in the review segment&lt;br /&gt;
           When the Student clicks the Analyze button for the segment&lt;br /&gt;
           Then a popup will show the user the results of the suggestion metrics analysis&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
#[http://peer-reviews-nlp.herokuapp.com/ NLP Project for suggestions algorithm]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=119291</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=119291"/>
		<updated>2018-11-10T16:41:11Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza. '''A test plan can be found at the bottom.'''&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. Using the given factories, we created 6 MenuItems (test1 to test6) to pass to the Menu as well as 1 Role used to test the Menu constructor. &lt;br /&gt;
&lt;br /&gt;
   let!(:test1) { create(:menu_item, name: &amp;quot;home1&amp;quot;, parent_id: nil, seq: 1) }&lt;br /&gt;
   &lt;br /&gt;
   admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: &amp;quot;&amp;quot;, parent_id: nil, default_page_id: nil)&lt;br /&gt;
&lt;br /&gt;
We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. &lt;br /&gt;
&lt;br /&gt;
   allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return(items)&lt;br /&gt;
&lt;br /&gt;
Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case, the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;br /&gt;
&lt;br /&gt;
'''Menu::Node'''&lt;br /&gt;
    &lt;br /&gt;
    #initialize&lt;br /&gt;
      when role is nil&lt;br /&gt;
        initializes with a nil parent&lt;br /&gt;
&lt;br /&gt;
    #setup&lt;br /&gt;
      when item.action_controller is nil&lt;br /&gt;
        returns /content_page.name&lt;br /&gt;
      when item.action_controller is not nil&lt;br /&gt;
        returns /controller.name/controller_action.name&lt;br /&gt;
&lt;br /&gt;
    #content_page&lt;br /&gt;
      should update the content_page instance variable&lt;br /&gt;
&lt;br /&gt;
    #controller_action&lt;br /&gt;
      when @controller_action already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
      when @controller_action is nil&lt;br /&gt;
        updates @controller_action&lt;br /&gt;
&lt;br /&gt;
    #site_controller&lt;br /&gt;
      when @site_controller is nil&lt;br /&gt;
        updates @site_controller&lt;br /&gt;
      when @site_controller already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
&lt;br /&gt;
    #add_child&lt;br /&gt;
      when node has children&lt;br /&gt;
        adds a child&lt;br /&gt;
      when node has no children&lt;br /&gt;
        can add multiple children&lt;br /&gt;
      when node has no children&lt;br /&gt;
        adds a child&lt;br /&gt;
&lt;br /&gt;
'''Menu'''&lt;br /&gt;
  #initialize&lt;br /&gt;
    when menu has items&lt;br /&gt;
      creates a new menu with item&lt;br /&gt;
    when menu has not items&lt;br /&gt;
      creates a new menu without items&lt;br /&gt;
    when role is nil&lt;br /&gt;
      creates a new menu&lt;br /&gt;
    when a role is passed as an argument&lt;br /&gt;
      creates a new menu &lt;br /&gt;
&lt;br /&gt;
  #select&lt;br /&gt;
    returns a node.id based on the given name&lt;br /&gt;
&lt;br /&gt;
  #get_item&lt;br /&gt;
    when menu has items&lt;br /&gt;
      returns the correct item&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
    when a nonexistent id is passed&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #get_menu&lt;br /&gt;
    when a node is selected&lt;br /&gt;
      returns a list of nodes that are the children of the selected node&lt;br /&gt;
    when called on a nonexistent node&lt;br /&gt;
      returns nil&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #selected?&lt;br /&gt;
    when id passed is not of a selected menu item&lt;br /&gt;
      returns false&lt;br /&gt;
    when id passed is of a selected menu item&lt;br /&gt;
      returns true&lt;br /&gt;
    when passed nil as the id&lt;br /&gt;
      return false&lt;br /&gt;
&lt;br /&gt;
  #selected&lt;br /&gt;
    when a nonexistent node is selected&lt;br /&gt;
      returns nil&lt;br /&gt;
    when an item is selected&lt;br /&gt;
      returns the name of the currently selected item&lt;br /&gt;
&lt;br /&gt;
  #crumbs&lt;br /&gt;
    when a node besides root is selected&lt;br /&gt;
      returns a list of nodes based on the selected item&lt;br /&gt;
    when root is selected&lt;br /&gt;
      returns a list of nodes based on the root&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb. Before the project the coverage was only &lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
Below is a snapshot of the coverage of our tests. Full coverage can be found at expertiza/coverage/coverage.html. The specific coverage can be found in menu under the models tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Fall2018E1853Coverage.png]]&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118671</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118671"/>
		<updated>2018-11-04T21:21:09Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. Using the given factories, we created 6 MenuItems (test1 to test6) to pass to the Menu as well as 1 Role used to test the Menu constructor. &lt;br /&gt;
&lt;br /&gt;
   let!(:test1) { create(:menu_item, name: &amp;quot;home1&amp;quot;, parent_id: nil, seq: 1) }&lt;br /&gt;
   &lt;br /&gt;
   admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: &amp;quot;&amp;quot;, parent_id: nil, default_page_id: nil)&lt;br /&gt;
&lt;br /&gt;
We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. &lt;br /&gt;
&lt;br /&gt;
   allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return(items)&lt;br /&gt;
&lt;br /&gt;
Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case, the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;br /&gt;
&lt;br /&gt;
'''Menu::Node'''&lt;br /&gt;
    &lt;br /&gt;
    #initialize&lt;br /&gt;
      when role is nil&lt;br /&gt;
        initializes with a nil parent&lt;br /&gt;
&lt;br /&gt;
    #setup&lt;br /&gt;
      when item.action_controller is nil&lt;br /&gt;
        returns /content_page.name&lt;br /&gt;
      when item.action_controller is not nil&lt;br /&gt;
        returns /controller.name/controller_action.name&lt;br /&gt;
&lt;br /&gt;
    #content_page&lt;br /&gt;
      should update the content_page instance variable&lt;br /&gt;
&lt;br /&gt;
    #controller_action&lt;br /&gt;
      when @controller_action already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
      when @controller_action is nil&lt;br /&gt;
        updates @controller_action&lt;br /&gt;
&lt;br /&gt;
    #site_controller&lt;br /&gt;
      when @site_controller is nil&lt;br /&gt;
        updates @site_controller&lt;br /&gt;
      when @site_controller already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
&lt;br /&gt;
    #add_child&lt;br /&gt;
      when node has children&lt;br /&gt;
        adds a child&lt;br /&gt;
      when node has no children&lt;br /&gt;
        can add multiple children&lt;br /&gt;
      when node has no children&lt;br /&gt;
        adds a child&lt;br /&gt;
&lt;br /&gt;
'''Menu'''&lt;br /&gt;
  #initialize&lt;br /&gt;
    when menu has items&lt;br /&gt;
      creates a new menu with item&lt;br /&gt;
    when menu has not items&lt;br /&gt;
      creates a new menu without items&lt;br /&gt;
    when role is nil&lt;br /&gt;
      creates a new menu&lt;br /&gt;
    when a role is passed as an argument&lt;br /&gt;
      creates a new menu &lt;br /&gt;
&lt;br /&gt;
  #select&lt;br /&gt;
    returns a node.id based on the given name&lt;br /&gt;
&lt;br /&gt;
  #get_item&lt;br /&gt;
    when menu has items&lt;br /&gt;
      returns the correct item&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
    when a nonexistent id is passed&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #get_menu&lt;br /&gt;
    when a node is selected&lt;br /&gt;
      returns a list of nodes that are the children of the selected node&lt;br /&gt;
    when called on a nonexistent node&lt;br /&gt;
      returns nil&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #selected?&lt;br /&gt;
    when id passed is not of a selected menu item&lt;br /&gt;
      returns false&lt;br /&gt;
    when id passed is of a selected menu item&lt;br /&gt;
      returns true&lt;br /&gt;
    when passed nil as the id&lt;br /&gt;
      return false&lt;br /&gt;
&lt;br /&gt;
  #selected&lt;br /&gt;
    when a nonexistent node is selected&lt;br /&gt;
      returns nil&lt;br /&gt;
    when an item is selected&lt;br /&gt;
      returns the name of the currently selected item&lt;br /&gt;
&lt;br /&gt;
  #crumbs&lt;br /&gt;
    when a node besides root is selected&lt;br /&gt;
      returns a list of nodes based on the selected item&lt;br /&gt;
    when root is selected&lt;br /&gt;
      returns a list of nodes based on the root&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118670</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118670"/>
		<updated>2018-11-04T21:12:12Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* List of all tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case, the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;br /&gt;
&lt;br /&gt;
'''Menu::Node'''&lt;br /&gt;
    &lt;br /&gt;
    #initialize&lt;br /&gt;
      when role is nil&lt;br /&gt;
        initializes with a nil parent&lt;br /&gt;
&lt;br /&gt;
    #setup&lt;br /&gt;
      when item.action_controller is nil&lt;br /&gt;
        returns /content_page.name&lt;br /&gt;
      when item.action_controller is not nil&lt;br /&gt;
        returns /controller.name/controller_action.name&lt;br /&gt;
&lt;br /&gt;
    #content_page&lt;br /&gt;
      should update the content_page instance variable&lt;br /&gt;
&lt;br /&gt;
    #controller_action&lt;br /&gt;
      when @controller_action already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
      when @controller_action is nil&lt;br /&gt;
        updates @controller_action&lt;br /&gt;
&lt;br /&gt;
    #site_controller&lt;br /&gt;
      when @site_controller is nil&lt;br /&gt;
        updates @site_controller&lt;br /&gt;
      when @site_controller already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
&lt;br /&gt;
    #add_child&lt;br /&gt;
      when node has children&lt;br /&gt;
        adds a child&lt;br /&gt;
      when node has no children&lt;br /&gt;
        can add multiple children&lt;br /&gt;
      when node has no children&lt;br /&gt;
        adds a child&lt;br /&gt;
&lt;br /&gt;
'''Menu'''&lt;br /&gt;
  #initialize&lt;br /&gt;
    when menu has items&lt;br /&gt;
      creates a new menu with item&lt;br /&gt;
    when menu has not items&lt;br /&gt;
      creates a new menu without items&lt;br /&gt;
    when role is nil&lt;br /&gt;
      creates a new menu&lt;br /&gt;
    when a role is passed as an argument&lt;br /&gt;
      creates a new menu &lt;br /&gt;
&lt;br /&gt;
  #select&lt;br /&gt;
    returns a node.id based on the given name&lt;br /&gt;
&lt;br /&gt;
  #get_item&lt;br /&gt;
    when menu has items&lt;br /&gt;
      returns the correct item&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
    when a nonexistent id is passed&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #get_menu&lt;br /&gt;
    when a node is selected&lt;br /&gt;
      returns a list of nodes that are the children of the selected node&lt;br /&gt;
    when called on a nonexistent node&lt;br /&gt;
      returns nil&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #selected?&lt;br /&gt;
    when id passed is not of a selected menu item&lt;br /&gt;
      returns false&lt;br /&gt;
    when id passed is of a selected menu item&lt;br /&gt;
      returns true&lt;br /&gt;
    when passed nil as the id&lt;br /&gt;
      return false&lt;br /&gt;
&lt;br /&gt;
  #selected&lt;br /&gt;
    when a nonexistent node is selected&lt;br /&gt;
      returns nil&lt;br /&gt;
    when an item is selected&lt;br /&gt;
      returns the name of the currently selected item&lt;br /&gt;
&lt;br /&gt;
  #crumbs&lt;br /&gt;
    when a node besides root is selected&lt;br /&gt;
      returns a list of nodes based on the selected item&lt;br /&gt;
    when root is selected&lt;br /&gt;
      returns a list of nodes based on the root&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118659</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118659"/>
		<updated>2018-11-03T21:58:46Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case, the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;br /&gt;
&lt;br /&gt;
'''Menu::Node'''&lt;br /&gt;
    &lt;br /&gt;
    #initialize&lt;br /&gt;
      when role is nil&lt;br /&gt;
        initializes with a nil parent&lt;br /&gt;
&lt;br /&gt;
    #setup&lt;br /&gt;
      when item.action_controller is nil&lt;br /&gt;
        returns /content_page.name&lt;br /&gt;
      when item.action_controller is not nil&lt;br /&gt;
        returns /controller.name/controller_action.name&lt;br /&gt;
&lt;br /&gt;
    #content_page&lt;br /&gt;
      should update the content_page instance variable&lt;br /&gt;
&lt;br /&gt;
    #controller_action&lt;br /&gt;
      when @controller_action already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
      when @controller_action is nil&lt;br /&gt;
        updates @controller_action&lt;br /&gt;
&lt;br /&gt;
    #site_controller&lt;br /&gt;
      when @site_controller is nil&lt;br /&gt;
        updates @site_controller&lt;br /&gt;
      when @site_controller already has a value&lt;br /&gt;
        remains the same&lt;br /&gt;
&lt;br /&gt;
    #add_child&lt;br /&gt;
      when node has children&lt;br /&gt;
        adds a child&lt;br /&gt;
      when node has no children&lt;br /&gt;
        can add multiple children&lt;br /&gt;
      when node has no children&lt;br /&gt;
        adds a child&lt;br /&gt;
&lt;br /&gt;
'''Menu'''&lt;br /&gt;
  #initialize&lt;br /&gt;
    when menu has items&lt;br /&gt;
      creates a new menu with item&lt;br /&gt;
    when menu has not items&lt;br /&gt;
      creates a new menu without items&lt;br /&gt;
    when role is nil&lt;br /&gt;
      creates a new menu&lt;br /&gt;
    when a role is passed as an argument&lt;br /&gt;
      creates a new menu &lt;br /&gt;
&lt;br /&gt;
  #select&lt;br /&gt;
    returns a node.id based on the given name&lt;br /&gt;
&lt;br /&gt;
  #get_item&lt;br /&gt;
    when menu has items&lt;br /&gt;
      returns the correct item&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
    when a nonexistent id is passed&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #get_menu&lt;br /&gt;
    when a node is selected&lt;br /&gt;
      returns a list of nodes that are the children of the selected node&lt;br /&gt;
    when called on a nonexistent node&lt;br /&gt;
      returns nil&lt;br /&gt;
    when menu has no items&lt;br /&gt;
      returns nil&lt;br /&gt;
&lt;br /&gt;
  #selected?&lt;br /&gt;
    when id passed is not of a selected menu item&lt;br /&gt;
      returns false&lt;br /&gt;
    when id passed is of a selected menu item&lt;br /&gt;
      returns true&lt;br /&gt;
    when passed nil as the id&lt;br /&gt;
      return false&lt;br /&gt;
&lt;br /&gt;
  #selected&lt;br /&gt;
    when a nonexistent node is selected&lt;br /&gt;
      returns nil&lt;br /&gt;
    when an item is selected&lt;br /&gt;
      returns the name of the currently selected item&lt;br /&gt;
&lt;br /&gt;
  #crumbs&lt;br /&gt;
    when a node besides root is selected&lt;br /&gt;
      returns a list of nodes based on the selected item&lt;br /&gt;
    when root is selected&lt;br /&gt;
      returns a list of nodes based on the root&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118449</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118449"/>
		<updated>2018-11-03T01:49:24Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case, the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118442</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118442"/>
		<updated>2018-11-03T01:40:08Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change, a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118439</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118439"/>
		<updated>2018-11-03T01:39:32Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The below line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118438</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118438"/>
		<updated>2018-11-03T01:38:43Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an error in the existing menu.rb code in the line shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The next line shows the change that we made. This allowed the code to be more robust and prevent NoMethodError from nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118437</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118437"/>
		<updated>2018-11-03T01:36:57Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the tests for Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an 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 NoMethodError from nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118435</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118435"/>
		<updated>2018-11-03T01:34:28Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* RSpec File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the following in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the functions to test Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an 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 NoMethodError from nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118434</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118434"/>
		<updated>2018-11-03T01:33:24Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
The Menu model is used to create the top bar menu in Expertiza. It does this by obtaining and organizing MenuItems based on the current user's Role. Before this project, there were no unit tests for menu.rb. This project seeks to bring the unit test coverage above 90%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
The final result can be found at expertiza/spec/models/menu_spec.rb. This specific spec file can be run by calling the followning in the expertiza directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide an easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total, we wrote 29 tests that covered all the functions in both Menu and its internal Node class. We created 6 MenuItems for testing using the given factories as well as 1 Role used to test the Menu constructor. We stubbed the MenuItem  method, items_for_permissions, to return an array of the 6 test items that we created. Other pieces of the code were stubbed because these pieces should be tested in other model specs and not Menu spec. The double 'temp' is created, which acts as a stand-in for some other class objects which interact with Menu, in order to only test the functionalities of Menu.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a known success case and an edge case or potential failure. As an example, a detailed look at the functions to test Menu#initialize is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an 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 NoMethodError from nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test covers the main use case of Menu. It is supplied with a role and assembles a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes, arranged appropriately and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have non-nil parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use, it is important that it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
Many of the functions in menu.rb return a Menu::Node. The simplest, Menu#get_item, takes a Node id and returns the corresponding Node object. All following functions use this to test that the correct Node is returned. However to prevent circular logic, the Menu#get_item test only checks the id of the returned Node.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb.&lt;br /&gt;
 &lt;br /&gt;
A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here]. &lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/BarrettJB/expertiza/ here]&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118165</id>
		<title>CSC/ECE 517 Fall 2018/E1853 Write unit tests for menu.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1853_Write_unit_tests_for_menu.rb&amp;diff=118165"/>
		<updated>2018-11-02T21:16:47Z</updated>

		<summary type="html">&lt;p&gt;Kmkangut: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This project wrote unit tests for the Menu.rb model in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Project Introduction==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Team===&lt;br /&gt;
Barrett Bryson (bbryson)&lt;br /&gt;
&lt;br /&gt;
Komal Kangutkar (kmkangut)&lt;br /&gt;
&lt;br /&gt;
===RSpec File===&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec -fd ./spec/models/menu_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The addition of the -fd argument will write out full descriptions of the tests and provide a easy look at the work we did.&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
In total we wrote 29 tests that covered all of the functions in both menu and its internal node class. We created 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.&lt;br /&gt;
&lt;br /&gt;
Each method in menu.rb has at least two tests checking both a know success case and a edge case or potential failure. As an example, a detailed look at the functions to test menu#initialize is found below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  context &amp;quot;when role is nil&amp;quot; do&lt;br /&gt;
    it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
      menu = Menu.new&lt;br /&gt;
      expect(menu.instance_of?(Menu))&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This first test revealed an 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 nilClass. Without this change a menu created with a nil role will throw an error causing the program to fail unnecessarily. This is important because the default value of role is nil and that should not fail.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache)[:credentials].try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  items = MenuItem.items_for_permissions(role.try(:cache).try(:[], :credentials).try(:permission_ids))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The second test uses the main covers the main use case of menu. It will be supplied with a role and will assemble a menu. Only a single role is tested because further testing of roles and menus should instead be handled in integration tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when a role is passed as an argument&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu&amp;quot; do&lt;br /&gt;
        admin_role = build(:role_of_administrator, id: 3, name: &amp;quot;Administrator&amp;quot;, description: '', parent_id: nil, default_page_id: nil)&lt;br /&gt;
        menu = Menu.new(admin_role)&lt;br /&gt;
        expect(menu.instance_of?(Menu))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The third test checks that when the menu is created with items, these items are put into nodes and contained within the menu. In this case the children of root will contain a single item, the node with id 1, because this node has a nil parent. The other nodes all have parents.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu with items&amp;quot; do&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children.length).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The final test checks a menu without any nodes. While this case is unlikely in actual use it is important it can be handled without throwing any errors. When a menu without any items is created, the root will never have anything added to its children array so this array will be nil.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when menu has not items&amp;quot; do&lt;br /&gt;
      it &amp;quot;creates a new menu without items&amp;quot; do&lt;br /&gt;
        allow(MenuItem).to receive(:items_for_permissions).with(anything).and_return([])&lt;br /&gt;
        menu = Menu.new&lt;br /&gt;
        expect(menu.root.children).to be_nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This 4 tests alone provide nearly 85% coverage of menu.rb because of how much they rely on a variety of other methods within the class.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The 29 tests provide 100% coverage of the lines in menu.rb. A video of all tests running can be seen [https://www.youtube.com/watch?v=yB_E5OORja0 here].&lt;br /&gt;
&lt;br /&gt;
==List of all tests==&lt;br /&gt;
Below is a list of the descriptions of all of the tests we wrote&lt;/div&gt;</summary>
		<author><name>Kmkangut</name></author>
	</entry>
</feed>