Class: Mumukit::Bridge::Runner
- Inherits:
-
Object
- Object
- Mumukit::Bridge::Runner
- Defined in:
- lib/mumukit/bridge/runner.rb
Instance Attribute Summary collapse
-
#test_runner_url ⇒ Object
Returns the value of attribute test_runner_url.
Instance Method Summary collapse
- #info ⇒ Object
-
#initialize(test_runner_url) ⇒ Runner
constructor
A new instance of Runner.
- #post_to_server(request, route, timeout = 10) ⇒ Object
- #run_query!(request) ⇒ Object
-
#run_tests!(request) ⇒ Object
Expects a hash string, extra: string, content: string, expectations: [{binding:string, inspection: string)]} Returns a hash string, test_results: [{title:string, status:symbol, result:string], status: :passed|:failed|:errored|:aborted|:passed_with_warnings, expectation_results: [inspection:string, result:symbol], feedback: string}.
- #with_sever_response(request, route, &action) ⇒ Object
Constructor Details
#initialize(test_runner_url) ⇒ Runner
Returns a new instance of Runner.
11 12 13 |
# File 'lib/mumukit/bridge/runner.rb', line 11 def initialize(test_runner_url) @test_runner_url = test_runner_url end |
Instance Attribute Details
#test_runner_url ⇒ Object
Returns the value of attribute test_runner_url.
9 10 11 |
# File 'lib/mumukit/bridge/runner.rb', line 9 def test_runner_url @test_runner_url end |
Instance Method Details
#info ⇒ Object
36 37 38 39 40 |
# File 'lib/mumukit/bridge/runner.rb', line 36 def info JSON.parse RestClient.get( "#{test_runner_url}/info", content_type: :json) end |
#post_to_server(request, route, timeout = 10) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/mumukit/bridge/runner.rb', line 49 def post_to_server(request, route, timeout=10) JSON.parse RestClient::Request.new( method: :post, url: "#{test_runner_url}/#{route}", payload: request.to_json, timeout: timeout, open_timeout: timeout, headers: {content_type: :json}).execute() end |
#run_query!(request) ⇒ Object
30 31 32 33 34 |
# File 'lib/mumukit/bridge/runner.rb', line 30 def run_query!(request) with_sever_response request, 'query' do |it| {status: it['exit'].to_sym, result: it['out']} end end |
#run_tests!(request) ⇒ Object
Expects a hash
{test: string, extra: string, content: string, expectations: [{binding:string, inspection: string})]}
Returns a hash
{result: string,
test_results: [{title:string, status:symbol, result:string}],
status: :passed|:failed|:errored|:aborted|:passed_with_warnings,
expectation_results: [{binding:string, inspection:string, result:symbol}],
feedback: string}
23 24 25 26 27 28 |
# File 'lib/mumukit/bridge/runner.rb', line 23 def run_tests!(request) with_sever_response request, 'test' do |response| response_type = ResponseType.for_response response response_type.parse response end end |
#with_sever_response(request, route, &action) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/mumukit/bridge/runner.rb', line 42 def with_sever_response(request, route, &action) response = post_to_server(request, route) action.call(response) rescue Exception => e {result: e., status: :errored} end |