mumuki-html-runner 1.4.1 → 1.5

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: 2c0771033573571fffde2c2d2da99b208dfacbb1e88ad309cf9876a305d9914a
4
- data.tar.gz: 9083f8440c43f84e15f11b4f2b38592e3febde3717307da9c5f51a1d630d07c6
3
+ metadata.gz: eb9f720963e478e84f41e49be031589ca06af4684380c9f7573e65a87884af86
4
+ data.tar.gz: 575ee6e54a3350ad148ec38c36afaa0c8c6467f88ff558049d19a8d7343b4349
5
5
  SHA512:
6
- metadata.gz: 6cebf7fe755a947f300a8881ef2b6079bf89857ef2ad78b0885397623081ba3de3836ef8c3599bacca7e7f5f5ebdcb0839dbbe1f31528c3170a71a69586eeebf
7
- data.tar.gz: 0209fb23e352863f542842972464852f761a04f2f3c88687595e81b15c6dfcc85981b1dfb5f7342dfd0a036694bf3e8685897134ecfd2d67a11e4bcf0f03800a
6
+ metadata.gz: d26a4aeb0fc1c77b9566a04299f04029f56976509ceff1b80ae589e21cd36b9670a15e4d4bbf7872c6d599415ada17f23fc48250b046490a68b24fa020b2532c
7
+ data.tar.gz: fafac3a131ad24d4c00d3a332c63737df6f0738b1c6f535915edddb1c631f6ed53982c983039ed4b1c0306bf14dddbbffaf529a553cee6f8efe509767d56ce0d
@@ -0,0 +1,46 @@
1
+ class CssParser::Parser
2
+ def tree
3
+ to_h['all'].with_indifferent_access
4
+ end
5
+ end
6
+
7
+ class String
8
+ def words
9
+ split(' ')
10
+ end
11
+ end
12
+
13
+ module Checker
14
+ class CSS
15
+ def self.run(document, expectation, binding)
16
+ content = document.xpath('//style').text.presence || document.text
17
+ inspection = expectation.inspection
18
+ parser = CssParser::Parser.new
19
+ parser.load_string! content
20
+ raise "Unsopported inspection #{inspection.type}" unless ['DeclaresStyle', 'DeclaresStyle:'].include? inspection.type
21
+ case inspection.target.to_s.split(':').size
22
+ when 0 then inspect_selector(parser, inspection, binding)
23
+ when 1 then inspect_property(parser, inspection, binding)
24
+ when 2 then inspect_property_and_value(parser, inspection, binding)
25
+ else raise "Malformed target value."
26
+ end
27
+ end
28
+
29
+ def self.inspect_selector(parser, inspection, binding)
30
+ parser.tree[binding.to_s].present?
31
+ end
32
+
33
+ def self.inspect_property(parser, inspection, binding)
34
+ property, value = parse_target(inspection.target)
35
+ parser.tree[binding.to_s][property].present?
36
+ end
37
+ def self.inspect_property_and_value(parser, inspection, binding)
38
+ property, value = parse_target(inspection.target)
39
+ parser.tree[binding.to_s][property].words.include? value
40
+ end
41
+
42
+ def self.parse_target(target)
43
+ target.to_s.split(':')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module Checker
2
+ class HTML
3
+ def self.run(document, expectation, binding)
4
+ document.xpath "#{compile_scope binding}//#{compile_html_target expectation.inspection}"
5
+ end
6
+
7
+ def self.compile_html_target(inspection)
8
+ target = inspection.target
9
+ raise 'Target is required' if target.blank?
10
+
11
+ case inspection.type
12
+ when 'DeclaresTag' then target.value
13
+ when 'DeclaresAttribute' then "@#{target.value}"
14
+ else raise "Unsupported inspection #{inspection.type}"
15
+ end
16
+ end
17
+
18
+ def self.compile_scope(binding)
19
+ "//#{binding == '*' ? '' : binding}"
20
+ end
21
+ end
22
+ end
data/lib/checker.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'checker/html.rb'
2
+ require_relative 'checker/css.rb'
@@ -7,28 +7,15 @@ class HtmlExpectationsHook < Mumukit::Hook
7
7
  document = Nokogiri::HTML(request.content)
8
8
  request.expectations.map do |raw|
9
9
  expectation = Mumukit::Inspection::Expectation.parse(raw.with_indifferent_access)
10
- matches = document.xpath "#{compile_scope expectation}//#{compile_target expectation.inspection}"
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
11
13
  {expectation: raw, result: negate(expectation, matches)}
12
14
  end
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def compile_target(inspection)
18
- target = inspection.target
19
- raise 'Target is required' if target.blank?
20
-
21
- case inspection.type
22
- when 'DeclaresTag' then target.value
23
- when 'DeclaresAttribute' then "@#{target.value}"
24
- else raise "Unsupported inspection #{inspection.type}"
25
- end
26
- end
27
-
28
- def compile_scope(expectation)
29
- "//#{expectation.binding == '*' ? '' : expectation.binding}"
30
- end
31
-
32
19
  def negate(expectation, matches)
33
20
  expectation.inspection.negated? ? matches.blank? : matches.present?
34
21
  end
data/lib/html_runner.rb CHANGED
@@ -2,6 +2,7 @@ require 'mumukit'
2
2
  require 'yaml'
3
3
  require 'nokogiri'
4
4
  require 'hexp'
5
+ require 'css_parser'
5
6
 
6
7
  I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
7
8
 
@@ -12,4 +13,5 @@ end
12
13
 
13
14
  require_relative './metadata_hook'
14
15
  require_relative './test_hook'
16
+ require_relative './checker'
15
17
  require_relative './expectations_hook'
data/lib/test_hook.rb CHANGED
@@ -13,7 +13,7 @@ class HtmlTestHook < Mumukit::Hook
13
13
 
14
14
  def run!(request)
15
15
  expected = request[:test]
16
- actual = request[:content]
16
+ actual = request[:extra] || request[:content]
17
17
 
18
18
  if contents_match?(expected, actual)
19
19
  [render_html(actual), :passed]
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HtmlVersionHook
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5'
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.4.1
4
+ version: '1.5'
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: 2017-12-29 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mumukit-content-type
42
+ name: css_parser
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.4.0
48
- type: :development
47
+ version: '1.6'
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.4.0
54
+ version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.3'
131
+ version: '3.0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.3'
138
+ version: '3.0'
139
139
  description:
140
140
  email:
141
141
  - franco@mumuki.org
@@ -143,6 +143,9 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - lib/checker.rb
147
+ - lib/checker/css.rb
148
+ - lib/checker/html.rb
146
149
  - lib/expectations_hook.rb
147
150
  - lib/html_runner.rb
148
151
  - lib/locales/en.yml
@@ -170,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
173
  version: '0'
171
174
  requirements: []
172
175
  rubyforge_project:
173
- rubygems_version: 2.7.4
176
+ rubygems_version: 2.7.6
174
177
  signing_key:
175
178
  specification_version: 4
176
179
  summary: HTML Runner for Mumuki