mumukit-bridge 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmNlZThkYjM3YzYxOWMxM2M5Y2MwNWE5MmNhNGI1YWRiMjViZDY1Mw==
4
+ ODBiZTk4NTliZjdjODllODNhZWZjZmJlMDI2Y2Y2MTFkNmY3YWVmNA==
5
5
  data.tar.gz: !binary |-
6
- YzZlNmQ4ZGEzOWU3ZTI1ZjUyYjhlMmYyNGI0OTE3MDY1MWIyMjNhMA==
6
+ NWZhOGVlN2ZlZWYwNDFiYTE4MWEwMGM0ZDdjMDI0YmE1NWEwYzVlNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmNhYjU4ZGQ0ZjUwMTE2ZjA4OWFiMTRmM2RiODZiNTc3NjM4MzYyYmYxOTBm
10
- ZjkwMGY2MzIwNDg4NTgxMThlNmIxYjAzMDAzZDM4NzY0NGIwYjdiYmE5ZjMz
11
- OTMxMTU0YWJmN2YxZGI2NWEwNGE2MDAyOTBmZjUzOWQ0Y2Q1NmE=
9
+ NTM5YjJmN2QwYjI0MTc5MzI1YThlNDc0MjNiOTBiOTc3NGU3NjhlN2JkZGMx
10
+ NzA3ZDhlYmRkM2IzZTEzZTViZGEwMjNjNjJhMWU1ZjllZTMyY2E4ZWI0NGFh
11
+ ZTVmNTMxOGM5NjNlMjdkYTYxMDA2ZGE5NmFjYWI4YjM4OWRmN2E=
12
12
  data.tar.gz: !binary |-
13
- MGYyM2U5ZmM0NGNiNTFmMDg0Njg2Y2I4ZDc5NDQ4YWI4NjhjYmFjNjIyNWQ0
14
- ZGRiZDZlZWI4NTM4OGZhMWJjZTcyZGVkMThlMWJkNWUxYmM5NTk1MTA1ODJi
15
- YjJkMzZjMmMxZDgxNzRkZTBhMDc4M2E2ZWM1YmIwYjRlYmI1NGE=
13
+ ODNkOGEyNzY2ZWEzODYxMmViMTRjZmVjN2E5MmNhODExM2Y3ZTRmZDY4ZTEz
14
+ OGM3MzYzZjI2ZWM3OGZhZDA5YmVmMjY1ZDMzMWE1MjNiYjg3NjY0YzUzZGI2
15
+ ZjZlNGRlNDJkMzlhMTVmZTUzNzVhOTZjMDdmNmExNmQ5ZTE5OTM=
@@ -1,6 +1,12 @@
1
1
  require 'mumukit/bridge/version'
2
+ require 'mumukit/bridge/response_type'
3
+ require 'mumukit/bridge/array'
4
+ require 'mumukit/bridge/boolean'
5
+
2
6
  require 'rest_client'
3
7
 
8
+ require 'active_support/core_ext/object'
9
+
4
10
  module Mumukit
5
11
  module Bridge
6
12
  class Bridge
@@ -13,25 +19,17 @@ module Mumukit
13
19
  # Expects a hash
14
20
  # {test: string, extra: string, content: string, expectations: [{binding:string, inspection: string})]}
15
21
  # Returns a hash
16
- # {result: string, status: string, expectation_results: [{binding:string, inspection:string, result:symbol}], feedback: string}
22
+ # {result: string,
23
+ # test_results: [{title:string, status:symbol, result:string}],
24
+ # status: :passed|:failed|:errored|:aborted|:passed_with_warnings,
25
+ # expectation_results: [{binding:string, inspection:string, result:symbol}],
26
+ # feedback: string}
17
27
  def run_tests!(request)
18
28
  response = post_to_server(request)
19
-
20
- {result: response['out'],
21
- status: response['exit'],
22
- expectation_results: parse_expectation_results(response['expectationResults'] || []),
23
- feedback: response['feedback'] || ''}
24
-
29
+ response_type = ResponseType.for_response response
30
+ response_type.parse response
25
31
  rescue Exception => e
26
- {result: e.message, status: :failed}
27
- end
28
-
29
- def parse_expectation_results(results)
30
- results.map do |it|
31
- {binding: it['expectation']['binding'],
32
- inspection: it['expectation']['inspection'],
33
- result: it['result'] ? :passed : :failed}
34
- end
32
+ {result: e.message, status: :errored}
35
33
  end
36
34
 
37
35
  def post_to_server(request)
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def fetch_mumuki_status(key)
3
+ all? { |it| it[key] == :passed }.to_mumuki_status
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class TrueClass
2
+ def to_mumuki_status
3
+ :passed
4
+ end
5
+ end
6
+
7
+ class FalseClass
8
+ def to_mumuki_status
9
+ :failed
10
+ end
11
+ end
@@ -0,0 +1,65 @@
1
+ module Mumukit::Bridge
2
+ module ResponseType
3
+ class Base
4
+ def parse(response)
5
+ expectation_results = parse_expectation_results(response['expectationResults'] || [])
6
+ feedback = response['feedback'] || ''
7
+ result = response['out'] || ''
8
+
9
+ build_hash(response).
10
+ merge(feedback: feedback, expectation_results: expectation_results, result: result).
11
+ update(status: expectation_results.fetch_mumuki_status(:result)) { |_, t, e| global_status(t, e) }
12
+ end
13
+
14
+ def global_status(test_status, expectation_status)
15
+ if test_status == :passed && expectation_status == :failed
16
+ :passed_with_warnings
17
+ else
18
+ test_status
19
+ end
20
+ end
21
+
22
+ def parse_expectation_results(results)
23
+ results.map do |it|
24
+ {binding: it['expectation']['binding'],
25
+ inspection: it['expectation']['inspection'],
26
+ result: it['result'].to_mumuki_status}
27
+ end
28
+ end
29
+ end
30
+
31
+ class Structured < Base
32
+ def build_hash(response)
33
+ test_results = parse_test_results(response['testResults'])
34
+ {response_type: :structured,
35
+ test_results: test_results,
36
+ status: test_results.fetch_mumuki_status(:status)}
37
+ end
38
+
39
+ private
40
+
41
+ def parse_test_results(results)
42
+ results.map { |it| {
43
+ title: it['title'],
44
+ status: it['status'].to_sym,
45
+ result: it['result']} }
46
+ end
47
+ end
48
+
49
+ class Unstructured < Base
50
+ def build_hash(response)
51
+ {response_type: :unstructured,
52
+ test_results: [],
53
+ status: response['exit'].to_sym}
54
+ end
55
+ end
56
+
57
+ def self.structured_test_results?(response)
58
+ response['testResults'].present?
59
+ end
60
+
61
+ def self.for_response(response)
62
+ structured_test_results?(response) ? Structured.new : Unstructured.new
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Bridge
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit-bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - flbulgarelli@yahoo.com.ar
@@ -74,6 +88,9 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - lib/mumukit/bridge.rb
91
+ - lib/mumukit/bridge/array.rb
92
+ - lib/mumukit/bridge/boolean.rb
93
+ - lib/mumukit/bridge/response_type.rb
77
94
  - lib/mumukit/bridge/version.rb
78
95
  homepage: http://github.com/uqbar-project/mumukit-bridge
79
96
  licenses: