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

From Expertiza_Wiki
Jump to navigation Jump to search
 
(120 intermediate revisions by the same user not shown)
Line 3: Line 3:


==Introduction==
==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.
Our contribution to this project is to write feature tests for assignment submission by student. The tests would mock steps taken by the student when he/she manually submit the assignment.


===Problem Statement===
===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'''.  
Once an assignment is created by the instructor the only call to action for the student is to submit the assignment. 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''' framework.


===Motivation===
===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.
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the 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. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.


===Assumptions===
===Assumptions===
Line 16: Line 16:
# An instructor entry is assumed to be present in the database. The credentials for this instructor is '''instructor6''' as username and '''password''' as password.
# An instructor entry is assumed to be present in the database. The credentials for this instructor is '''instructor6''' as username and '''password''' as password.
# 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.
# 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.
# The assignment created for testing contain no teams and topic selections.
# The assignment created for testing contain no teams and topic for selection.


===Steps for manual submission===
===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:
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:
# Login with valid student username and password
# Login with valid student username and password
# Click on an assignment to submit
# Click on an assignment to submit
Line 35: Line 35:


====capybara====
====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>[https://github.com/jnicklas/capybara capybara on GitHub]</ref>
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.<ref>[https://github.com/jnicklas/capybara capybara on GitHub]</ref> To control the environments in which the scenarios are run, it provides before and after hooks.<ref>[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]</ref>
*before(:each) blocks are run before each scenario in the group
*before(:all) blocks are run once before all of the scenarios in the group
*after(:each) blocks are run after each scenario in the group
*after(:all) blocks are run once after all of the scenarios in the group


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


<div style="float:left; width:500px; 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;">
Scenario to check whether student is able to login<br>
Scenario to check whether student is able to login<br>
:Login with <b>student13</b> and <b>password</b><br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>Sign In</b> button<br>
:Page should have text content <b>Assignment</b>
:Updated page should have text content <b>Assignment</b><br>
</div>
</div>
   
   
 
<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
<div style="margin:50px float:left; width:500px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is able to submit valid link to an ongoing assignment<br>
Scenario to check whether student is able to submit valid link to an ongoing assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>Sign In</b> button<br>
:Click_on <b>OnGoing Assignment</b><br>
:Click on <b>OnGoing Assignment</b><br>
:Click_on <b>Your work</b><br>
:Click on <b>Your work</b><br>
:Upload Link <b>http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule</b><br>
:Upload link <b><nowiki>http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule</nowiki></b><br>
:Page should have text content <b>http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule</b>
:Updated page should have link <b><nowiki>http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule</nowiki></b>
</div>
</div>


<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is not able submit invalid link to an ongoing assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>OnGoing Assignment</b><br>
:Click on <b>Your work</b><br>
:Upload link <b>http://</b><br>
:Updated page should display flash message with text <b>URI is not valid</b>
</div>


<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is able to upload a file to an ongoing assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>OnGoing Assignment</b><br>
:Click on <b>Your work</b><br>
:Upload file <b>student_submission_spec.rb</b><br>
:Updated page should contain filename <b>student_submission_spec.rb</b>
</div>


<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>OnGoing Assignment</b><br>
:Click on <b>Your work</b><br>
:Upload link <b><nowiki>http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments</nowiki></b><br>
:Upload file <b>users_spec.rb</b><br>
:Updated page should have link <b><nowiki>http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments</nowiki></b><br>
:Updated page should contain filename <b>users_spec.rb</b>
</div>


<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is not able submit valid link to a finished assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>Finished Assignment</b><br>
:Click on <b>Your work</b><br>
:Page should not have <b>Upload link</b> button
</div>


<div style="width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Scenario to check whether student is able upload file to a finished assignment<br>
:Login with <b>student13</b> and <b>password</b><br>
:Click on <b>Sign In</b> button<br>
:Click on <b>Finished Assignment</b><br>
:Click on <b>Your work</b><br>
:Upload file <b>student_submission_spec.rb</b><br>
:Updated page should contain filename <b>student_submission_spec.rb</b>
</div>


<pre style="border:1px solid lightgrey; background:ivory; color:black; font-size: 13px">
===Code===
Scenario to check whether student is not able submit invalid link to an ongoing assignment
Code for the feature test consist in two files:
 
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.
Login with '''student13''' and '''password'''
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments.
Click on '''Sign In''' button
Click_on '''OnGoing Assignment'''
Click_on 'Your work'
Upload Link 'http://'
Page should display flash message with text 'URI is not valid'
</pre>


<pre style="border:1px solid lightgrey; background:ivory; color:black; font-size: 13px">
====Structure====
Scenario to check whether student is able to upload a file to an ongoing assignment


Login with '''student13''' and '''password'''
<div style="width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
Click on '''Sign In''' button
<b>require</b> files
Click_on '''OnGoing Assignment'''
Click_on 'Your work'
Upload file student_submission_spec.rb'
Page should contain filename 'student_submission_spec.rb'
</pre>


<pre style="border:1px solid lightgrey; background:ivory; color:black; font-size: 13px">
<b>RSpec.feature 'assignment submission when student' do</b>
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment


Login with '''student13''' and '''password'''
:<b>before(:all) do</b>
Click on '''Sign In''' button
::create assignments for submission
Click_on '''OnGoing Assignment'''
:<b>end</b>
Click_on 'Your work'
Upload Link 'http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments'
Upload file 'users_spec.rb'
Page should have text content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments'
Page should contain filename 'users_spec.rb'
</pre>


<pre style="border:1px solid lightgrey; background:ivory; color:black; font-size: 13px">
:<b>before(:each) do</b>
Scenario to check whether student is not able submit valid link to a finished  assignment
::capybara steps to login
:<b>end</b>


Login with '''student13''' and '''password'''
:<b>after(:all) do</b>
Click on '''Sign In''' button
::delete assignments created
Click_on '''Finished Assignment'''
:<b>end</b>
Click_on 'Your work'
Page should not have 'Upload link' button
</pre>


<pre style="border:1px solid lightgrey; background:ivory; color:black; font-size: 13px">
:<b>scenario 'submits only valid link to ongoing assignment' do</b>
Scenario to check whether student is able upload file to a finished  assignment
::mock steps using capybara
::make assertions
:<b>end</b>


Login with '''student13''' and '''password'''
:....
Click on '''Sign In''' button
:....
Click_on '''Finished Assignment'''
:....
Click_on 'Your work'
Upload file 'student_submission_spec.rb'
Page should contain filename 'student_submission_spec.rb'
</pre>


===Code===
<b>end</b>
Code for the feature test consist in two files '''assignment_creation.rb''' and '''student_assignment_submission.rb'''.
</div>


===assignment_creation.rb===
====Sample Scenario====
As the name mentions, this file consist code for creating assignments. When this file is run, two assignments are created: one in ongoing/submission phase and other in finished state. The name of the ongoing assignment is '''FeatureTest''' and the name of the finished assignment is '''LibraryRailsApp'''. Furthermore this file also adds '''student13''' as participant to both the assignments. The steps in this file are written in capybara using rspec framework. And the scenario is run with '''js enabled''', so the tester can view the steps in a browser.


<pre>
<pre style="font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
require 'rails_helper'
require 'rails_helper'
require 'spec_helper'
require 'spec_helper'
require 'assignment_setup'


RSpec.feature 'assignment creation' do
RSpec.feature 'assignment submission when student' do


   before(:each) do
   active_assignment="FeatureTest"
    # Login as instructor
  expired_assignment="LibraryRailsApp"
    visit root_path
  d = Date.parse(Time.now.to_s)
    fill_in('login_name', :with => 'instructor6')
  due_date1=(d >> 1).strftime("%Y-%m-%d %H:%M:00")
    fill_in('login_password', :with => 'password')
  due_date2=(d << 1).strftime("%Y-%m-%d %H:%M:00")
    click_on('SIGN IN')
    expect(page).to have_content('Manage')
 
    # Steps to create new ongoing public assignment
 
    # Step 1: Browse to new public assignment
    within('.content') do
      click_on('Assignments')
    end
    click_button 'New public assignment'
 
    # Step 2: Fill in details of new ongoing public assignment
    fill_in('assignment_form_assignment_name',:with => 'FeatureTest')
    select('CSC 517 Fall 2010', from: 'assignment_form_assignment_course_id')
    fill_in('assignment_form_assignment_directory_path',:with => 'csc517/oss')
    fill_in('assignment_form_assignment_spec_location',:with => 'feature test')
    check('assignment_form_assignment_availability_flag')
    click_on('Create')
 
    # Step 3: Specify grading rubrics for new ongoing public assignment
    click_on('Rubrics')
    within('#questionnaire_table_ReviewQuestionnaire') do
      select('Animation', from: 'assignment_form[assignment_questionnaire][][questionnaire_id]')
    end
    within('#questionnaire_table_AuthorFeedbackQuestionnaire') do
      select('Author feedback OTD1', from: 'assignment_form[assignment_questionnaire][][questionnaire_id]')
    end
    expect(page).to have_content("Rubrics")
    click_on('submit_btn')
    expect(page).to have_content("successfully",:wait=>5)
 
    # Step 4: Specify due dates for the new ongoing public assignment
    click_on('Due dates')
    fill_in('datetimepicker_submission_round_1',:with => '2015/11/10 23:00')
    fill_in('datetimepicker_review_round_1',:with => '2015/11/10 23:00')
    click_on('submit_btn')
 
    # Step 5: Add student13 as a participant to the new ongoing public assignment
    click_on('Manage...', :wait=>5)
 
    within(:xpath, "//table/tbody/tr[.//td[contains(.,'FeatureTest')]]") do
      find(:xpath, ".//a/img[@src='/assets/tree_view/add-participant-24.png']/..").click
    end
    expect(page).to have_content("Participants",:wait=>5)
    fill_in('user_name', :with => 'student13')
    click_on('add_a')
 
    # Steps to create new finished public assignment
    click_on('Manage...', :wait=>5)
 
    # Step 1: Browse to new public assignment
    click_button 'New public assignment'
 
    # Step 2: Fill in details of new finished public assignment
    fill_in('assignment_form_assignment_name',:with => 'LibraryRailsApp')
    select('CSC 517 Fall 2010', from: 'assignment_form_assignment_course_id')
    fill_in('assignment_form_assignment_directory_path',:with => 'csc517/rails')
    fill_in('assignment_form_assignment_spec_location',:with => 'rails application')
    check('assignment_form_assignment_availability_flag')
    click_on('Create')
 
    # Step 3: Specify grading rubrics for new finished public assignment
    click_on('Rubrics')
    within('#questionnaire_table_ReviewQuestionnaire') do
      select('Animation', from: 'assignment_form[assignment_questionnaire][][questionnaire_id]')
    end
    within('#questionnaire_table_AuthorFeedbackQuestionnaire') do
      select('Author feedback OTD1', from: 'assignment_form[assignment_questionnaire][][questionnaire_id]')
    end
    expect(page).to have_content("Rubrics")
    click_on('submit_btn')
    expect(page).to have_content("successfully",:wait=>5)
 
    # Step 4: Specify due dates for the new finished public assignment
    click_on('Due dates')
    fill_in('datetimepicker_submission_round_1',:with => '2015/9/9 23:00')
    fill_in('datetimepicker_review_round_1',:with => '2015/9/9 23:00')
    click_on('submit_btn')
 
    # Step 5: Add student13 as a participant to the new finished public assignment
    click_on('Manage...',:wait=>5)
 
    within(:xpath, "//table/tbody/tr[.//td[contains(.,'LibraryRailsApp')]]") do
      find(:xpath, ".//a/img[@src='/assets/tree_view/add-participant-24.png']/..").click
    end
    expect(page).to have_content("Participants",:wait=>5)
    fill_in('user_name', :with => 'student13')
    click_on('add_a')
 
  end
 
 
  scenario 'checked', :js => true do
 
    click_on('Manage...',:wait=>5)


    expect(page).to have_content 'FeatureTest'
  # Before all block runs once before all the scenarios are tested
     expect(page).to have_content 'LibraryRailsApp'
  before(:all) do
    # Create active/ongoing assignment
     create_assignment(active_assignment, due_date1)


     # Logout
     # Create expired/finished assignment
     find(:xpath, "//a[@href='/auth/logout']").click
     create_assignment(expired_assignment, due_date2)
   end
   end


end
  # Before each block runs before every scenario
</pre>
 
===student_assignment_submission.rb===
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:
 
<pre>
require 'rails_helper'
require 'spec_helper'
 
RSpec.feature 'student assignment submission' do
 
   before(:each) do
   before(:each) do
    # Login as a student before each scenario
     visit root_path
     visit root_path
     fill_in 'User Name', :with => 'student13'
     fill_in 'User Name', :with => 'student13'
Line 258: Line 181:
   end
   end


   scenario 'student with valid credentials' do
   # After all block runs after all the scenarios are tested
     expect(page).to have_content 'Assignment'
  after(:all)do
     # Delete active/ongoing assignment created by the test
    assignment = Assignment.find_by_name(active_assignment)
    assignment.delete
 
    # Delete expired/finished assignment created by the test
    assignment = Assignment.find_by_name(expired_assignment)
    assignment.delete
   end
   end


   scenario 'submitting only valid link to ongoing assignment' do
  # Scenario to check whether student is able to submit valid link to an ongoing assignment
     click_on 'FeatureTest'
   scenario 'submits only valid link to ongoing assignment' do
     click_on active_assignment
     click_on 'Your work'
     click_on 'Your work'
     fill_in 'submission', :with => 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
     fill_in 'submission', :with => 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
     click_on 'Upload link'
     click_on 'Upload link'
     expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
     expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'
  end
  scenario 'submitting only invalid link to ongoing assignment' do
    click_on 'FeatureTest'
    click_on 'Your work'
    fill_in 'submission', :with => 'http://'
    click_on 'Upload link'
    expect(page).to have_content 'bad URI(absolute but no path)'
  end
  scenario 'submitting only existing file to ongoing assignment' do
    click_on 'FeatureTest'
    click_on 'Your work'
    attach_file('uploaded_file', File.absolute_path('./spec/features/student_submission_spec.rb'))
    click_on 'Upload file'
    expect(page).to have_content 'student_submission_spec.rb'
  end
  scenario 'submitting link and file to ongoing assignment' do
    click_on 'FeatureTest'
    click_on 'Your work'
    fill_in 'submission', :with => 'http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments'
    click_on 'Upload link'
    attach_file('uploaded_file', File.absolute_path('./spec/features/users_spec.rb'))
    click_on 'Upload file'
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments'
    expect(page).to have_content 'users_spec.rb'
  end
  scenario 'submitting link for finished assignment' do
    click_on 'LibraryRailsApp'
    click_on 'Your work'
    expect(page).to have_no_button('Upload link')
  end
  scenario 'submitting file for finished assignment' do
    click_on 'LibraryRailsApp'
    click_on 'Your work'
    expect(page).to have_no_button('Upload file')
   end
   end


Line 317: Line 209:


* Clone the repository in a new directory
* Clone the repository in a new directory
<pre>
<pre style="font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
$ mkdir review
$ mkdir review
$ cd review
$ cd review
Line 323: Line 215:
</pre>
</pre>


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
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.
<pre>
<pre style="font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
$ cd expertiza
$ cd expertiza
$ rake db:create:all
$ rake db:create:all
$ cd Downloads/
$ mysql -u root -p expertiza_development < expertiza_scrubbed_2015_08_14.sql
$ mysql -u root -p expertiza_development < expertiza_scrubbed_2015_08_14.sql
password:
password:


$ cd expertiza
$ rake db:migrate
$ rake db:migrate
</pre>
* Check if you are able to start rails server.
<pre>
$ rails s
</pre>
* Type the command to create assignment
<pre>
rspec spec/features/assignment_creation.rb   
</pre>
</pre>


* Type the command to run tests for assignment submission
* Type the command to run tests for assignment submission
<pre>
<pre style="font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;">
rspec spec/features/student_submission_spec.rb  
rspec spec/features/student_submission_spec.rb  
</pre>
</pre>
Line 350: Line 234:
==Test Results==
==Test Results==


The following is the result after running '''rspec spec/features/assignment_creation.rb'''
The following screenshot shows the result of the rspec command.
 
<pre>
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
$       
</pre>
 
'''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 '''
 
<pre>
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.
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]
[Coveralls] Outside the CI environment, not sending data.
FAIL: 1


expertiza_developer@expertizadev: ~/review/expertiza master
=== Test Analysis ===
$     
</pre>


'''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.
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.
* The tests take around 35 seconds to run, which implies that they are fast.
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.
* They are also self-verifying as all the results are in green, which mean that all the cases passed.


=== Existing Bugs ===
=== Existing Bugs ===
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:
# A student can upload file even after the assignment is finished.
# A student can upload file even after the assignment is finished.
# A student can upload an .exe file to any assignment. Basically there is no check present on the type of file uploaded.
# A student can upload an .exe file to any assignment.




Line 422: Line 254:




[[File:1_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]
 
<center>'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.</center>
 


Figure: This screenshot shows the list of assignments along with their current stage in Expertiza.
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]


<center>'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.</center>


[[File:2_screenshot_expertiza.jpg|Select file for finished assignment]]


Figure: This screenshot shows that a student can select a file in a finished assignment in Expertiza.
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]


<center>'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.</center>


[[File:3_screenshot_expertiza.jpg|Uploaded file for finished assignment]]


Figure: This screenshot shows that a student can upload a file in a finished assignment in Expertiza.
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]


<center>'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.</center>


[[File:4_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]


Figure: This screenshot shows that a student can select an .exe file in any assignment in Expertiza.
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]


<center>'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.</center>


[[File:5_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]
=== Future Work ===


Figure: This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.
* To run the test on test database using factories and fixtures, so that the tests are completely independent.


==Project Resources==
==Project Resources==
# [https://github.com/shrenujgandhi/expertiza GitHub Link]
# [https://github.com/shrenujgandhi/expertiza GitHub Link]
# [https://youtu.be/MMRsTXR8DdI YouTube Demo]
# [https://youtu.be/_58l0VPy04M YouTube Demo]


=References=
=References=

Latest revision as of 22:25, 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 to this project is to write feature tests for assignment submission by student. The tests would mock steps taken by the student when he/she manually submit the assignment.

Problem Statement

Once an assignment is created by the instructor the only call to action for the student is to submit the assignment. 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 framework.

Motivation

Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the 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. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.

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 for selection.

Steps for manual submission

Before analyzing code, one must familiarize themselves 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 application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.<ref>capybara on GitHub</ref> To control the environments in which the scenarios are run, it provides before and after hooks.<ref>Before and after hooks</ref>

  • before(:each) blocks are run before each scenario in the group
  • before(:all) blocks are run once before all of the scenarios in the group
  • after(:each) blocks are run after each scenario in the group
  • after(:all) blocks are run once after all of the scenarios in the group

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
Updated 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:

Structure

require files

RSpec.feature 'assignment submission when student' do

before(:all) do
create assignments for submission
end
before(:each) do
capybara steps to login
end
after(:all) do
delete assignments created
end
scenario 'submits only valid link to ongoing assignment' do
mock steps using capybara
make assertions
end
....
....
....

end

Sample Scenario

require 'rails_helper'
require 'spec_helper'
require 'assignment_setup'

RSpec.feature 'assignment submission when student' do

  active_assignment="FeatureTest"
  expired_assignment="LibraryRailsApp"
  d = Date.parse(Time.now.to_s)
  due_date1=(d >> 1).strftime("%Y-%m-%d %H:%M:00")
  due_date2=(d << 1).strftime("%Y-%m-%d %H:%M:00")

  # Before all block runs once before all the scenarios are tested
  before(:all) do
    # Create active/ongoing assignment
    create_assignment(active_assignment, due_date1)

    # Create expired/finished assignment
    create_assignment(expired_assignment, due_date2)
  end

  # Before each block runs before every scenario
  before(:each) do
    # Login as a student before each scenario
    visit root_path
    fill_in 'User Name', :with => 'student13'
    fill_in 'Password', :with => 'password'
    click_on 'SIGN IN'
  end

  # After all block runs after all the scenarios are tested
  after(:all)do
    # Delete active/ongoing assignment created by the test
    assignment = Assignment.find_by_name(active_assignment)
    assignment.delete

    # Delete expired/finished assignment created by the test
    assignment = Assignment.find_by_name(expired_assignment)
    assignment.delete
  end

  # Scenario to check whether student is able to submit valid link to an ongoing assignment
  scenario 'submits only valid link to ongoing assignment' do
    click_on active_assignment
    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.

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

$ cd expertiza
$ rake db:migrate
  • Type the command to run tests for assignment submission
rspec spec/features/student_submission_spec.rb 

Test Results

The following screenshot shows the result of the rspec command.

Feature Test Result

Test Analysis

  • 7 examples, 0 failures imply that there are 7 test scenarios and none of them failed.
  • The tests take around 35 seconds to run, which implies that they are fast.
  • They are also repeatable as the assignments that are created in the before all block are also deleted in the after all block.
  • They are also self-verifying as all the results are in green, which mean that all the cases passed.

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.


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.

Future Work

  • To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.
  • Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.
  • To run the test on test database using factories and fixtures, so that the tests are completely independent.

Project Resources

  1. GitHub Link
  2. YouTube Demo

References

<references></references>

External links