CSC/ECE 517 Spring 2024 - E2418. Reimplement of due date.rb (Phase 2): Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "==E2418. Reimplement due_date.rb== This page provides a description of the Expertiza based OSS project. __TOC__ ===About Expertiza=== [http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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 tea...")
 
No edit summary
 
(29 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==E2418. Reimplement due_date.rb==
==E2418. Reimplement due_date.rb (Phase 2)==


This page provides a description of the Expertiza based OSS project.  
This page provides a description of the Expertiza based OSS project.  
Line 11: Line 11:
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.


== Project Changes ==
==Introduction==
In this project, the following specific changes were implemented:
We're refactoring the due_dates.rb in Expertiza, enhancing its codebase to adhere to DRY and design principles, improving readability, and reducing redundancy. Our focus includes changing class methods to instance methods and further testing.


* Renamed methods and variables to accurately describe their responsibilities.
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.
* Overrode the comparator operator for the DueDate class and replace the `deadline_sort` class method.
* Utilized Rails built-in APIs for tasks such as validation, scoping, and database access.
* Conducted code smell checks using Code Climate


These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.
==Problem Statement==
The reimplementation project entails:
#<b>Refactoring due_date.rb:</b> Enhancing code clarity, optimizing, and adding comments for unclear lines of code to improve maintainability and readability.
#<b>Class to Instance Methods:</b> Changing as many class methods to instance methods as possible.
#<b>Testing with Rspec:</b> Writing comprehensive tests using Rspec for each method to ensure functionality and integration, followed by a video demonstration showcasing the functionality of the reimplementation.


== Current Implementation of DueDate Class ==
==Class Diagram==
[[File:UML_diagram_Due_Date.png|600px|thumb|none|]]


The current implementation of the `DueDate` class can be summarized in a few key points:
==Plan for Reimplementation of DueDate==
====Refactoring due_date.rb:====
#Our refactoring initiative encompassed specific actions to improve code clarity, optimize performance, and bolster maintainability across our application.<br>
#Firstly, we embarked on adding descriptive comments throughout the codebase. For instance, within the teammate_review_allowed? method, we included comments explaining the logic behind determining whether teammate review is allowed, making it easier for developers to understand the function's purpose and behavior.<br>
#Secondly, we focused on enhancing variable and method names. In the done_in_assignment_round method, we renamed variables like due_dates to assignment_due_dates for clarity. Additionally, we renamed the copy method to duplicate_due_dates to better convey its functionality. Breaking down complex methods into smaller, focused functions was another key aspect. For example, in the done_in_assignment_round method, we extracted the logic for sorting and filtering due dates into separate helper methods, improving readability and maintainability.<br>
#Optimization efforts involved reviewing database queries for efficiency. In the get_next_due_date method, we optimized the query by using ActiveRecord query methods or adding appropriate database indexes to speed up retrieval of due dates, especially in cases where assignments had staggered deadlines or multiple topics.<br>
#Robustness enhancements included refining error handling mechanisms. For instance, in the due_at_is_valid_datetime method, we provided more informative error messages to guide developers in identifying and resolving invalid datetime inputs.<br>
#Adherence to Ruby and Rails best practices was ensured throughout the refactoring process. We leveraged Rails conventions and built-in functionalities wherever possible. For example, in the set_flag method, we utilized ActiveRecord's update method with attribute names instead of update_attribute for improved code clarity and safety.<br>
#To mitigate against regressions, we implemented thorough unit tests using frameworks like RSpec or Minitest. For instance, we wrote tests to verify the behavior of the set_flag method and ensured it correctly updated the flag attribute.<br>
#Lastly, we documented our progress and collaborated effectively using version control systems like Git. Code reviews provided valuable feedback on adherence to coding standards and best practices, ensuring consistency and quality across the codebase. By undertaking these specific actions, we aimed to transform our codebase into a more readable, efficient, and maintainable state, facilitating ongoing development and enhancement of our application.


=== Validation of Due Date Format ===
====Class Methods to Instance Methods:====
The class includes a validation method due_at_is_valid_datetime to ensure that the due date is in a valid datetime format. It checks if the due_at attribute is present and attempts to parse it using DateTime.strptime. If parsing fails and raises an ArgumentError, the method adds an error to the due_at attribute indicating that it must be a valid datetime.


=== Default Permission Handling ===
Transforming class methods to instance methods in the DueDate class requires considering how these methods will interact with the individual state of each instance, rather than operating at the class level. This transformation ensures that methods directly utilize the properties of an individual instance of the class. Here's a structured plan for each class method identified in the provided code:
The class provides a default_permission method, which retrieves the default permission for a given deadline type and permission type. It accesses the DEFAULT_PERMISSION constant defined in the DeadlineRight module and returns the corresponding permission value.


=== Current Due Date Retrieval ===
#<b>set_flag:</b> Currently, as a class method, this might work by accepting an identifier for a DueDate instance (such as id) to locate and update a specific record. To convert it to an instance method, remove the need for an identifier parameter, and allow the method to directly manipulate the attribute of the instance it's called on. The signature would change from set_flag(id) to just set_flag, utilizing the instance's own data.
It offers functionality through the current_due_date method to retrieve the current due date from a list of due dates. This method iterates over the provided due dates and checks if any due date lies in the future compared to the current time. It returns the first future due date encountered, indicating the current due date.
#<b>due_at_is_valid_datetime:</b> This validation method might currently be designed to accept a datetime string at the class level. Converting this to an instance method involves removing the parameter and directly checking the instance's due_at attribute to see if it is a valid datetime. This aligns better with Rails conventions where validations typically operate on instance data, ensuring that each object maintains its integrity before saving or updating.
#For the <b><=> (spaceship operator) method</b>, converting this from a class method to an instance method aligns with its conventional use. The spaceship operator is intended to compare two instances of the same class. As an instance method, it would naturally compare the calling instance to another instance passed as a parameter, facilitating direct and intuitive comparison of attributes like due dates within the same class.


=== Flag Setting ===
The transformation from class methods to instance methods typically means moving from a broad, generalized operation to focusing on the specific attributes and behavior of individual instances. This change often simplifies method signatures by eliminating the need for additional parameters to identify specific instances since the method naturally operates on the instance from which it is called. For functionalities like validations or comparisons (spaceship operator), this shift enhances practicality and aligns well with object-oriented programming principles in Rails, improving code readability and maintainability.
It includes a set_flag method to set the flag attribute to true for a DueDate instance. This method updates the flag attribute and saves the record to the database.
 
=== Due Date Copying ===
The class implements functionality to copy due dates from one assignment to another using the copy method. It retrieves due dates associated with a given assignment ID, duplicates each due date record, assigns the new parent ID, and saves the duplicated records for the new assignment.
 
=== Due Date Setting ===
Provides a set_duedate method to set due dates for assignments with specified parameters. It creates a new DueDate instance with the provided parameters, including the deadline type, parent assignment ID, round, and saves the record to the database.
 
===Sorting of Due Dates ===
Implements a method deadline_sort to sort due dates based on the due date attribute. This method sorts the provided list of due dates in ascending order of their due dates, ensuring that due dates without due_at values are placed at the end.
 
=== Assignment Round Calculation ===
Calculates the round of the response within an assignment based on due dates using the done_in_assignment_round method. It retrieves due dates associated with the given assignment ID, sorts them by due date, and iterates over them to determine the round based on the response's creation time.
 
=== Next Due Date Retrieval ===
Offers functionality through the get_next_due_date method to retrieve the next due date for an assignment or topic. Depending on whether the assignment has staggered deadlines, it queries either AssignmentDueDate or TopicDueDate records and returns the next due date after the current time.
 
The DueDate class in the Expertiza project serves as a pivotal component responsible for managing, validating, and retrieving due dates associated with assignments, encompassing functionalities such as validation of datetime formats, permission handling, and determining the current and next due dates for assignments and topics.
 
== Improvements in the New Implementation of DueDate Class ==
 
 
 
=== Renamed methods to describe their responsibility ===
* '''Problem''': Method names might not have accurately described their functionality, leading to confusion for developers.
* '''Solution''': Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.


Old Code:
Old Code:
<pre>
<pre>
def self.current_due_date(due_dates)
..
def self.teammate_review_allowed(student)
..
def self.set_duedate(duedate, deadline, assign_id, max_round)
..
def self.deadline_sort(due_dates)
</pre>
New Code:
<pre>
def self.current(due_dates)
..
def self.teammate_review_allowed?(student)
def self.teammate_review_allowed?(student)
..
def self.set_due_date(duedate, deadline, assign_id, max_round)
..
def self.sort_deadlines(due_dates)
</pre>
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.
Old Code:
<pre>
def self.current(due_dates)
# Get the current due date from list of due dates
due_dates.each do |due_date|
  if due_date.due_at > Time.now
    current_due_date = due_date
    return current_due_date
  end
end
# in case current due date not found
nil
end
</pre>
<pre>
def self.teammate_review_allowed?(student)
# time when teammate review is allowed
# time when teammate review is allowed
due_date = current(student.assignment.due_dates)
due_date = current(student.assignment.due_dates)
student.assignment.find_current_stage == 'Finished' ||
  due_date &&
    (due_date.teammate_review_allowed_id == 3 ||
    due_date.teammate_review_allowed_id == 2) # late(2) or yes(3)
end
</pre>
<pre>
def self.copy(old_assignment_id, new_assignment_id)
    duedates = where(parent_id: old_assignment_id)
    duedates.each do |orig_due_date|
  ..
    end
end
</pre>
<pre>
def self.done_in_assignment_round(assignment_id, response)
..
..
due_dates.reject { |due_date| due_date.deadline_type_id != 1 && due_date.deadline_type_id != 2 }
..
end
</pre>
</pre>


New Code:
New Code:
<pre>
<pre>
def self.current(due_dates)
def teammate_review_allowed?(student)
due_dates.detect { |due_date| due_date.due_at > Time.now }
# time when teammate review is allowed
end
    due_date = self.class.current(student.assignment.due_dates)
 
<pre>
def self.teammate_review_allowed?(student)
# time when teammate review is allowed
due_date = current(student.assignment.due_dates)
student.assignment.find_current_stage == 'Finished' ||
  (due_date && [2, 3].include?(due_date.teammate_review_allowed_id))
end
</pre>
 
<pre>
def self.copy(old_assignment_id, new_assignment_id)
    where(parent_id: old_assignment_id).each do |orig_due_date|
    ..
    end
end
</pre>
</pre>


<pre>
== Design Principles ==
def self.done_in_assignment_round(assignment_id, response)
====Single Responsibility Principle (SRP):====
..
Each method in the DueDate class was responsible for a specific task related to managing due dates.
due_dates.reject { |due_date| ![1, 2].include?(due_date.deadline_type_id) }
Methods were refactored to separate concerns such as setting due dates, retrieving due dates, and performing operations on due dates.
..
For example, the set_duedate method focused solely on setting the due date for a task.
end
</pre>


====Don't Repeat Yourself (DRY) Principle:====
Code duplication in the DueDate class was eliminated by extracting common functionality into helper methods or modules.
Repetitive logic, such as date calculations or formatting, was refactored to promote code reusability and maintainability.


=== Utilized Rails built-in APIs for tasks such as validation, scoping, and database access ===
====Encapsulation:====
Data and behavior within the DueDate class were encapsulated within appropriate instance methods and attributes to minimize dependencies.
Access to instance variables and methods was limited, promoting encapsulation and separation of concerns.


Old Code:
====Dependency Inversion Principle (DIP):====
<pre>
The DueDate class depended on abstractions, interfaces, or higher-level modules instead of concrete implementations.
def set_flag
Dependency injection or inversion of control was used to decouple the class from specific date manipulation implementations, allowing for flexibility and easier testing.
self.flag = true
save
end
..
</pre>


<pre>
== Testing ==
def self.set_due_date(duedate, deadline, assign_id, max_round)
====Testing with Rspec:====
submit_duedate = DueDate.new(duedate)
At our last testing iteration, we enhanced the readability, maintainability, and coverage of our DueDate model tests using RSpec. We achieved this by implementing several key strategies.
submit_duedate.deadline_type_id = deadline
submit_duedate.parent_id = assign_id
submit_duedate.round = max_round
submit_duedate.save
end
</pre>


New Code:
#Firstly, we organized our tests into contextual groupings using descriptive describe blocks. Each block encapsulated different aspects of the model's functionality, such as validation, manipulation, and behavior under specific conditions. This approach improved the readability of our test suite by providing clear and logical groupings. Additionally, we employed helper methods within the before(:each) block to streamline setup logic. These methods handled common setup tasks, such as creating due dates with various attributes, reducing repetition, and making the test setup more concise and understandable.<br>
<pre>
#To ensure test efficiency and isolation, we leveraged mocking techniques to simulate dependencies where necessary. For methods relying on complex associations or external data, we mocked the required dependencies rather than relying on real database records. This approach sped up tests and isolated the behavior under test.<br>
def set_flag
#Furthermore, we paid attention to edge cases, ensuring comprehensive test coverage by including scenarios such as nil due dates, absence of response maps, and staggered deadline variations. By testing these edge cases, we ensured the robustness of our model and handled unexpected scenarios gracefully.<br>
update_attribute(:flag, true)
#Our test assertions were reviewed to ensure clarity and completeness. We verified that each test covered all expected outcomes and that assertions were clear and concise. For instance, in tests like copying due dates to a new assignment, we not only checked the count but also verified that due dates in the new assignment matched the originals.<br>
end
#We also focused on error handling, testing both error and success paths thoroughly. For methods like due_at_is_valid_datetime, we ensured that error handling scenarios were covered comprehensively, guaranteeing robustness in the face of unexpected inputs. As our test suite grew, we monitored test performance using RSpec's profiling tools and optimized slow tests as needed. Additionally, we documented our tests with comments or descriptions to clarify the purpose of each test, aiding understanding for future maintainers and contributing to overall code quality.<br>
..
#By implementing these strategies, we created a comprehensive, maintainable, and efficient test suite for our DueDate model using RSpec.
</pre>


<pre>
def self.set_due_date(duedate, deadline, assign_id, max_round)
submit_duedate = DueDate.new(duedate)
submit_duedate.update(deadline_type_id: deadline, parent_id: assign_id, round: max_round)
end
</pre>


[[File:PR.png|600px|thumb|none|]]


==Team==
=====Mentor=====
*Kalyan Karnatı


 
=====Members=====  
=== Overrode the comparator operator for the DueDate class and replaced the `deadline_sort` class method ===
*Atharva Patil (aspatil2@ncsu.edu)
* '''Problem''': Existing code had a dedicated method for sorting due dates, which violated Ruby conventions.
*Deepika Choudhary Patibandla (@ncsu.edu)
* '''Solution''': Overrode the <=> operator and defined a new function for sorting due_dates and called that instead.
*Dhruv Kolhatkar (dukolhat@ncsu.edu)
 
Old Code:
<pre>
def self.sort_deadlines(due_dates)
due_dates.sort do |m1, m2|
  if m1.due_at && m2.due_at
    m1.due_at <=> m2.due_at
  elsif m1.due_at
    -1
  else
    1
  end
end
end
</pre>
 
<pre>
..
def self.done_in_assignment_round(assignment_id, response)
    ..
    sorted_deadlines = sort_deadlines(due_dates)
    ..
end
</pre>
 
New Code:
<pre>
def <=>(other)
return nil unless other.is_a?(DueDate)
 
if due_at && other.due_at
  due_at <=> other.due_at
elsif due_at
  -1
else
  1
end
end
..
</pre>
 
<pre>
def self.done_in_assignment_round(assignment_id, response)
    ..
    sorted_deadlines = due_dates.sort
    ..
end
</pre>
 
 
== Test Plan ==
 
All the previous test cases pass in the new implementation of the system.
The following outlines the NEW scenario and cases to be tested for the <=> functionality within the system:
 
=== Sorting Due Dates ===
* Scenario: Verify that due dates are sorted in the correct order.
* Edge Case: Include due dates with identical timestamps to assess the stability of the sorting algorithm.
 
<pre>
it 'sort duedate records' do
sorted_due_dates = @due_dates
expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at <=> m2.due_at) != 1 }).to eql false
sorted_due_dates = @due_dates.sort
expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at <=> m2.due_at) != 1 }).to eql true
end
</pre>
 
