CSC/ECE 517 Fall 2018/E1849 Write Unit Tests for vm question response.rb: Difference between revisions

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




    it 'adds reviews' do
      allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_reviews(ppnt0, team, false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end
This code tests that the add_reviews method works when VMQuestionResponse has been initialized with @questionnaire_type = "ReviewQuestionnaire"
    context 'when given a team' do
      it 'displays the members of the team' do
        team = double('team')
        ppnt2 = double('ppnt2')
        allow(ppnt2).to receive_messages :fullname => 'R'
        team_member_names = [ppnt0, ppnt1, ppnt2]
        allow(team).to receive_messages(:participants => team_member_names)
        out = 'Team members:'
        vm_rsp.add_team_members(team)
        team.participants.each do |participant|
          out = out + " (" + participant.fullname + ") "
        end
        expect(vm_rsp.display_team_members).to eq out
      end
    end
This code tests that when VMQuestionResponse is initialized with a team the team members can be displayed
    context 'when given a list of valid questions' do
      let(:qs) { qs = Array.new(1) { question2 } }
      it 'can calculate the max score for the questionnaire' do
        vm_rsp.add_questions qs
        expect(vm_rsp.max_score).to eq 5
        expect(vm_rsp.list_of_rows.size).to eq 1
        expect(vm_rsp.max_score_for_questionnaire()).to eq qs.size * rq.max_question_score
      end
    end
This code tests VMQuestionResponse knows the max score for the questionnaire.
    it 'has the round value of the given questionnaire' do
      expect(vm_rsp.round).to eq 1
    end
This code checks that VMQuestionResponse knows the value of @round for the given questionnaire.
  context 'is initialized with an AuthorFeedbackQuestionnaire' do
    [mock setup omitted for brevity]
    it 'adds reviews' do
      # review = double('review1')
      # review.stub(:map_id => 1, :response_id => 1)
      # allow(review).to receive_messages(:map_id => 1)
      # ppnt0 = double('ppnt0')
      # allow(ppnt0).to receive_messages(:feedback => [review])
      # ppnt1 = double('ppnt1')
      # allow(ppnt1).to receive_messages(:fullname => 'Python')
      # mapping = double
      # allow(mapping).to receive_messages(:first => mapping, :reviewer_id => 2)
      # allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      # allow(Participant).to receive_messages(:find => ppnt1)
      # vm_rsp.add_questions qs
      # vm_rsp.add_reviews(ppnt0, '', false)
      # expect(vm_rsp.list_of_reviews.size).to eq 1
      # expect(vm_rsp.list_of_reviewers.size).to eq 1
      # expect(vm_rsp.list_of_reviews).to eq [ppnt1]
    end
    it 'adds answers' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      allow(Answer).to receive_messages(:where => [ans])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question2)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
    end
    it 'gets the number of comments greater than 10 words' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      allow(Answer).to receive_messages(:where => [ans])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question2)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
     
      row = double('row')
      allow(row).to receive_messages(:countofcomments => 7, :question_id => 2,
        :question_max_score => 5, :score_row => [3])
      allow(VmQuestionResponseRow).to receive_messages(:new => row)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_rows.size).to eq 1
      vm_rsp.get_number_of_comments_greater_than_10_words
      expect(vm_rsp.list_of_rows[0].countofcomments).to eq 7
    end
  end
The above tests cover the scenario in which VMQuestionResponse is initialized with @questionnaire_type = "AuthorFeedbackQuestionnaire". We check that VMQuestionResponse can add revews, add answers, and retrieve the number of comments greater than 10 words in length. Here the test for add_reviews is commented out because it is still being developed.
  context 'is initialized with an TeammateReviewQuestionnaire' do
    let(:tmrq) { create(:questionnaire, name: "TeammateReviewQuestionnaire",
                        type: 'TeammateReviewQuestionnaire') }
    let(:vm_rsp) { VmQuestionResponse.new( tmrq, assignment, 1 ) }
    let(:question2) { create(:question, questionnaire: tmrq, weight: 2, id: 2, type: 'good') }
    let(:qs) { qs = Array.new(1) { question2 } }
    it 'adds reviews' do
      allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end
  end
