E1848 Write unit tests for assignment team
For this progect, the goal is to wirte up unit tests for assignment_team.rb
Project Introduction
assignment_team.rb is the child class of team.rb. It is used to manage student teams in assignments. There are not enough unit tests for this model in expertiza. The following tests are added to assignment_team.rb in this project.
Unit Tests
Unit Test Tool
Rspec
Unit Test File
expertiza/spec/models/assignment_team_spec.rb
Unit Test Steps
- Create unit test cases in the assignment_team_spec.rb
- run rspec spec/models/assignment_team_spec.rb under expertiza directory
- the rspec outputs the number of test cases that are passed and those that are failed.
Unit Test Cases
Testing has_submissions?
Includes 4 testcases:
1.The team doesn't submit any file or link.
let(:team2) { build(:assignment_team, id: 2, parent_id: 1, name: "team2", submitted_hyperlinks: "") } it "no file or no link" do expect(team2.has_submissions?).to eq(false) end
2.The team submits a link instead of files.
let(:team1) { build(:assignment_team, id: 1, parent_id: 1, name: "team1", submitted_hyperlinks: "http://example.com") } it "submitted hyperlinks" do expect(team1.has_submissions?).to eq(true) end
3. The team submits some files. Stub is used to emulate the scenario that the team has submitted a file.
it "returns true" do allow(team2).to receive(:submitted_files).and_return([double(:File)]) expect(team2.has_submissions?).to be true end