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
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Problem Statement ==
== Introduction ==


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%.
=== VMQuestionResponse in Brief ===
This class acquires reviews from a given questionnaire and assignment, and creates a heat map visualization of the review scores a reviewee received from other people (reviewers) for an assignment.


'''Team'''
 
== Objective ==
 
There are currently no test cases for vm_question_response.rb. We seek to create unit tests to attain at least 90% coverage by line.
 
=== Team ===


Matt Leader (mfleader@ncsu.edu)
Matt Leader (mfleader@ncsu.edu)
Line 9: Line 15:
Jonathan Gill (jtgill@ncsu.edu)
Jonathan Gill (jtgill@ncsu.edu)


'''Files Involved'''
=== Files Involved ===


app/models/vm_question_response.rb
app/models/vm_question_response.rb
Line 15: Line 21:
spec/models/vm_question_response_spec.rb
spec/models/vm_question_response_spec.rb


== Testing Plan ==


== Testing Plan ==
=== Testing Strategy: Unit Test ===
Testing VMQuestionResponse hinges upon collaboration verification, so that we know VMQuestionResponse is getting the right messages from the right classes, so that it can appropriately create its data structures.


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.
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.
Line 22: Line 30:
Here is an outline of our implementation strategy:
Here is an outline of our implementation strategy:


describe VMQuestionResponse do
To describe VMQuestionResponse
   
   
  context 'when initialized with a valid assignment questionnaire'
1) Test initialize
 
  it 'adds reviews'
* in the context when VMQuestionResponse is initialized with a review questionnaire
 
  context 'when given a team'
* in the context when VMQuestionResponse is initialized with any other questionnaire type
 
    it 'displays the members of the team'
2) Test add questions
 
  context 'when given a list of valid questions'
* in the context when VMQuestionResponse is given a list of questions
   
 
    it 'can calculate the max score for the questionnaire'
3) Test add_reviews
 
  it 'has the round value of the given questionnaire'
* in the context when VMQuestionResponse is initialized with a review questionnaire
 
  context 'is initialized with an AuthorFeedbackQuestionnaire'
* in the context when VMQuestionResponse is initialized with a author feedback questionnaire
 
  it 'adds reviews'
* in the context when VMQuestionResponse is initialized with a teammate review questionnaire
 
  it 'adds answers'
* in the context when VMQuestionResponse is initialized with a metareview questionnaire
 
  it 'get the number of comments greater than 10 words'
4) Test display_team_members
 
  context 'is initialized with a TeammateReviewQuestionnair'
5) Test add_team_members
  it 'adds reviews'
  context 'is initialized with a MetaReviewQuesionnaire'
  it 'adds reviews'


== Testing Implementation ==
6) Test listofteamparticipants


7) Test max_score_for_questionnaire


    it 'adds reviews' do
8) Test add_answer
      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"
9) Test get_number_of_comments_greater_than_10_words


== Testing Implementation ==


     context 'when given a team' do
*''initialize'' : This tests that the VmQuestionResponse is initialized with the appropriate round number.
<pre>
       it 'displays the members of the team' do
describe '#initialize' do
     context 'when intitialized with a review questionnaire' do
         team = double('team')
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
       it 'initializes the instance variables' do
         ppnt2 = double('ppnt2')
         expect(response.round).to eq 1
         expect(response.questionnaire_type).to eq "ReviewQuestionnaire"
         allow(ppnt2).to receive_messages :fullname => 'R'
         expect(response.rounds).to eq 2
      end
        team_member_names = [ppnt0, ppnt1, ppnt2]
    end
    context 'when intitialized with any other questionnaire type' do
        allow(team).to receive_messages(:participants => team_member_names)
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'initializes the instance variables' do
        out = 'Team members:'
         expect(response.round).to eq 1
         expect(response.questionnaire_type).to eq "MetareviewQuestionnaire"
         vm_rsp.add_team_members(team)
         expect(response.rounds).to eq 2
         team.participants.each do |participant|
          out = out + " (" + participant.fullname + ") "
        end
         expect(vm_rsp.display_team_members).to eq out
       end
       end
     end
     end
  end