This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "TeammateReviewQuestionnaire".
  context 'is initialized with an MetareviewQuestionnaire' do
    let(:mrq) { create(:questionnaire, name: "MetareviewQuestionnaire", type: 'MetareviewQuestionnaire') }
    let(:question2) { create(:question, questionnaire: mrq, weight: 2, id: 2, type: 'good') }
    let(:qs) { qs = Array.new(1) { question2 } }
    let(:vm_rsp) { VmQuestionResponse.new( mrq, assignment, 1 ) }
    it 'adds reviews' do
      allow(MetareviewResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end
  end
This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "MetaReviewQuestionnaire".


== Results ==
== Results ==

Revision as of 23:54, 5 November 2018

Problem Statement

There are currently no test cases for vm_question_response.rb. We seek to create unit tests for this model with a coverage of at least 90%.

Team

Matt Leader (mfleader@ncsu.edu)

Jonathan Gill (jtgill@ncsu.edu)

Files Involved

app/models/vm_question_response.rb

spec/models/vm_question_response_spec.rb


Testing Plan

We first went through each method of the VMQuestionResponse class and determined whether the method was a command, or query and whether the method was incoming, outgoing, or sent-to-self. For each method we will write tests for valid and invalid inputs as well as edge cases.

Here is an outline of our implementation strategy:

describe VMQuestionResponse do

 context 'when initialized with a valid assignment questionnaire'

  it 'adds reviews'

  context 'when given a team'

   it 'displays the members of the team'

  context 'when given a list of valid questions'

   it 'can calculate the max score for the questionnaire'

  it 'has the round value of the given questionnaire'

 context 'is initialized with an AuthorFeedbackQuestionnaire'

  it 'adds reviews'

  it 'adds answers'

  it 'get the number of comments greater than 10 words'

 context 'is initialized with a TeammateReviewQuestionnair'

  it 'adds reviews'

 context 'is initialized with a MetaReviewQuesionnaire'

  it 'adds reviews'

Testing Implementation

   it 'adds reviews' do

     allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)

     allow(Participant).to receive_messages(:find => ppnt1)

     vm_rsp.add_reviews(ppnt0, team, false)

     expect(vm_rsp.list_of_reviews.size).to eq 1

     expect(vm_rsp.list_of_reviewers.size).to eq 1

     expect(vm_rsp.list_of_reviews).to eq [review]

   end

This code tests that the add_reviews method works when VMQuestionResponse has been initialized with @questionnaire_type = "ReviewQuestionnaire"


   context 'when given a team' do

     it 'displays the members of the team' do

       team = double('team')

       ppnt2 = double('ppnt2')

       allow(ppnt2).to receive_messages :fullname => 'R'

       team_member_names = [ppnt0, ppnt1, ppnt2]

       allow(team).to receive_messages(:participants => team_member_names)

       out = 'Team members:'

       vm_rsp.add_team_members(team)

       team.participants.each do |participant|

         out = out + " (" + participant.fullname + ") "

       end

       expect(vm_rsp.display_team_members).to eq out

     end

   end

This code tests that when VMQuestionResponse is initialized with a team the team members can be displayed


   context 'when given a list of valid questions' do

     let(:qs) { qs = Array.new(1) { question2 } }

     it 'can calculate the max score for the questionnaire' do

       vm_rsp.add_questions qs

       expect(vm_rsp.max_score).to eq 5

       expect(vm_rsp.list_of_rows.size).to eq 1

       expect(vm_rsp.max_score_for_questionnaire()).to eq qs.size * rq.max_question_score

     end

   end

This code tests VMQuestionResponse knows the max score for the questionnaire.


   it 'has the round value of the given questionnaire' do

     expect(vm_rsp.round).to eq 1

   end

