CSC/ECE 517 Spring 2020 - Project E2011. Refactor assignment creation spec.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 60: Line 60:
end
end
</pre>
</pre>
The following is an example of how we were able to reduce block size and duplicate code with further extraction of methods:
[[File:E2011RefactoringDiff.png]]


Most of the sampled code above had originally existed as defined methods at the top of assignment_creation_spec for later reference in the same file. Some of these functions were developed during this refactor as redundant blocks of code were found and generalized. To aid in shortening the length of the original file, these methods were off-loaded to a helper file called assignment_creation_helper.rb.  
Most of the sampled code above had originally existed as defined methods at the top of assignment_creation_spec for later reference in the same file. Some of these functions were developed during this refactor as redundant blocks of code were found and generalized. To aid in shortening the length of the original file, these methods were off-loaded to a helper file called assignment_creation_helper.rb.  
Line 74: Line 78:




The following is an example of how we were able to reduce block size and duplicate code with further extraction of methods:


[[File:E2011RefactoringDiff.png]]


In the relocation of assignment_creation_spec's functionality and creation of new constituent files, additional refactoring was done to ensure that trailing whitespace was deleted, files ended with a final newline character, and other unnecessary characters were removed.
In the relocation of assignment_creation_spec's functionality and creation of new constituent files, additional refactoring was done to ensure that trailing whitespace was deleted, files ended with a final newline character, and other unnecessary characters were removed.

Revision as of 05:43, 23 March 2020

E2011. Refactoring assignment_creation_spec.rb

This page provides a description of the Expertiza based OSS project.

Introduction

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

Problem Statement

The two major tasks for this project were the following:

  • Refactor existing test cases to follow good coding practices. This includes variable names, following the Don't Repeat Yourself (DRY) principle, and more.
  • Check coverage of assignment_creation_spec.rb and improve upon it through additional testing.

Current Implementation

The assignment_creation_spec file contains test cases that ensure proper functionality of an instructor's workflow in regards to the creation of assignments. An instructor, when logged into Expertiza, should be able to create new assignments where each assignment has it's own assigned parameters, rubrics, review strategies and due dates. At the start of this project, all logic and handling of testing this instructor workflow was handled within a single file. This single-file implementation leads to problems with maintenance, and such problems within this implementation can be abstracted into one of these forms:

  • File is too long: This file exceeds 250 lines of code, and should not.
  • Block has too many lines: Within the file, the code used to handle a certain operation is implemented with too many subroutines within one block.
  • Similar/Exact block(s) of code found: Across the file, there were duplicate/near-duplicate blocks of code being used.
  • General syntax issues: This could include unnecessary whitespace, use of deprecated classes or things of the like.

Refactoring Process

To address the issues of the original file being too long, having long-running/duplicate blocks of code, assignment_creation_spec was refactored into multiple files based off of the grouped code's primary function. For example, these were ones that were created by the previous team:

        def get_questionnaire(finder_var = nil)
		if finder_var.nil?
			AssignmentQuestionnaire.find_by(assignment_id: @assignment.id)
		else
			AssignmentQuestionnaire.where(assignment_id: @assignment.id).where(questionnaire_id: get_selected_id(finder_var))
		end
	end

	def get_selected_id(finder_var)
		if finder_var == "ReviewQuestionnaire2"
			ReviewQuestionnaire.find_by(name: finder_var).id
		elsif finder_var == "AuthorFeedbackQuestionnaire2"
			AuthorFeedbackQuestionnaire.find_by(name: finder_var).id
		elsif finder_var == "TeammateReviewQuestionnaire2"
			TeammateReviewQuestionnaire.find_by(name: finder_var).id
		end
	end

	def fill_assignment_form
		fill_in 'assignment_form_assignment_name', with: 'edit assignment for test'
		select('Course 2', from: 'assignment_form_assignment_course_id')
		fill_in 'assignment_form_assignment_directory_path', with: 'testDirectory1'
		fill_in 'assignment_form_assignment_spec_location', with: 'testLocation1'
	end

	def assignment_creation_setup(privacy,name)
		login_as("instructor6")
		new_assignment_url = "/assignments/new?private=#{privacy}"
		visit new_assignment_url

		fill_in 'assignment_form_assignment_name', with: name
		select('Course 2', from: 'assignment_form_assignment_course_id')
		fill_in 'assignment_form_assignment_directory_path', with: 'testDirectory'
	end

The following is an example of how we were able to reduce block size and duplicate code with further extraction of methods:

Most of the sampled code above had originally existed as defined methods at the top of assignment_creation_spec for later reference in the same file. Some of these functions were developed during this refactor as redundant blocks of code were found and generalized. To aid in shortening the length of the original file, these methods were off-loaded to a helper file called assignment_creation_helper.rb.

Beyond the creation of the helper file, assignment_creation_spec.rb was broken up into the following files:

  • assignment_creation_dates_spec.rb
  • assignment_creation_deadlines_spec.rb
  • assignment_creation_general_tab_spec.rb
  • assignment_creation_page_spec.rb
  • assignment_creation_participants_spec.rb
  • assignment_creation_review_strategy_spec.rb
  • assignment_creation_rubrics_spec.rb
  • assignment_creation_topics_spec.rb



In the relocation of assignment_creation_spec's functionality and creation of new constituent files, additional refactoring was done to ensure that trailing whitespace was deleted, files ended with a final newline character, and other unnecessary characters were removed.

Testing

Link to [video] (to be uploaded) showing the RSpec testing.

Automated Testing using RSpec

Files to be uploaded soon

Testing from Travis CI

Files to be uploaded soon

Project Mentors

  1. Dr. Edward Gehringer (efg@ncsu.edu)
  2. Srujana Rachakonda (srachak@ncsu.edu)

Team Members

  1. Colin Foley (cmfoley2@ncsu.edu)
  2. Ayush Khot (akhot@ncsu.edu)
  3. Christian Morris (cgmorris@ncsu.edu)

References

  1. Expertiza on GitHub