OSS E1852.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 7: Line 7:
== Problem ==
== Problem ==


Participant model does not have any unit tests.
There are not enough unit tests for participant.rb Current path coverage is only 36.08%.




Line 15: Line 15:


* Achieve path coverage more than 90%
* Achieve path coverage more than 90%
* Achieve as high branch coverage as possible


=== Files Modified/Created ===
=== Files Modified/Created ===
Line 24: Line 26:
Unit tests are used to test the functionality of methods in the model. there are two types of unit tests, Test Driven Development(TDD) and Behaviour Driven Development(BDD). BDD is preferred because of its simplicity. In this project, We are using RSpec for BDD.  
Unit tests are used to test the functionality of methods in the model. there are two types of unit tests, Test Driven Development(TDD) and Behaviour Driven Development(BDD). BDD is preferred because of its simplicity. In this project, We are using RSpec for BDD.  


doubt ? do I have to write more about RSpec????
 


== Participant Unit Test ==
== Participant Unit Test ==
Line 53: Line 55:
</pre>
</pre>


'''Methods tested in participant model''':
'''Methods tested in participant model:'''


* team
* team
Line 68: Line 70:
</pre>
</pre>


*name
*name: Returns the name of the participant
*fullname
<pre>
*handle
describe "#name" do
*delete
    it "returns the name of the user" do
*force_delete
      expect( participant.name ).to eq( "Jane" )
*topic_name
    end
  end
</pre>
 
*fullname : Returns the full name of the participant
<pre>
describe "#fullname" do
    it "returns the full name of the user" do
      expect( participant.fullname ).to eq( "Doe, Jane" )
    end
  end
</pre>
 
*handle : Returns handle of the participant
<pre>
describe '#handle' do
    it 'returns the handle of the participant' do
      expect( participant.handle( nil ) ).to eq( "handle" )
    end
</pre>
 
* delete: It deletes the participant if the participant doesn't have any association adn value of "force" is nil else it will raise an exception
<pre>
describe '#delete' do
    it 'deletes a participant if no associations exist and force is nil' do
      expect( participant.delete( nil ) ).to eq( participant )
    end
    it 'deletes a participant if no associations exist and force is true' do
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      allow( team ).to receive( :teams_users ).and_return( length: 1 )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'raises execption when trying to delect participant where associations exists and force is nil' do
      allow( participant ).to receive( :team ).and_return( team )
      expect{ participant.delete( nil ) }.to raise_error.with_message("Associations exist for this participant.")
    end
  end
</pre>
*force_delete: This method is called inside the delete method . coverage for this is handled in delete method. hence there is not explicit cases are written.
*topic_name: Retunrs the topic name associated with the participant
<pre>
describe '#topic_name' do
    it 'returns the topic name associated with the participant topic name is nil' do
      expect( participant.topic_name ).to eq( '<center>&#8212;</center>' )
    end
    it 'returns the topic name associated with the participant topic name has value' do
      allow( participant ).to receive( :topic ).and_return( topic )
      expect( participant.topic_name ).to eq( "Hello world!" ) 
    end
  end
</pre>
*able_to_review
*able_to_review
*email
*email

Revision as of 21:40, 27 October 2018

This wiki page is for the description of changes made under E1852 OSS assignment for Fall 2018, CSC/ECE 517

Background

Expertiza is an open source web-based peer review system developed and maintained by students and faculty members at North Carolina State University. It enables students enrolled in a particular course to form online teams and complete assignments.

Problem

There are not enough unit tests for participant.rb Current path coverage is only 36.08%.


Work to be done

  • Write unit test using Rspec
  • Achieve path coverage more than 90%
  • Achieve as high branch coverage as possible

Files Modified/Created

  • spec/models/particpant_spec.rb

Unit Test Description

Unit tests are used to test the functionality of methods in the model. there are two types of unit tests, Test Driven Development(TDD) and Behaviour Driven Development(BDD). BDD is preferred because of its simplicity. In this project, We are using RSpec for BDD.


Participant Unit Test

We used factory methods to generate the necessary variables.

let(:user) { 
	build( :student, id: 1, name: 'no name', fullname: 'no one') }
  let(:team) {	
	build( :assignment_team, id: 1, name: 'myTeam' ) }
  let(:team_user) { 
	build( :team_user, id: 1, user: user, team: team) }

  let(:topic){ build( :topic ) }

  let(:participant) {
	build(:participant,
	user: build( :student, name: "Jane", fullname: "Doe, Jane", id: 1 ) ) }
  let(:participant2) { 
	build(:participant, 
	user: build( :student, name: "John", fullname: "Doe, John", id: 2 ) ) }
  let(:participant3) { 
	build(:participant, can_review: false, 
	user: build(:student, name: "King", fullname: "Titan, King", id: 3 ) ) }

  let(:assignment) { build(:assignment, id: 1, name: 'no assgt') }

Methods tested in participant model:

  • team

  • response : This method returns the response associated with the perticular participant. we use mock method to simulate return of the response from the participant response_map
describe '#response' do
    it 'Returns the responses that are associated with this participant' do
      allow( participant ).to receive( :responses ).and_return( response )
      expect( participant.responses ).to eq( response )
    end
  end
  • name: Returns the name of the participant
describe "#name" do
    it "returns the name of the user" do
      expect( participant.name ).to eq( "Jane" )
    end
  end
  • fullname : Returns the full name of the participant
describe "#fullname" do
    it "returns the full name of the user" do
      expect( participant.fullname ).to eq( "Doe, Jane" )
    end
  end
  • handle : Returns handle of the participant
describe '#handle' do
    it 'returns the handle of the participant' do
      expect( participant.handle( nil ) ).to eq( "handle" )
    end
  • delete: It deletes the participant if the participant doesn't have any association adn value of "force" is nil else it will raise an exception
describe '#delete' do
    it 'deletes a participant if no associations exist and force is nil' do
      expect( participant.delete( nil ) ).to eq( participant )
    end
    it 'deletes a participant if no associations exist and force is true' do
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      allow( team ).to receive( :teams_users ).and_return( length: 1 )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'raises execption when trying to delect participant where associations exists and force is nil' do
      allow( participant ).to receive( :team ).and_return( team )
      expect{ participant.delete( nil ) }.to raise_error.with_message("Associations exist for this participant.")
    end
  end
  • force_delete: This method is called inside the delete method . coverage for this is handled in delete method. hence there is not explicit cases are written.
  • topic_name: Retunrs the topic name associated with the participant
describe '#topic_name' do
    it 'returns the topic name associated with the participant topic name is nil' do
      expect( participant.topic_name ).to eq( '<center>—</center>' )
    end
    it 'returns the topic name associated with the participant topic name has value' do
      allow( participant ).to receive( :topic ).and_return( topic )
      expect( participant.topic_name ).to eq( "Hello world!" )   
    end
  end
  • able_to_review
  • email
  • score
  • get_permissions
  • get_authorization
  • sort_by_name

Running the Tests

To run the test run below command in terminal

 rspec spec/models/participant_spec.rb

External links

External links

References