This code checks that VMQuestionResponse knows the value of @round for the given questionnaire.


 context 'is initialized with an AuthorFeedbackQuestionnaire' do

   [mock setup omitted for brevity]

   it 'adds reviews' do

     # review = double('review1')

     # review.stub(:map_id => 1, :response_id => 1)

     # allow(review).to receive_messages(:map_id => 1)

     # ppnt0 = double('ppnt0') 

     # allow(ppnt0).to receive_messages(:feedback => [review])

     # ppnt1 = double('ppnt1')

     # allow(ppnt1).to receive_messages(:fullname => 'Python')

     # mapping = double

     # allow(mapping).to receive_messages(:first => mapping, :reviewer_id => 2)

     # allow(FeedbackResponseMap).to receive_messages(:where => mapping)

     # allow(Participant).to receive_messages(:find => ppnt1)



     # vm_rsp.add_questions qs

     # vm_rsp.add_reviews(ppnt0, , false)

     # expect(vm_rsp.list_of_reviews.size).to eq 1

     # expect(vm_rsp.list_of_reviewers.size).to eq 1

     # expect(vm_rsp.list_of_reviews).to eq [ppnt1]

   end

   it 'adds answers' do

     allow(FeedbackResponseMap).to receive_messages(:where => mapping)

     allow(Participant).to receive_messages(:find => ppnt1)

     allow(Answer).to receive_messages(:where => [ans])

     allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])

     allow(Question).to receive_messages(:find => question2)

     allow(TagPrompt).to receive_messages(:find => true)

     allow(VmTagPromptAnswer).to receive_messages(:new => )

     allow(VmQuestionResponseScoreCell).to receive_messages(:new => )

     vm_rsp.add_questions qs

     vm_rsp.add_reviews(ppnt0, , false)

   end

   it 'gets the number of comments greater than 10 words' do

     allow(FeedbackResponseMap).to receive_messages(:where => mapping)

     allow(Participant).to receive_messages(:find => ppnt1)

     allow(Answer).to receive_messages(:where => [ans])

     allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])

     allow(Question).to receive_messages(:find => question2)

     allow(TagPrompt).to receive_messages(:find => true)

     allow(VmTagPromptAnswer).to receive_messages(:new => )

     allow(VmQuestionResponseScoreCell).to receive_messages(:new => )

     

     row = double('row')

     allow(row).to receive_messages(:countofcomments => 7, :question_id => 2,

       :question_max_score => 5, :score_row => [3])

     allow(VmQuestionResponseRow).to receive_messages(:new => row)



     vm_rsp.add_questions qs

     vm_rsp.add_reviews(ppnt0, , false)

     expect(vm_rsp.list_of_rows.size).to eq 1

     vm_rsp.get_number_of_comments_greater_than_10_words

     expect(vm_rsp.list_of_rows[0].countofcomments).to eq 7

   end

 end

The above tests cover the scenario in which VMQuestionResponse is initialized with @questionnaire_type = "AuthorFeedbackQuestionnaire". We check that VMQuestionResponse can add revews, add answers, and retrieve the number of comments greater than 10 words in length. Here the test for add_reviews is commented out because it is still being developed.


 context 'is initialized with an TeammateReviewQuestionnaire' do

   let(:tmrq) { create(:questionnaire, name: "TeammateReviewQuestionnaire",

                       type: 'TeammateReviewQuestionnaire') }

   let(:vm_rsp) { VmQuestionResponse.new( tmrq, assignment, 1 ) }

   let(:question2) { create(:question, questionnaire: tmrq, weight: 2, id: 2, type: 'good') }

   let(:qs) { qs = Array.new(1) { question2 } }



   it 'adds reviews' do

     allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)

     allow(Participant).to receive_messages(:find => ppnt1)



     vm_rsp.add_questions qs

     vm_rsp.add_reviews(ppnt0, , false)

     expect(vm_rsp.list_of_reviews.size).to eq 1

     expect(vm_rsp.list_of_reviewers.size).to eq 1

     expect(vm_rsp.list_of_reviews).to eq [review]

   end

 end

This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "TeammateReviewQuestionnaire".


 context 'is initialized with an MetareviewQuestionnaire' do

   let(:mrq) { create(:questionnaire, name: "MetareviewQuestionnaire", type: 'MetareviewQuestionnaire') }

   let(:question2) { create(:question, questionnaire: mrq, weight: 2, id: 2, type: 'good') }

   let(:qs) { qs = Array.new(1) { question2 } }

   let(:vm_rsp) { VmQuestionResponse.new( mrq, assignment, 1 ) }



   it 'adds reviews' do

     allow(MetareviewResponseMap).to receive_messages(:where => mapping)

     allow(Participant).to receive_messages(:find => ppnt1)



     vm_rsp.add_questions qs

     vm_rsp.add_reviews(ppnt0, , false)

     expect(vm_rsp.list_of_reviews.size).to eq 1

     expect(vm_rsp.list_of_reviewers.size).to eq 1

     expect(vm_rsp.list_of_reviews).to eq [review]

   end

 end

This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "MetaReviewQuestionnaire".

Results

We have now attained 91% coverage.

Links/Resources

spec/models/vm_question_response_spec.rb