</pre>


This code tests that when VMQuestionResponse is initialized with a team the team members can be displayed
*''add_questions'': This tests that the VmQuestionResponse adds questions from a given review
<pre>
  describe '#add_questions' do
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
    it 'adds questions' do
      response.add_questions questions
      expect(response.max_score).to eq 5
      expect(response.list_of_rows.size).to eq 1
      expect(response.max_score_for_questionnaire()).to eq questions.size * review_questionnaire.max_question_score
    end
  end
</pre>


 
*''add_reviews'' : This tests that the VmQuestionResponse adds reviews and reviewers from a given review
     context 'when given a list of valid questions' do
<pre>
  describe '#add_reviews' do
       let(:qs) { qs = Array.new(1) { question2 } }
     context 'when initialized with a review questionnaire' do
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
       it 'can calculate the max score for the questionnaire' do
      it 'adds reviews' do
        allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)
         vm_rsp.add_questions qs
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
         expect(vm_rsp.max_score).to eq 5
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
         expect(vm_rsp.list_of_rows.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
         expect(vm_rsp.max_score_for_questionnaire()).to eq qs.size * rq.max_question_score
    end
    context 'when initialized with a author feedback questionnaire' do
       let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1) }
       it 'adds reviews' do
        allow(FeedbackResponseMap).to receive_messages(:where => mapping)
         allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
         expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
         expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a teammate review questionnaire' do
      let(:response) { VmQuestionResponse.new(teammate_review_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
         expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a meta review type' do
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(MetareviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
       end
       end
     end
     end
  end
</pre>


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


 
*''display_team_members'' : This tests that the VmQuestionResponse can print out the appropriate team member names.
     it 'has the round value of the given questionnaire' do
<pre>
  describe '#display_team_members' do
       expect(vm_rsp.round).to eq 1
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
     it 'displays the members of the team' do
      team = double('team')
      participant2 = double('participant2')
      allow(participant2).to receive_messages :fullname => 'R'
      team_member_names = [participant0, participant1, participant2]
      allow(team).to receive_messages(:participants => team_member_names)
      out = 'Team members:'
      response.add_team_members(team)
      team.participants.each do |participant|
        out = out + " (" + participant.fullname + ") "
      end
       expect(response.display_team_members).to eq out
     end
     end
 
  end
This code checks that VMQuestionResponse knows the value of @round for the given questionnaire.
</pre>




  context 'is initialized with an AuthorFeedbackQuestionnaire' do
*''add_answer'' : This tests that the VmQuestionResponse adds all of the review scores from its reviews to VmQuestionResponseCells in VmQuestionResponseRows.
<pre>
    [mock setup omitted for brevity]
  describe '#add_answer' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    it 'adds reviews' do
    let(:tag_dep) do
       tag_dep = double('tag_dep')
      # review = double('review1')
       allow(tag_dep).to receive_messages(:question_type => question.type,
                                        :answer_length_threshold => 4,
      # review.stub(:map_id => 1, :response_id => 1)
                                        :tag_prompt_id => 1)
       tag_dep
      # 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
     end
     it 'adds an answer' do
     it 'adds answers' do
       allow(FeedbackResponseMap).to receive_messages(:where => mapping)
       allow(FeedbackResponseMap).to receive_messages(:where => mapping)
       allow(Participant).to receive_messages(:find => participant1)
       allow(Participant).to receive_messages(:find => ppnt1)
       allow(Answer).to receive_messages(:where => [answer])
       allow(Answer).to receive_messages(:where => [ans])
       allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
       allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
       allow(Question).to receive_messages(:find => question)
       allow(Question).to receive_messages(:find => question2)
       allow(TagPrompt).to receive_messages(:find => true)
       allow(TagPrompt).to receive_messages(:find => true)
       allow(VmTagPromptAnswer).to receive_messages(:new => '')
       allow(VmTagPromptAnswer).to receive_messages(:new => '')
       allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
       allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
 
       vm_rsp.add_questions qs
       response.add_questions questions
       response.add_reviews(participant0, '', false)
       vm_rsp.add_reviews(ppnt0, '', false)
    end
  end
</pre>
 
 
 
*''get_number_of_comments_greater_than_10_words'' : This tests that VmQuestionResponse only finds comments that have at least 10 words.
<pre>
  describe '#get_number_of_comments_greater_than_10_words' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    let(:tag_dep) do
      tag_dep = double('tag_dep')
      allow(tag_dep).to receive_messages(:question_type => question.type,
                                        :answer_length_threshold => 4,
                                        :tag_prompt_id => 1)
      tag_dep
     end
     end
     it 'returns number of comments greater than 10 words' do
     it 'gets the number of comments greater than 10 words' do
       allow(FeedbackResponseMap).to receive_messages(:where => mapping)
       allow(FeedbackResponseMap).to receive_messages(:where => mapping)
       allow(Participant).to receive_messages(:find => participant1)
       allow(Participant).to receive_messages(:find => ppnt1)
       allow(Answer).to receive_messages(:where => [answer])
       allow(Answer).to receive_messages(:where => [ans])
       allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
       allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
       allow(Question).to receive_messages(:find => question)
       allow(Question).to receive_messages(:find => question2)
       allow(TagPrompt).to receive_messages(:find => true)
       allow(TagPrompt).to receive_messages(:find => true)
       allow(VmTagPromptAnswer).to receive_messages(:new => '')
       allow(VmTagPromptAnswer).to receive_messages(:new => '')
       allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
       allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
        
        
       row = double('row')
       row = double('row')
       allow(row).to receive_messages(:countofcomments => 7, :question_id => 2,
       allow(row).to receive_messages(:countofcomments => 7, :question_id => 2,
         :question_max_score => 5, :score_row => [3])
         :question_max_score => 5, :score_row => [3])
       allow(VmQuestionResponseRow).to receive_messages(:new => row)
       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
       response.add_questions questions
       response.add_reviews(participant0, '', false)
    let(:mrq) { create(:questionnaire, name: "MetareviewQuestionnaire", type: 'MetareviewQuestionnaire') }
       expect(response.list_of_rows.size).to eq 1
       response.get_number_of_comments_greater_than_10_words
    let(:question2) { create(:question, questionnaire: mrq, weight: 2, id: 2, type: 'good') }
       expect(response.list_of_rows[0].countofcomments).to eq 7
    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
end
  end
</pre>
 
This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "MetaReviewQuestionnaire".


== Results ==
== Results ==


We have now attained 91% coverage.
We have now attained 97.25% coverage.


== Links/Resources ==
== Links/Resources ==


[https://github.com/mfleader42/expertiza/blob/master/spec/models/vm_question_response_spec.rb spec/models/vm_question_response_spec.rb]
[https://github.com/mfleader42/expertiza/blob/master/spec/models/vm_question_response_spec.rb spec/models/vm_question_response_spec.rb]
[https://youtu.be/yDfhSqVOoOk Testing Video(YouTube)]

Latest revision as of 04:50, 10 November 2018

Introduction

VMQuestionResponse in Brief

This class acquires reviews from a given questionnaire and assignment, and creates a heat map visualization of the review scores a reviewee received from other people (reviewers) for an assignment.


Objective

There are currently no test cases for vm_question_response.rb. We seek to create unit tests to attain at least 90% coverage by line.

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

Testing Strategy: Unit Test

Testing VMQuestionResponse hinges upon collaboration verification, so that we know VMQuestionResponse is getting the right messages from the right classes, so that it can appropriately create its data structures.

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:

To describe VMQuestionResponse

1) Test initialize

  • in the context when VMQuestionResponse is initialized with a review questionnaire
  • in the context when VMQuestionResponse is initialized with any other questionnaire type

2) Test add questions

  • in the context when VMQuestionResponse is given a list of questions

3) Test add_reviews

  • in the context when VMQuestionResponse is initialized with a review questionnaire
  • in the context when VMQuestionResponse is initialized with a author feedback questionnaire
  • in the context when VMQuestionResponse is initialized with a teammate review questionnaire
  • in the context when VMQuestionResponse is initialized with a metareview questionnaire

4) Test display_team_members

5) Test add_team_members

6) Test listofteamparticipants

