examiner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47e2a6a62cf3492f80d7e9e1e6025c2efea11e49
4
+ data.tar.gz: 8f06bf636a2da099d282209e5e018069d13684bc
5
+ SHA512:
6
+ metadata.gz: ad52fa7af0abfadcd4ea88bd9f3c4f9352b72362e2925db404362d79f3416100f67c21de99360f735e73d8275a0e345fc4ac7bed1817effea34772a9d8915391
7
+ data.tar.gz: 8fa1fd9f36692ed873f77ab693ebcc49855649a6237ab61250b04e828fce137dff06856cc8140882e71b12ade06ce5abebb70391d2bb995524c11e0d8086e4e9
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in examiner.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sebastien Saunier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ [![Build Status](https://travis-ci.org/ssaunier/examiner.svg?branch=master)](https://travis-ci.org/ssaunier/examiner)
2
+ [![Gem Version](https://badge.fury.io/rb/examiner.svg)](http://badge.fury.io/rb/examiner)
3
+
4
+ # Examiner
5
+
6
+ Grade a student's exercise solution.
7
+
8
+ Assumptions:
9
+
10
+ - The exercise uses [minitest](https://github.com/seattlerb/minitest) to be checkied
11
+ - There is a `Rakefile` in the exercise folder
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'examiner'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ ## Usage
26
+
27
+ You can quickly grade a student's exercise solution with
28
+ the following code.
29
+
30
+ ```ruby
31
+ exercise_directory = "/path/to/student_exercise_with_rakefile"
32
+
33
+ runner = Examiner::RakeRunner.new
34
+ runner.run exercise_directory
35
+ if runner.success?
36
+ puts "Results: #{runner.tests - runner.failures}/#{runner.tests}"
37
+ end
38
+
39
+ # You can display stdout and stderr
40
+ puts runner.stdout_lines.join
41
+ puts runner.stderr_lines.join
42
+ ```
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.libs.push 'spec'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'examiner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "examiner"
8
+ spec.version = Examiner::VERSION
9
+ spec.authors = ["Sebastien Saunier"]
10
+ spec.email = ["seb@saunier.me"]
11
+ spec.summary = %q{Grade a student's exercise solution using rake and minitest}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,2 @@
1
+ require "examiner/version"
2
+ require "examiner/rake_runner"
@@ -0,0 +1,32 @@
1
+ module Examiner
2
+ class MinitestParser
3
+ attr_reader :tests, :failures
4
+
5
+ def initialize
6
+ @tests, @assertions, @failures, @errors, @skips = 0, 0, 0, 0, 0
7
+ @success = false
8
+ end
9
+
10
+ def parse(lines)
11
+ return unless lines.kind_of? Enumerable
12
+
13
+ lines.reverse_each.each do |line|
14
+ result = PATTERN.match line
15
+ if result
16
+ result.names.zip(result.captures.map(&:to_i)).each do |feature, number|
17
+ instance_variable_set :"@#{feature}", number
18
+ end
19
+ @success = true
20
+ break
21
+ end
22
+ end
23
+ end
24
+
25
+ def success?
26
+ @success
27
+ end
28
+
29
+ private
30
+ PATTERN = /(?<tests>\d+) (tests|runs), (?<assertions>\d+) assertions, (?<failures>\d+) failures, (?<errors>\d+) errors, (?<skips>\d+) skips/
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ require 'open3'
2
+ require_relative 'minitest_parser'
3
+
4
+ module Examiner
5
+ class RakeRunner
6
+ attr_reader :stdout_lines, :stderr_lines
7
+ attr_reader :tests, :failures
8
+
9
+ def initialize
10
+ @tests, @failures = 0, 0
11
+ @stdout_lines, @stderr_lines = [], []
12
+ @success = false
13
+ end
14
+
15
+ def run(directory)
16
+ return unless rakefile?(directory)
17
+
18
+ Open3.popen3('rake', chdir: directory) do |_, stdout, stderr, wait_thr|
19
+ @stdout_lines, @stderr_lines = stdout.readlines, stderr_lines
20
+ parse_stdout
21
+ end
22
+ end
23
+
24
+ def success?
25
+ @success
26
+ end
27
+
28
+ private
29
+
30
+ def parse_stdout
31
+ parser = MinitestParser.new
32
+ parser.parse @stdout_lines
33
+ if parser.success?
34
+ @tests = parser.tests
35
+ @failures = parser.failures
36
+ @success = true
37
+ end
38
+ end
39
+
40
+ def rakefile?(directory)
41
+ File.exists?(File.join(directory, 'Rakefile'))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Examiner
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+ require "examiner/minitest_parser"
3
+
4
+ module Exmanier
5
+ describe "MinitestParser" do
6
+ let(:parser) { Examiner::MinitestParser.new }
7
+
8
+ describe "#parse" do
9
+ it "must not raise if given nil" do
10
+ parser.parse nil
11
+ parser.success?.must_equal false
12
+ end
13
+
14
+ it "must not raise if given an empty array" do
15
+ parser.parse []
16
+ parser.success?.must_equal false
17
+ end
18
+
19
+ it "must parse correctly a Minitest stdout" do
20
+ lines = [ "", "4 runs, 3 assertions, 3 failures, 0 errors, 0 skips", "rake aborted!" ]
21
+ parser.parse lines
22
+ parser.tests.must_equal 4
23
+ parser.failures.must_equal 3
24
+ parser.success?.must_equal true
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "examiner/rake_runner"
3
+
4
+ module Exmanier
5
+ describe "RakeRunner" do
6
+ let(:runner) { Examiner::RakeRunner.new }
7
+
8
+ it "should handle a folder without Rakefile" do
9
+ runner.run directory("no_rake_file")
10
+ runner.success?.must_equal false
11
+ end
12
+
13
+ it "should be successful for 1_test_0_failure use case" do
14
+ runner.run directory("1_test_0_failure")
15
+ runner.success?.must_equal true
16
+ runner.tests.must_equal 1
17
+ runner.failures.must_equal 0
18
+ runner.stdout_lines.wont_be_empty
19
+ runner.stderr_lines.must_be_empty
20
+ end
21
+
22
+ it "should be successful for 2_tests_1_failure use case" do
23
+ runner.run directory("2_tests_1_failure")
24
+ runner.success?.must_equal true
25
+ runner.tests.must_equal 2
26
+ runner.failures.must_equal 1
27
+ runner.stdout_lines.wont_be_empty
28
+ runner.stderr_lines.must_be_empty
29
+ end
30
+
31
+ it "should handle a file with syntax errors" do
32
+ runner.run directory("syntax_error")
33
+ runner.success?.must_equal false
34
+ end
35
+
36
+ def directory(name)
37
+ File.expand_path("../../support/#{name}", __FILE__)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
@@ -0,0 +1,12 @@
1
+ def plus_one(i)
2
+ i + 1
3
+ end
4
+
5
+ task :default do
6
+ require "minitest/autorun"
7
+ describe "#plus_one" do
8
+ it "should return 2 when passed 1" do
9
+ plus_one(1).must_equal 2
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ def plus_one(i)
2
+ i + 1
3
+ end
4
+
5
+ def minus_one(i)
6
+ i # Boffus implementation!
7
+ end
8
+
9
+ task :default do
10
+ require "minitest/autorun"
11
+ describe "#plus_one" do
12
+ it "should return 2 when passed 1" do
13
+ plus_one(1).must_equal 2
14
+ end
15
+ end
16
+ describe "#minus_one" do
17
+ it "should return 2 when passed 3" do
18
+ minus_one(3).must_equal 2
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ def plus_one(i)
2
+ i + 1
3
+ end
4
+
5
+ def foo # Deliberate syntax error
6
+
7
+ task :default do
8
+ require "minitest/autorun"
9
+ describe "#plus_one" do
10
+ it "should return 2 when passed 1" do
11
+ plus_one(1).must_equal 2
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: examiner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastien Saunier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Grade a student's exercise solution using rake and minitest
42
+ email:
43
+ - seb@saunier.me
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - examiner.gemspec
55
+ - lib/examiner.rb
56
+ - lib/examiner/minitest_parser.rb
57
+ - lib/examiner/rake_runner.rb
58
+ - lib/examiner/version.rb
59
+ - spec/examiner/minitest_parser_spec.rb
60
+ - spec/examiner/rake_runner_spec.rb
61
+ - spec/spec_helper.rb
62
+ - spec/support/1_test_0_failure/Rakefile
63
+ - spec/support/2_tests_1_failure/Rakefile
64
+ - spec/support/syntax_error/Rakefile
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.2.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Grade a student's exercise solution using rake and minitest
89
+ test_files:
90
+ - spec/examiner/minitest_parser_spec.rb
91
+ - spec/examiner/rake_runner_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/1_test_0_failure/Rakefile
94
+ - spec/support/2_tests_1_failure/Rakefile
95
+ - spec/support/syntax_error/Rakefile