CSC/ECE 517 Spring 2017/E1724

From Expertiza_Wiki
Revision as of 15:19, 23 March 2017 by Ylu36 (talk | contribs)
Jump to navigation Jump to search

E1724 - Refactoring Feature Tests

About Expertiza

Expertiza is an open source web application project based on Ruby on Rails framework. It provides an online interactive platform for instructors to post and grade assignments, and for students to contribute to team-based projects as well as individual assignments.

Problem Statement

Remove duplicated code in feature tests and improve the overall Code Climate.

Refactoring Delayed_mailer Method

Delayed_mailer_spec method covers testing scenarios with the email reminder feature targeting various users and tasks. This method took time stamps using time_parse function, which would create issues when users change their time zones. Calling time_zone_parse instead of time_parse solves the issue.These method were and involved with massive similar code. Helper methods enqueue_delayed_job(stage) and enqueue_scheduled_tasks(stage) are used to modularize the same repetitive tasks being performed.

After refactoring using these methods: In delayed_mailer_spec.rb:

def enqueue_delayed_job(stage) #enqueue a delayed job using current stage’s timestamp end

describe '<stage> deadline reminder email' do

   it 'is able to send reminder email for <stage> deadline to <stage_users> ' do
   enqueue_delayed_job(stage)
   expect(Delayed::Job.count).to eq(1)
   expect(Delayed::Job.last.handler).to include("deadline_type: <stage>")
   end

end