CSC/ECE 517 Fall 2015/oss E1574 BKS: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 114: Line 114:


<div style="width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
<div style="width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
require <files>
<b>require<b> <files>


RSpec.feature "student assignment submission" do
<b>RSpec.feature "student assignment submission" do</b>


:<b>before(:all) do</b>
:<b>before(:all) do</b>

Revision as of 18:06, 7 November 2015

Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. <ref>Expertiza on GitHub</ref>


Introduction

Our contribution in this project is to write feature test for assignment submission by student. The test would mock steps taken by the student to manually submit the assignment.

Problem Statement

Once an assignment is created by the instructor the only call to action for the student is assignment submission. Currently, there is no feature test for assignment submission. The goal is to understand the flow of the assignment submission by student manually and mock this flow in the Feature Tests using RSpec and Capybara.

Motivation

Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test this functionality from users perspective. Feature spec allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation.

Assumptions

To successfully implement each scenario in the test, the following assumptions are taken:

  1. The feature test will use the development environment. In particular, it will use the expertiza_development database.
  2. An instructor entry is assumed to be present in the database. The credentials for this instructor is instructor6 as username and password as password.
  3. A student entry is also assumed to be present in the database. The credentials for this student is student13 as username and password as password.
  4. The assignment created for testing contain no teams and topic selections.

Steps for manual submission

Before analyzing code, one must make themselves familiar with the steps involved in assignment submission by student on Expertiza. The steps involved are:

  1. Login with valid student username and password
  2. Click on an assignment to submit
  3. Click on "Your Work"
  4. Paste the link or browse to the file containing your work
  5. Click on "Upload Link" or "Upload File" to submit deliverable

Creating the Tests

Gems involved

The gems used in feature testing are rspec-rails and capybara

rspec-rails

Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.<ref>rpsce-rails on GitHub</ref>

capybara

Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.<ref>capybara on GitHub</ref>

Test Scenarios

Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:

Scenario to check whether student is able to login

Login with student13 and password
Click on Sign In button
Page should have text content Assignment

Scenario to check whether student is able to submit valid link to an ongoing assignment

Login with student13 and password
Click on Sign In button
Click on OnGoing Assignment
Click on Your work
Upload link http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule
Updated page should have link http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule

Scenario to check whether student is not able submit invalid link to an ongoing assignment

Login with student13 and password
Click on Sign In button
Click on OnGoing Assignment
Click on Your work
Upload Link http://
Updated page should display flash message with text URI is not valid

Scenario to check whether student is able to upload a file to an ongoing assignment

Login with student13 and password
Click on Sign In button
Click on OnGoing Assignment
Click on Your work
Upload file student_submission_spec.rb
Updated page should contain filename student_submission_spec.rb

Scenario to check whether student is able to upload valid link and a file to an ongoing assignment

Login with student13 and password
Click on Sign In button
Click on OnGoing Assignment
Click on Your work
Upload Link http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments
Upload file users_spec.rb
Updated page should have link http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments
Updated page should contain filename users_spec.rb

Scenario to check whether student is not able submit valid link to a finished assignment

Login with student13 and password
Click on Sign In button
Click on Finished Assignment
Click on Your work
Page should not have Upload link button

Scenario to check whether student is able upload file to a finished assignment

Login with student13 and password
Click on Sign In button
Click on Finished Assignment
Click on Your work
Upload file student_submission_spec.rb
Updated page should contain filename student_submission_spec.rb

Code

Code for the feature test consist in two files assignment_creation.rb and student_assignment_submission.rb.

Structure

require <files>

RSpec.feature "student assignment submission" do

before(:all) do
<create assignments for submission>
end
before(:each) do
<capybara steps to login>
end
scenario "student login" do
<mock steps using capybara>
<make assertions>
end
....
....
....
after(:all) do
<delete assignments created>
end

end

Sample Scenario

This file consists of the test scenarios discussed in the Test Scenario section. The steps mainly comprises of selecting either the FeatureTest or LibraryRailsApp assignment and submitting a link or file. Again these steps are written in capybara using RSpec. But unlike assignment_creation.rb, these tests run with js disabled and hence are executed without a browser. The following are the contents of the file:


