mumuki-html-runner 1.6.1 → 1.6.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 08c96b4d60cea964b43ffb8bde5cc0fdfdfac145e96e9c6efe9ce8561be306ec
4
- data.tar.gz: 8bc74778d1079957c5f1988f2fee4e77966817422c3bf3006246a5fcbb57028d
3
+ metadata.gz: 300794e63c7cac26dd6c8f769f2e36002c7e867f779cf860c17b64479ed02848
4
+ data.tar.gz: 9ffb85ae1c11f1f541e73181cd41e04e77bc2fa88ecfb69bd16e857e4ae01ae6
5
5
  SHA512:
6
- metadata.gz: 4568cfca7e92895d4d41dbed6fa9f989248463181acc2bd8425662b868dadca0105f3f6b96b6a630bfdd105b097ed9d1c363fed470b3195f7e6b0c9e73f772b9
7
- data.tar.gz: e0ff4ddae4c7f62bfc639b4538a02736a9115633da409feebb86bfae0490820e1da9d4a5752d97bde21e63340fb61c5b3678d2b2244641de013762b1d64ac01d
6
+ metadata.gz: b6a24b9db3a79f97793dec247313eb79961c6890e614767bbe5a0150fbc007701c8a305c0740a4d29d98a35ec18bafd3c7bf613fbb18062ff8281d931c82bce2
7
+ data.tar.gz: 1012c8f4c91dbf9ab91616288df728a7ddee93ad904cf3efc9ab77e08998a3ee284c6fc23a8ae767690ced81a2e3cfe1169e0f0c123dad655a26d827c9abf0a2
@@ -1,6 +1,6 @@
1
1
  class CssParser::Parser
2
- def tree
3
- to_h['all'].with_indifferent_access
2
+ def dig(*keys)
3
+ to_h['all'].dig(*keys.map(&:to_s)) rescue {}
4
4
  end
5
5
  end
6
6
 
@@ -17,7 +17,11 @@ module Checker
17
17
  inspection = expectation.inspection
18
18
  parser = CssParser::Parser.new
19
19
  parser.load_string! content
20
- raise "Unsopported inspection #{inspection.type}" unless ['DeclaresStyle', 'DeclaresStyle:'].include? inspection.type
20
+ raise "Unsupported inspection #{inspection.type}" unless ['DeclaresStyle', 'DeclaresStyle:'].include? inspection.type
21
+ inspect parser, inspection, binding
22
+ end
23
+
24
+ def self.inspect(parser, inspection, binding)
21
25
  case inspection.target.to_s.split(':').size
22
26
  when 0 then inspect_selector(parser, inspection, binding)
23
27
  when 1 then inspect_property(parser, inspection, binding)
@@ -27,16 +31,17 @@ module Checker
27
31
  end
28
32
 
29
33
  def self.inspect_selector(parser, inspection, binding)
30
- parser.tree[binding.to_s].present?
34
+ parser.dig(binding).present?
31
35
  end
32
36
 
33
37
  def self.inspect_property(parser, inspection, binding)
34
38
  property, value = parse_target(inspection.target)
35
- parser.tree[binding.to_s][property].present?
39
+ parser.dig(binding, property).present?
36
40
  end
41
+
37
42
  def self.inspect_property_and_value(parser, inspection, binding)
38
43
  property, value = parse_target(inspection.target)
39
- parser.tree[binding.to_s][property].words.include? value
44
+ parser.dig(binding, property)&.words&.include? value
40
45
  end
41
46
 
42
47
  def self.parse_target(target)
@@ -6,16 +6,24 @@ class HtmlExpectationsHook < Mumukit::Hook
6
6
  def run!(request)
7
7
  document = Nokogiri::HTML(compile_content(request))
8
8
  request.expectations.map do |raw|
9
- expectation = Mumukit::Inspection::Expectation.parse(raw.with_indifferent_access)
10
- binding = expectation.binding.gsub(/(css:)|(html:)/, '')
11
- lang = expectation.binding.starts_with?('css:')? 'CSS' : 'HTML'
12
- matches = "Checker::#{lang}".constantize.run document, expectation, binding
13
- {expectation: raw, result: negate(expectation, matches)}
9
+ evaluate_expectation raw, document
14
10
  end
15
11
  end
16
12
 
17
13
  private
18
14
 
15
+ def evaluate_expectation(raw, document)
16
+ expectation = Mumukit::Inspection::Expectation.parse(raw.with_indifferent_access)
17
+ binding = expectation.binding.gsub(/(css:)|(html:)/, '')
18
+ matches = checker_for(expectation).run document, expectation, binding
19
+ {expectation: raw, result: negate(expectation, matches)}
20
+ end
21
+
22
+ def checker_for(expectation)
23
+ lang = expectation.binding.starts_with?('css:')? 'CSS' : 'HTML'
24
+ "Checker::#{lang}".constantize
25
+ end
26
+
19
27
  def compile_content(request)
20
28
  request.content.presence || request.extra
21
29
  end
@@ -1,3 +1,3 @@
1
1
  module HtmlVersionHook
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-html-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
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: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.7.6
176
+ rubygems_version: 2.7.7
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: HTML Runner for Mumuki