All tests passed successfully:
[[File:DueDateTest.png|1000px|thumb|none|]]
 


==References==
==References==

Latest revision as of 03:56, 29 April 2024

E2418. Reimplement due_date.rb (Phase 2)

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



About Expertiza

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.

Introduction

We're refactoring the due_dates.rb in Expertiza, enhancing its codebase to adhere to DRY and design principles, improving readability, and reducing redundancy. Our focus includes changing class methods to instance methods and further testing.


Problem Statement

The reimplementation project entails:

  1. Refactoring due_date.rb: Enhancing code clarity, optimizing, and adding comments for unclear lines of code to improve maintainability and readability.
  2. Class to Instance Methods: Changing as many class methods to instance methods as possible.
  3. Testing with Rspec: Writing comprehensive tests using Rspec for each method to ensure functionality and integration, followed by a video demonstration showcasing the functionality of the reimplementation.

Class Diagram

Plan for Reimplementation of DueDate

Refactoring due_date.rb:

  1. Our refactoring initiative encompassed specific actions to improve code clarity, optimize performance, and bolster maintainability across our application.
  2. Firstly, we embarked on adding descriptive comments throughout the codebase. For instance, within the teammate_review_allowed? method, we included comments explaining the logic behind determining whether teammate review is allowed, making it easier for developers to understand the function's purpose and behavior.
  3. Secondly, we focused on enhancing variable and method names. In the done_in_assignment_round method, we renamed variables like due_dates to assignment_due_dates for clarity. Additionally, we renamed the copy method to duplicate_due_dates to better convey its functionality. Breaking down complex methods into smaller, focused functions was another key aspect. For example, in the done_in_assignment_round method, we extracted the logic for sorting and filtering due dates into separate helper methods, improving readability and maintainability.
  4. Optimization efforts involved reviewing database queries for efficiency. In the get_next_due_date method, we optimized the query by using ActiveRecord query methods or adding appropriate database indexes to speed up retrieval of due dates, especially in cases where assignments had staggered deadlines or multiple topics.
  5. Robustness enhancements included refining error handling mechanisms. For instance, in the due_at_is_valid_datetime method, we provided more informative error messages to guide developers in identifying and resolving invalid datetime inputs.
  6. Adherence to Ruby and Rails best practices was ensured throughout the refactoring process. We leveraged Rails conventions and built-in functionalities wherever possible. For example, in the set_flag method, we utilized ActiveRecord's update method with attribute names instead of update_attribute for improved code clarity and safety.
  7. To mitigate against regressions, we implemented thorough unit tests using frameworks like RSpec or Minitest. For instance, we wrote tests to verify the behavior of the set_flag method and ensured it correctly updated the flag attribute.
  8. Lastly, we documented our progress and collaborated effectively using version control systems like Git. Code reviews provided valuable feedback on adherence to coding standards and best practices, ensuring consistency and quality across the codebase. By undertaking these specific actions, we aimed to transform our codebase into a more readable, efficient, and maintainable state, facilitating ongoing development and enhancement of our application.