require 'rails_helper'
require 'spec_helper'

RSpec.feature 'student assignment submission' do

  before(:each) do
    visit root_path
    fill_in 'User Name', :with => 'student13'
    fill_in 'Password', :with => 'password'
    click_on 'SIGN IN'
  end

  scenario 'submitting only valid link to ongoing assignment' do
    click_on 'FeatureTest'
    click_on 'Your work'
    fill_in 'submission', :with => 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
    click_on 'Upload link'
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
  end
end

Running the tests

The following are steps required to run the test

  • Clone the repository in a new directory
$ mkdir review
$ cd review
$ git clone https://github.com/shrenujgandhi/expertiza.git

In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents. Open the terminal, traverse to that directory and type the following command

$ cd expertiza
$ rake db:create:all
$ mysql -u root -p expertiza_development < expertiza_scrubbed_2015_08_14.sql
password:

$ rake db:migrate
  • Check if you are able to start rails server.
$ rails s
  • Type the command to create assignment
rspec spec/features/assignment_creation.rb    
  • Type the command to run tests for assignment submission
rspec spec/features/student_submission_spec.rb 

Test Results

The following is the result after running rspec spec/features/assignment_creation.rb

expertiza_developer@expertizadev: ~/review/expertiza master
$ rspec spec/features/assignment_creation.rb                                                               [1:39:18]
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.

Randomized with seed 34268
.

Finished in 5 minutes 31 seconds (files took 3.92 seconds to load)
1 example, 0 failures

Randomized with seed 34268

Coverage report generated for RSpec to /home/expertiza_developer/review/expertiza/coverage. 1688 / 5005 LOC (33.73%) covered.
[Coveralls] Outside the CI environment, not sending data.
 
expertiza_developer@expertizadev: ~/review/expertiza master
$        

0 failures mean that the assignments "FeatureTest" and "LibraryRailsApp" were created successfully.


The following is the result after running rspec spec/features/student_submission_spec.rb

expertiza_developer@expertizadev: ~/review/expertiza master
$ rspec spec/features/student_submission_spec.rb                                                           [1:45:15]
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.

Randomized with seed 53903
...F...

Failures:

  1) student assignment submission submitting file for finished assignment
     Failure/Error: expect(page).to have_no_button('Upload file')
       expected #has_no_button?("Upload file") to return true, got false
     # ./spec/features/student_submission_spec.rb:61:in `block (2 levels) in <top (required)>'

Finished in 29.37 seconds (files took 5.57 seconds to load)
7 examples, 1 failure

Failed examples:

rspec ./spec/features/student_submission_spec.rb:58 # student assignment submission submitting file for finished assignment

Randomized with seed 53903

Coverage report generated for RSpec to /home/expertiza_developer/review/expertiza/coverage. 1297 / 4307 LOC (30.11%) covered.
[Coveralls] Outside the CI environment, not sending data.
FAIL: 1

expertiza_developer@expertizadev: ~/review/expertiza master
$       

7 examples, 1 failure means that our scenarios were executed but one of them failed. This scenario is "submit file for finished assignment" which states that, unlike "upload link" button, the "Upload file" button is still active. This means that user can submit a file even after the assignment is finished.

Existing Bugs

During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:

  1. A student can upload file even after the assignment is finished.
  2. A student can upload an .exe file to any assignment. Basically there is no check present on the type of file uploaded.


The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.


List of Assignments in Expertiza with Current Stage

Figure: This screenshot shows the list of assignments along with their current stage in Expertiza.


Select file for finished assignment

Figure: This screenshot shows that a student can select a file in a finished assignment in Expertiza.


Uploaded file for finished assignment

Figure: This screenshot shows that a student can upload a file in a finished assignment in Expertiza.


Select .exe file for ongoing assignment

Figure: This screenshot shows that a student can select an .exe file in any assignment in Expertiza.


Uploaded .exe file for ongoing assignment

Figure: This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.

Project Resources

  1. GitHub Link
  2. YouTube Demo

References

<references></references>

External links