Class: JSONAPI::Grader::ServerGrader

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/grader/server_grader.rb

Constant Summary collapse

SCENARII =
[Server::EmptyCollectionScenario.new]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ServerGrader

Returns a new instance of ServerGrader.



8
9
10
# File 'lib/jsonapi/grader/server_grader.rb', line 8

def initialize(options = {})
  @host = options[:host]
end

Instance Method Details

#gradeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jsonapi/grader/server_grader.rb', line 12

def grade
  compliance = true
  score = 0
  max_score = 0
  SCENARII.each do |scenario|
    STDERR.print "Running scenario #{scenario.name}... "
    $stderr.flush

    begin
      scenario.call(@host)
      STDERR.puts "passed"
      score += scenario.score
    rescue Exception => error
      STDERR.puts "failed"
      STDERR.puts scenario.description
      STDERR.puts ">>> #{error}"
      compliance = false if scenario.required
    end
    max_score += scenario.score
  end

  STDERR.puts "Compliance: #{compliance}"
  score_percent = (100.0 * score / max_score).round(2)
  STDERR.puts "Score: #{score} / #{max_score} (#{score_percent}%)"

  score
end