Class Methods to Instance Methods:

Transforming class methods to instance methods in the DueDate class requires considering how these methods will interact with the individual state of each instance, rather than operating at the class level. This transformation ensures that methods directly utilize the properties of an individual instance of the class. Here's a structured plan for each class method identified in the provided code:

  1. set_flag: Currently, as a class method, this might work by accepting an identifier for a DueDate instance (such as id) to locate and update a specific record. To convert it to an instance method, remove the need for an identifier parameter, and allow the method to directly manipulate the attribute of the instance it's called on. The signature would change from set_flag(id) to just set_flag, utilizing the instance's own data.
  2. due_at_is_valid_datetime: This validation method might currently be designed to accept a datetime string at the class level. Converting this to an instance method involves removing the parameter and directly checking the instance's due_at attribute to see if it is a valid datetime. This aligns better with Rails conventions where validations typically operate on instance data, ensuring that each object maintains its integrity before saving or updating.
  3. For the <=> (spaceship operator) method, converting this from a class method to an instance method aligns with its conventional use. The spaceship operator is intended to compare two instances of the same class. As an instance method, it would naturally compare the calling instance to another instance passed as a parameter, facilitating direct and intuitive comparison of attributes like due dates within the same class.

The transformation from class methods to instance methods typically means moving from a broad, generalized operation to focusing on the specific attributes and behavior of individual instances. This change often simplifies method signatures by eliminating the need for additional parameters to identify specific instances since the method naturally operates on the instance from which it is called. For functionalities like validations or comparisons (spaceship operator), this shift enhances practicality and aligns well with object-oriented programming principles in Rails, improving code readability and maintainability.