7) Test max_score_for_questionnaire

8) Test add_answer

9) Test get_number_of_comments_greater_than_10_words

Testing Implementation

  • initialize : This tests that the VmQuestionResponse is initialized with the appropriate round number.
 describe '#initialize' do
    context 'when intitialized with a review questionnaire' do
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
      it 'initializes the instance variables' do
        expect(response.round).to eq 1
        expect(response.questionnaire_type).to eq "ReviewQuestionnaire"
        expect(response.rounds).to eq 2
      end
    end
    context 'when intitialized with any other questionnaire type' do
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'initializes the instance variables' do
        expect(response.round).to eq 1
        expect(response.questionnaire_type).to eq "MetareviewQuestionnaire"
        expect(response.rounds).to eq 2
      end
    end
  end
  • add_questions: This tests that the VmQuestionResponse adds questions from a given review
  describe '#add_questions' do
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
    it 'adds questions' do
      response.add_questions questions
      expect(response.max_score).to eq 5
      expect(response.list_of_rows.size).to eq 1
      expect(response.max_score_for_questionnaire()).to eq questions.size * review_questionnaire.max_question_score
    end
  end
  • add_reviews : This tests that the VmQuestionResponse adds reviews and reviewers from a given review
  describe '#add_reviews' do
    context 'when initialized with a review questionnaire' do
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a author feedback questionnaire' do
      let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(FeedbackResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a teammate review questionnaire' do
      let(:response) { VmQuestionResponse.new(teammate_review_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a meta review type' do
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(MetareviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
  end


  • display_team_members : This tests that the VmQuestionResponse can print out the appropriate team member names.
  describe '#display_team_members' do
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
    it 'displays the members of the team' do
      team = double('team')
      participant2 = double('participant2')
      allow(participant2).to receive_messages :fullname => 'R'
      team_member_names = [participant0, participant1, participant2]
      allow(team).to receive_messages(:participants => team_member_names)
      out = 'Team members:'
      response.add_team_members(team)
      team.participants.each do |participant|
        out = out + " (" + participant.fullname + ") "
      end
      expect(response.display_team_members).to eq out
    end
  end


  • add_answer : This tests that the VmQuestionResponse adds all of the review scores from its reviews to VmQuestionResponseCells in VmQuestionResponseRows.
  describe '#add_answer' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    let(:tag_dep) do
      tag_dep = double('tag_dep')
      allow(tag_dep).to receive_messages(:question_type => question.type,
                                         :answer_length_threshold => 4,
                                         :tag_prompt_id => 1)
      tag_dep
    end
    it 'adds an answer' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => participant1)
      allow(Answer).to receive_messages(:where => [answer])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')

      response.add_questions questions
      response.add_reviews(participant0, '', false)
    end
  end


  • get_number_of_comments_greater_than_10_words : This tests that VmQuestionResponse only finds comments that have at least 10 words.
  describe '#get_number_of_comments_greater_than_10_words' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    let(:tag_dep) do
      tag_dep = double('tag_dep')
      allow(tag_dep).to receive_messages(:question_type => question.type,
                                         :answer_length_threshold => 4,
                                         :tag_prompt_id => 1)
      tag_dep
    end
    it 'returns number of comments greater than 10 words' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => participant1)
      allow(Answer).to receive_messages(:where => [answer])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question)
      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)

      response.add_questions questions
      response.add_reviews(participant0, '', false)
      expect(response.list_of_rows.size).to eq 1
      response.get_number_of_comments_greater_than_10_words
      expect(response.list_of_rows[0].countofcomments).to eq 7
    end
end

Results

We have now attained 97.25% coverage.

Links/Resources

spec/models/vm_question_response_spec.rb

Testing Video(YouTube)