Class: Mumukit::Server::TestServer

Inherits:
Object
  • Object
show all
Includes:
WithContentType
Defined in:
lib/mumukit/server/test_server.rb

Instance Method Summary collapse

Methods included from WithContentType

#content_type

Instance Method Details

#info(url) ⇒ Object



12
13
14
# File 'lib/mumukit/server/test_server.rb', line 12

def info(url)
  runtime.info.merge(runtime..).merge(url: url)
end

#parse_request(sinatra_request) ⇒ Object



19
20
21
# File 'lib/mumukit/server/test_server.rb', line 19

def parse_request(sinatra_request)
  OpenStruct.new parse_request_headers(sinatra_request).merge(parse_request_body(sinatra_request))
end

#parse_request_body(sinatra_request) ⇒ Object



27
28
29
30
31
# File 'lib/mumukit/server/test_server.rb', line 27

def parse_request_body(sinatra_request)
  JSON.parse(sinatra_request.body.read).tap do |it|
    I18n.locale = it['locale'] || :en
  end rescue {}
end

#parse_request_headers(sinatra_request) ⇒ Object



23
24
25
# File 'lib/mumukit/server/test_server.rb', line 23

def parse_request_headers(sinatra_request)
  {}
end

#query!(request) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/mumukit/server/test_server.rb', line 42

def query!(request)
  respond_to(request) do |r|
    results = run_query!(r)
    Mumukit::Server::ResponseBuilder.build do
      add_query_results(results)
    end
  end
end

#run_expectations!(request) ⇒ Object



66
67
68
69
70
# File 'lib/mumukit/server/test_server.rb', line 66

def run_expectations!(request)
  return [] if request.expectations.nil? || request.content.nil?

  compile_and_run runtime.expectations_hook, request
end

#run_feedback!(request, results) ⇒ Object



72
73
74
# File 'lib/mumukit/server/test_server.rb', line 72

def run_feedback!(request, results)
  runtime.feedback_hook.run!(request, results)
end

#run_tests!(request) ⇒ Object



60
61
62
63
64
# File 'lib/mumukit/server/test_server.rb', line 60

def run_tests!(request)
  return ['', :passed] if request.test.blank?

  compile_and_run runtime.test_hook, request
end

#runtimeObject



8
9
10
# File 'lib/mumukit/server/test_server.rb', line 8

def runtime
  Mumukit.runtime
end

#start_request!(_request) ⇒ Object



16
17
# File 'lib/mumukit/server/test_server.rb', line 16

def start_request!(_request)
end

#test!(request) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/mumukit/server/test_server.rb', line 33

def test!(request)
  respond_to(request) do |r|
    pipeline = Mumukit::Server::TestPipeline.new self, r
    pipeline.evaluate!
    pipeline.generate_feedback!
    pipeline.response
  end
end

#try!(request) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/mumukit/server/test_server.rb', line 51

def try!(request)
  respond_to(request) do |r|
    results = run_try!(r)
    Mumukit::Server::ResponseBuilder.build do
      add_try_results(results)
    end
  end
end