Last active
December 23, 2015 18:38
-
-
Save rsepassi/6676641 to your computer and use it in GitHub Desktop.
RSpec Assessment Scorer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will run rake in each folder, check how | |
# many specs failed, and output scores | |
# (passed specs of total specs) into | |
# 'final_grades.txt' along with a note if | |
# 'rake' errored out. | |
# | |
# | |
# Expectations: | |
# | |
# Single folder that contains one folder | |
# per student. The name of each of the | |
# folders should be the student's name. | |
# One of the folders should be named | |
# 'solution' and have a 'spec' folder in | |
# it (this folder will be copied to all | |
# the student folders). | |
# | |
# Must be able to call 'rake' inside each | |
# student folder to run tests. | |
# | |
# This script should be placed at the same | |
# level as all of the student folders. | |
# | |
# Grades will be available in a file titled | |
# 'final_scores.txt' | |
require 'pp' | |
require 'fileutils' | |
PERFECT_SCORE = 19 | |
COMMAND = "rspec" | |
folder_names = [] | |
scores = {} | |
exclude = ["final_scores.txt", "grading_script.rb"] | |
names = Dir.entries('.').select do |entry| | |
# Ignore '.', '..', and any junk hidden files (e.g. .DS_Store) | |
/^[a-zA-Z].*/ =~ entry && !exclude.include?(entry) | |
end | |
puts "Scoring: " | |
puts names | |
names.each do |name| | |
Dir.chdir("#{name}") | |
unless name == "solution" | |
FileUtils.cp_r("../solution/spec", ".") | |
end | |
output = `#{COMMAND}` | |
score_line = output.split("\n").find do |line| | |
/(\d+) examples?, (\d+) failures?/ =~ line | |
end | |
examples, failures = score_line.split(", ").map do |line| | |
line.split.first.to_i | |
end | |
# Checks if `rake` errored out by checking to see if the last line | |
# of its output is "19 Examples, ..." | |
if examples != PERFECT_SCORE | |
scores[name] = 0 | |
puts "!!!!Error on #{name}!!!!" | |
Dir.chdir("..") | |
next | |
end | |
scores[name] = PERFECT_SCORE - failures | |
Dir.chdir("..") | |
puts "Scored #{name}. Score: #{scores[name]} of #{PERFECT_SCORE}" | |
end | |
puts "\n" * 5 | |
puts "-" * 10 | |
File.open("final_scores.txt", 'w') do |f| | |
scores.each do |name, score| | |
next if name == "solution" | |
text = "#{name}: #{score} of #{PERFECT_SCORE}" | |
text << " ERROR!!" if score == 0 | |
puts text | |
f.puts text | |
end | |
end | |
puts | |
puts "Scores available in 'final_scores.txt'" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment