grade_runner 0.0.3 → 0.0.4.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bca6a9499dd2c470ddca0987086391fec5f6b279949dfbbd8467375ddbe83024
4
- data.tar.gz: f22699e5ba8d8245b4668d8d9e618b0502da9e7f06b87d852b22c17659ceb8b3
3
+ metadata.gz: a0d5594572bec1135a4b450337a2e19bb4ebac70391fb5a07f44b144a391598c
4
+ data.tar.gz: 6cce5686313ee19768a9a4d47b629570b34d24a3c1e6387ec4a3de1b628045db
5
5
  SHA512:
6
- metadata.gz: deeb0a73556460275d08bb98418e3d9d466515aa4f617cad9e70d4eddd8d497cf8f6f4400f8443e50c019bb399f3650ec7340404891096513410344b76a635ce
7
- data.tar.gz: c5ffbb984fb6202b03e7122a5d48fbc1cc22a3d3ab7e794ef352f9f40ec5b560c1ebb78c8412c61bf85eef3200e7055506425dafc91888983afc9f5f37e74e75
6
+ metadata.gz: 63137c0908311fa1e8be305dc58c22a78052f9e0eed81559707ff54d77ab6e33273fe11fab42fbcc678e38f43fab2b5307de8a640600a1c9bcf4da943f954fa5
7
+ data.tar.gz: b84198012f42fc3beb0c997b6d0713a9a42e32229c3a58e188975d261922f825320366ae86e78f7d91fe68e1d3254e3c9bf4e5a6686f69b19bda39bcac767598
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GEM
12
12
  descendants_tracker (0.0.4)
13
13
  thread_safe (~> 0.3, >= 0.3.1)
14
14
  diff-lcs (1.3)
15
- docile (1.3.1)
15
+ docile (1.3.2)
16
16
  faraday (0.15.4)
17
17
  multipart-post (>= 1.2, < 3)
18
18
  git (1.5.0)
@@ -36,12 +36,12 @@ GEM
36
36
  rake
37
37
  rdoc
38
38
  semver
39
- jwt (2.1.0)
39
+ jwt (2.2.1)
40
40
  method_source (0.9.2)
41
41
  mini_portile2 (2.4.0)
42
42
  multi_json (1.13.1)
43
43
  multi_xml (0.6.0)
44
- multipart-post (2.0.0)
44
+ multipart-post (2.1.1)
45
45
  nokogiri (1.10.3)
46
46
  mini_portile2 (~> 2.4.0)
47
47
  oauth2 (1.4.1)
@@ -68,7 +68,7 @@ GEM
68
68
  pry-stack_explorer (0.4.9.3)
69
69
  binding_of_caller (>= 0.7)
70
70
  pry (>= 0.9.11)
71
- public_suffix (3.0.3)
71
+ public_suffix (3.1.0)
72
72
  rack (2.0.7)
73
73
  rake (12.3.2)
74
74
  rdoc (3.12.2)
data/Rakefile CHANGED
@@ -40,7 +40,7 @@ task :default => :spec
40
40
 
41
41
  require 'rdoc/task'
42
42
  Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+ version = File.file?('VERSION') ? File.read('VERSION') : ""
44
44
 
45
45
  rdoc.rdoc_dir = 'rdoc'
46
46
  rdoc.title = "grade_runner #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4.pre.1
data/grade_runner.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: grade_runner 0.0.3 ruby lib
5
+ # stub: grade_runner 0.0.3.pre.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "grade_runner".freeze
9
- s.version = "0.0.3"
9
+ s.version = "0.0.3.pre.3"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
11
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Raghu Betina".freeze]
14
- s.date = "2019-06-19"
14
+ s.date = "2019-06-26"
15
15
  s.description = "This gem runs your RSpec test suite and posts the JSON output to grades.firstdraft.com.".freeze
16
16
  s.email = "raghu@firstdraft.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -1,11 +1,11 @@
1
- require 'rails'
1
+ # require 'rails'
2
2
 
3
3
  module GradeRunner
4
- class Railtie < ::Rails::Railtie
4
+ # class Railtie < ::Rails::Railtie
5
5
 
6
- rake_tasks do
7
- load "tasks/grade_runner.rake"
8
- load "tasks/grade.rake"
9
- end
10
- end
6
+ # rake_tasks do
7
+ # load "tasks/grade_runner.rake"
8
+ # load "tasks/grade.rake"
9
+ # end
10
+ # end
11
11
  end
data/lib/tasks/grade.rake CHANGED
@@ -1,23 +1,28 @@
1
+ require 'yaml'
2
+ require 'net/http'
3
+ require "json"
4
+ require_relative "../grade_runner/runner"
5
+
1
6
  desc "Alias for \"grade:next\"."
2
7
  task grade: "grade:all" do
3
8
  end
4
9
 
5
10
  namespace :grade do
6
11
  desc "Run all tests and submit a build report."
7
- task all: :environment do
12
+ task :all do
8
13
  ARGV.each { |a| task a.to_sym do ; end }
9
14
  input_token = ARGV[1]
10
15
  file_token = nil
11
16
 
12
- config_file_name = Rails.root.join("grades.yml")
17
+ config_file_name = File.join(project_root, "grades.yml")
13
18
  student_config = {}
14
19
  student_config["submission_url"] = "https://grades.firstdraft.com"
15
20
 
16
- if File.exist?(config_file_name)
21
+ if File.file?(config_file_name)
17
22
  begin
18
23
  config = YAML.load_file(config_file_name)
19
24
  rescue
20
- abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rails grade:all` again, and be sure to provide the access token for THIS project.".red
25
+ abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rake grade:all` again, and be sure to provide the access token for THIS project.".red
21
26
  end
22
27
  submission_url = config["submission_url"]
23
28
  file_token = config["personal_access_token"]
@@ -26,11 +31,13 @@ namespace :grade do
26
31
  submission_url = "https://grades.firstdraft.com"
27
32
  end
28
33
 
29
- if input_token.present?
34
+ if input_token != false && input_token != "" && input_token != " " && !input_token.nil? && input_token != [] && input_token != {}
35
+
30
36
  token = input_token
31
37
  student_config["personal_access_token"] = input_token
32
38
  update_config_file(config_file_name, student_config)
33
- elsif input_token.nil? && file_token.present?
39
+ elsif input_token.nil? && file_token != false && file_token != "" && file_token != " " && !file_token.nil? && file_token != [] && file_token != {}
40
+
34
41
  token = file_token
35
42
  elsif input_token.nil? && file_token.nil?
36
43
  puts "Enter your access token for this project"
@@ -53,15 +60,19 @@ namespace :grade do
53
60
  end
54
61
  end
55
62
 
56
- if token.present?
63
+ if token != false && token != "" && token != " " && !token.nil? && token != [] && token != {}
57
64
  if is_valid_token?(submission_url, token) == false
58
65
  student_config["personal_access_token"] = nil
59
66
  update_config_file(config_file_name, student_config)
60
- puts "Your access token looked invalid, so we've reset it to be blank. Please re-run rails grade and, when asked, copy-paste your token carefully from the assignment page."
67
+ puts "Your access token looked invalid, so we've reset it to be blank. Please re-run rake grade and, when asked, copy-paste your token carefully from the assignment page."
61
68
  else
62
- path = Rails.root.join("/tmp/output/#{Time.now.to_i}.json")
63
- `bin/rails db:migrate RAILS_ENV=test`
64
- `RAILS_ENV=test bundle exec rspec --order default --format JsonOutputFormatter --out #{path}`
69
+ path = File.join(project_root, "/tmp/output/#{Time.now.to_i}.json")
70
+ # `bin/rails db:migrate RAILS_ENV=test`
71
+ if Dir.exist?("bin")
72
+ `bin/rake db:migrate`
73
+ end
74
+ # `RAILS_ENV=test bundle exec rspec --order default --format JsonOutputFormatter --out #{path}`
75
+ `bundle exec rspec -I spec/support -f JsonOutputFormatter --out #{path}`
65
76
  rspec_output_json = JSON.parse(File.read(path))
66
77
  username = ""
67
78
  reponame = ""
@@ -70,19 +81,21 @@ namespace :grade do
70
81
  GradeRunner::Runner.new(submission_url, token, rspec_output_json, username, reponame, sha, "manual").process
71
82
  end
72
83
  else
73
- puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rails grade ... command shown there."
84
+ puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rake grade ... command shown there."
74
85
  end
75
86
  end
76
87
 
77
88
  desc "Run only the next failing test."
78
- task next: :environment do
79
- path = Rails.root.join("examples.txt")
80
- if File.exist?(path)
81
- `bin/rails db:migrate RAILS_ENV=test`
82
- puts `RAILS_ENV=test bundle exec rspec --next-failure --format HintFormatter`
89
+ task :next do
90
+ path = File.join(__dir__, "examples.txt")
91
+ if File.file?(path)
92
+ # `bin/rails db:migrate RAILS_ENV=test`
93
+ # puts `RAILS_ENV=test bundle exec rspec --next-failure --format HintFormatter`
94
+ puts `bundle exec rspec --next-failure --format HintFormatter`
83
95
  else
84
- puts `RAILS_ENV=test bundle exec rspec`
85
- puts "Please rerun rails grade:next to run the first failing spec"
96
+ # puts `RAILS_ENV=test bundle exec rspec`
97
+ puts `bundle exec rspec`
98
+ puts "Please rerun rake grade:next to run the first failing spec"
86
99
  end
87
100
  end
88
101
 
@@ -93,15 +106,31 @@ def update_config_file(config_file_name, config)
93
106
  end
94
107
 
95
108
  def is_valid_token?(root_url, token)
96
- return false unless token.is_a?(String) && token =~ /^[1-9A-Za-z][^OIl]{23}$/
109
+ return false unless token.is_a?(String) && !(token =~ /^[1-9A-Za-z][^OIl]{23}$/).nil?
110
+
97
111
  url = "#{root_url}/submissions/validate_token?token=#{token}"
98
112
  uri = URI.parse(url)
113
+
99
114
  req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json')
115
+
100
116
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
101
117
  http.request(req)
102
118
  end
119
+
103
120
  result = JSON.parse(res.body)
104
121
  result["success"]
105
122
  rescue => e
106
123
  return false
107
124
  end
125
+
126
+ def project_root
127
+ if defined?(Rails)
128
+ return Rails.root
129
+ end
130
+
131
+ if defined?(Bundler)
132
+ return Bundler.root
133
+ end
134
+
135
+ Dir.pwd
136
+ end
@@ -1,14 +1,16 @@
1
+ require 'yaml'
2
+
1
3
  namespace :grade_runner do
2
4
  desc "Grade project"
3
- task runner: :environment do
5
+ task :runner do
4
6
  default_submission_url = "https://grades.firstdraft.com"
5
7
  config = {}
6
- path = Rails.root.join("grades.yml")
7
- if File.exist?(path)
8
+ path = File.join(__dir__,"grades.yml")
9
+ if File.file?(path)
8
10
  begin
9
11
  config = YAML.load_file(path)
10
12
  rescue
11
- abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rails grade:all` again, and be sure to provide the access token for THIS project.".red
13
+ abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rake grade:all` again, and be sure to provide the access token for THIS project.".red
12
14
  end
13
15
  end
14
16
  rspec_output_json = JSON.parse(File.read("#{ENV['CIRCLE_ARTIFACTS']}/output/rspec_output.json"))
@@ -16,10 +18,15 @@ namespace :grade_runner do
16
18
  reponame = ENV["CIRCLE_PROJECT_REPONAME"]
17
19
  sha = ENV["CIRCLE_SHA1"]
18
20
  token = ENV['GRADES_PERSONAL_ACCESS_TOKEN']
19
- if token.present?
21
+ if token != false &&
22
+ token != "" &&
23
+ token != " " &&
24
+ !token.nil? &&
25
+ token != [] &&
26
+ token != {}
20
27
  GradeRunner::Runner.new('', config['submission_url'] || default_submission_url, token, rspec_output_json, username, reponame, sha, 'circle_ci').process
21
28
  else
22
- puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rails grade ... command shown there."
29
+ puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rake grade ... command shown there."
23
30
  end
24
31
  end
25
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grade_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -202,9 +202,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - ">="
205
+ - - ">"
206
206
  - !ruby/object:Gem::Version
207
- version: '0'
207
+ version: 1.3.1
208
208
  requirements: []
209
209
  rubyforge_project:
210
210
  rubygems_version: 2.7.8