CSC/ECE 517 Spring 2017/E1724: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:


Delayed_mailer_spec method covers testing scenarios with the email reminder feature targeting various users and tasks.
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.
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. This method also had massive duplicate code for different test scenarios. A helper method enqueue_delayed_job(stage) is used to encapsulate the task being performed.


After refactoring using these methods:
After refactoring in delayed_mailer_spec.rb:
In delayed_mailer_spec.rb:


     def enqueue_delayed_job(stage)
     def enqueue_delayed_job(stage)
Line 23: Line 22:
     describe '<stage> deadline reminder email' do
     describe '<stage> deadline reminder email' do
       it 'is able to send reminder email for <stage> deadline to <stage_users> ' do
       it 'is able to send reminder email for <stage> deadline to <stage_users> ' do
      enqueue_delayed_job(stage)
        enqueue_delayed_job(stage)
      expect(Delayed::Job.count).to eq(1)
        expect(Delayed::Job.count).to eq(1)
      expect(Delayed::Job.last.handler).to include("deadline_type: <stage>")
        expect(Delayed::Job.last.handler).to include("deadline_type: <stage>")
       end
       end
    end
'''Refactoring Scheduled_task_spec Method'''
Scheduled_task_spec method covers testing scenarios with scheduling for the deadline 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. This method also had massive duplicate code for different test scenarios. A helper method enqueue_scheduled_tasks(stage) is used to encapsulate the task being performed.
After refactoring in scheduled_spec.rb:
    def enqueue_scheduled_tasks(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_scheduled_tasks(stage)
        expect(Delayed::Job.count).to eq(1)
        expect(Delayed::Job.last.handler).to include("deadline_type: <stage>")
      end
     end
     end

Revision as of 15:27, 23 March 2017

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. This method also had massive duplicate code for different test scenarios. A helper method enqueue_delayed_job(stage) is used to encapsulate the task being performed.

After refactoring 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

Refactoring Scheduled_task_spec Method

Scheduled_task_spec method covers testing scenarios with scheduling for the deadline 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. This method also had massive duplicate code for different test scenarios. A helper method enqueue_scheduled_tasks(stage) is used to encapsulate the task being performed.

After refactoring in scheduled_spec.rb:

   def enqueue_scheduled_tasks(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_scheduled_tasks(stage)
       expect(Delayed::Job.count).to eq(1)
       expect(Delayed::Job.last.handler).to include("deadline_type: <stage>")
     end
   end