Old Code:

def self.teammate_review_allowed?(student)
	# time when teammate review is allowed
	due_date = current(student.assignment.due_dates)
	..

New Code:

def teammate_review_allowed?(student)
	# time when teammate review is allowed
    	due_date = self.class.current(student.assignment.due_dates)

Design Principles

Single Responsibility Principle (SRP):

Each method in the DueDate class was responsible for a specific task related to managing due dates. Methods were refactored to separate concerns such as setting due dates, retrieving due dates, and performing operations on due dates. For example, the set_duedate method focused solely on setting the due date for a task.

Don't Repeat Yourself (DRY) Principle:

Code duplication in the DueDate class was eliminated by extracting common functionality into helper methods or modules. Repetitive logic, such as date calculations or formatting, was refactored to promote code reusability and maintainability.

Encapsulation:

Data and behavior within the DueDate class were encapsulated within appropriate instance methods and attributes to minimize dependencies. Access to instance variables and methods was limited, promoting encapsulation and separation of concerns.

Dependency Inversion Principle (DIP):

The DueDate class depended on abstractions, interfaces, or higher-level modules instead of concrete implementations. Dependency injection or inversion of control was used to decouple the class from specific date manipulation implementations, allowing for flexibility and easier testing.

Testing

Testing with Rspec:

At our last testing iteration, we enhanced the readability, maintainability, and coverage of our DueDate model tests using RSpec. We achieved this by implementing several key strategies.

  1. Firstly, we organized our tests into contextual groupings using descriptive describe blocks. Each block encapsulated different aspects of the model's functionality, such as validation, manipulation, and behavior under specific conditions. This approach improved the readability of our test suite by providing clear and logical groupings. Additionally, we employed helper methods within the before(:each) block to streamline setup logic. These methods handled common setup tasks, such as creating due dates with various attributes, reducing repetition, and making the test setup more concise and understandable.
  2. To ensure test efficiency and isolation, we leveraged mocking techniques to simulate dependencies where necessary. For methods relying on complex associations or external data, we mocked the required dependencies rather than relying on real database records. This approach sped up tests and isolated the behavior under test.
  3. Furthermore, we paid attention to edge cases, ensuring comprehensive test coverage by including scenarios such as nil due dates, absence of response maps, and staggered deadline variations. By testing these edge cases, we ensured the robustness of our model and handled unexpected scenarios gracefully.
  4. Our test assertions were reviewed to ensure clarity and completeness. We verified that each test covered all expected outcomes and that assertions were clear and concise. For instance, in tests like copying due dates to a new assignment, we not only checked the count but also verified that due dates in the new assignment matched the originals.
  5. We also focused on error handling, testing both error and success paths thoroughly. For methods like due_at_is_valid_datetime, we ensured that error handling scenarios were covered comprehensively, guaranteeing robustness in the face of unexpected inputs. As our test suite grew, we monitored test performance using RSpec's profiling tools and optimized slow tests as needed. Additionally, we documented our tests with comments or descriptions to clarify the purpose of each test, aiding understanding for future maintainers and contributing to overall code quality.
  6. By implementing these strategies, we created a comprehensive, maintainable, and efficient test suite for our DueDate model using RSpec.


Team

Mentor
  • Kalyan Karnatı
Members
  • Atharva Patil (aspatil2@ncsu.edu)
  • Deepika Choudhary Patibandla (@ncsu.edu)
  • Dhruv Kolhatkar (dukolhat@ncsu.edu)

References

  1. Expertiza on GitHub
  2. GitHub Project Repository Fork
  3. The live Expertiza website
  4. Expertiza project documentation wiki
  5. Rspec Documentation
  6. Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin