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 99: Line 99:
=== Testing ===
=== Testing ===
As part of the refactoring, we fixed a few broken tests in the original assignments_controller_spec.rb and created additional ones to increase coverage.
As part of the refactoring, we fixed a few broken tests in the original assignments_controller_spec.rb and created additional ones to increase coverage.
Link to [video] (to be uploaded) showing the RSpec testing.


=== Additional Rspec Tests Created ===
=== Additional Rspec Tests Created ===
Line 108: Line 106:


[[File:E2011NewTests.png]]
[[File:E2011NewTests.png]]
==RSpec ScreenCast==
Links to RSpec screencasts for new test cases.
#  [https://drive.google.com/open?id=1AIi3MtD_TtUN5F1k3kzgqIgi8ficz_Ar Assignment Creation General Tab]
#  [https://drive.google.com/open?id=1VnH_4NSLBX1x7xeYnH1Zsy6XG_nWD7Vk Assignment Creation Topic]
#  [https://drive.google.com/open?id=1jUQSgXjjI5jQBTWAkD8YGhYnYIIXPtnq Assignment Creation Page]


=== Coverage ===
=== Coverage ===

Revision as of 00:39, 24 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

The first refactor that our team did was to extract methods from what otherwise would be duplicate code and large block sizes. The previous team had started this process, but we were able to follow it to completion. We also then moved all of these extracted methods into the helper class assignment_creation_helper.rb. Here is an example of extracted methods that the previous team had created:

        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 into assignment_creation_helper.rb:

Another major refactor we did was to break up the one large 'describe' block in assignment_creation_spec, which contained all of the tests for that controller. Since assignment creation has many different pages, we created a separate file for testing each page or responsibility.

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. All of this was to remove any other problems that code climate detected.

Additional Code Climate Issues

There were a few things that code climate detected that we decided did not need to be refactored. The first was a complaint about blocks being too large, even after we divided the one large 'describe' statement into many smaller ones. This is because, in rspec, each test has its own 'it' block, but all of those must be grouped in a larger 'describe' block. I suggest that this be discussed with the teams who may refactor the other test files or have code climate to be configured to instead look just at the 'it' block size.

This is an diagram on how otherwise good ruby code may be flagged by code climate:

'describe' block
  'it' block
    (23 lines of code) - Code climate: √ 
  'it' block
    (15 lines of code) - Code climate: √
  'it' block
    (11 lines of code) - Code climate: √
end  - Code climate: X (23+15+11 = 49 lines)

Additionally, code climate was suggesting to change DateTime to Date or Time. As assignments are due not only on a certain day but at a specific time and that this would require a large refactoring of the entire Expertiza system for tracking submission times, we decided it was beyond the scope of this refactor.

Testing

As part of the refactoring, we fixed a few broken tests in the original assignments_controller_spec.rb and created additional ones to increase coverage.

Additional Rspec Tests Created

Looking at the methods that were covered in assignments_controller.rb we decided to create the following additional test cases for assignment creation.

These are additions to the existing assignments_controller_spec.rb.

RSpec ScreenCast

Links to RSpec screencasts for new test cases.

  1. Assignment Creation General Tab
  2. Assignment Creation Topic
  3. Assignment Creation Page


Coverage

91.6% for assignments_controller.rb

+17.7% increase overall to 42.017%

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