E1850 Write unit tests for review response map: Difference between revisions
No edit summary |
No edit summary |
||
Line 24: | Line 24: | ||
</pre> | </pre> | ||
The following tests the questionnaire method | The following tests the questionnaire method | ||
===The questionnaire method=== | |||
<pre>describe '#questionnaire' do | <pre>describe '#questionnaire' do | ||
it 'returns questionnaire' do | it 'returns questionnaire' do | ||
Line 32: | Line 33: | ||
end </pre> | end </pre> | ||
The following tests the export fields method | The following tests the export fields method | ||
===The export_fields method=== | |||
<pre> describe '.export_fields' do | <pre> describe '.export_fields' do | ||
it 'returns list of strings "contributor" and "reviewed by"' do | it 'returns list of strings "contributor" and "reviewed by"' do | ||
Line 38: | Line 40: | ||
end</pre> | end</pre> | ||
The following tests the delete method | The following tests the delete method | ||
===The delete method=== | |||
<pre>describe '#delete' do | <pre>describe '#delete' do | ||
it 'deletes the review response map' do | it 'deletes the review response map' do | ||
Line 51: | Line 54: | ||
</pre> | </pre> | ||
The folowing code tests the get responses for team round method | The folowing code tests the get responses for team round method | ||
===The get_responses_for_team_round method=== | |||
<pre>describe '.get_responses_for_team_round' do | <pre>describe '.get_responses_for_team_round' do | ||
context 'when team doesnt exist' do | context 'when team doesnt exist' do | ||
Line 69: | Line 73: | ||
end</pre> | end</pre> | ||
The following code tests the show feedback method | The following code tests the show feedback method | ||
===The show_feedback method=== | |||
<pre>describe '#show_feedback' do | <pre>describe '#show_feedback' do | ||
context 'when no response is present or response is nil' do | context 'when no response is present or response is nil' do |
Revision as of 02:20, 9 November 2018
Expertiza
It is an open source software created by North Carolina State University's students. It works on ruby on rails framework. This platform allows instructor to post notification about tests and assignments and also allows students to view grades, submit assignments, find teammates etc.
Problem Statement
1.Create a new file named review_response_map_spec.rb under spec/models folder
2.Write RSpec unit tests to make the path coverage above 90%.
3.Coverage as many edge cases as you can.
4.Achieve as high branch coverage as you can. We will use the mutant-rspec gem to measure test thoroughness and fault-finding capability of your tests.
Test Plan
The following test checks if the title is correct or not.
describe '#get_title' do it 'returns the title' do expect(review_response_map.get_title).to eql("Review") end end
The following tests the questionnaire method
The questionnaire method
describe '#questionnaire' do it 'returns questionnaire' do allow(assignment).to receive(:review_questionnaire_id).and_return(1) allow(Questionnaire).to receive(:find_by).with(id: 1).and_return(questionnaire) expect(review_response_map.questionnaire.id).to eq(1) end end
The following tests the export fields method
The export_fields method
describe '.export_fields' do it 'returns list of strings "contributor" and "reviewed by"' do expect(ReviewResponseMap.export_fields "").to eq(["contributor", "reviewed by"]) end end
The following tests the delete method
The delete method
describe '#delete' do it 'deletes the review response map' do allow(review_response_map.response).to receive(:response_id).and_return(1) allow(FeedbackResponseMap).to receive(:where).with(reviewed_object_id: 1).and_return([feedback_response_map]) allow(feedback_response_map).to receive(:delete).with(nil).and_return(true) allow(MetareviewResponseMap).to receive(:where).with(reviewed_object_id: review_response_map.id).and_return([meta_review_response_map]) allow(meta_review_response_map).to receive(:delete).with(nil).and_return(true) allow(review_response_map).to receive(:destroy).and_return(true) expect(review_response_map.delete).to be true end end
The folowing code tests the get responses for team round method
The get_responses_for_team_round method
describe '.get_responses_for_team_round' do context 'when team doesnt exist' do it 'returns empty response' do team = instance_double('AssignmentTeam').as_null_object allow(team).to receive(:id).and_return(false) expect(ReviewResponseMap.get_responses_for_team_round team, 1).to eql([]) end end context 'when team exists' do it 'returns the responses for particular round' do team = instance_double('AssignmentTeam', :id=>1) round = 1 allow(ResponseMap).to receive(:where).with(reviewee_id: 1, type: "ReviewResponseMap").and_return([response_map, response_map2]) expect(ReviewResponseMap.get_responses_for_team_round(team, round).length).to eql(2) end end end
The following code tests the show feedback method
The show_feedback method
describe '#show_feedback' do context 'when no response is present or response is nil' do it 'returns nil' do db1 = instance_double("Response").as_null_object expect(review_response_map.show_feedback db1).to be(nil) end end end end