mumuki-html-runner 1.2.0 → 1.3.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90318399001a50de2298a98ff8a52935e82a5b1036ea4287f91c0ec8b0231dc3
4
- data.tar.gz: bb6818f459cd4b032909257a53cfc88d62792bfc90b3d8447b08bb8d8194ae1a
3
+ metadata.gz: 381f811961e7943923bb0e7ea097983cb3df09bdca4bf42c810d16a11fab1668
4
+ data.tar.gz: b71db3c7a3c2faebacd8d94f1ed36ea2fe200b87487cc51a42cf2b29913d581e
5
5
  SHA512:
6
- metadata.gz: a6953c20bd10aeadad5d11e7e09eb5af71669cc4a1c8ebb9b89b8fe97dd9d9c1c13c0c71f8f5865797b2160cae5e19d15af1e8dc290f1ce281568e2fd3ec7c18
7
- data.tar.gz: a22084ffc2fafb1447e6283f7eb6f33fe732146e7fc828ac6a5d4b111f04226c5430d7be3203ce366b862923f152c419ede1c8fd7fac6a57e0e763d48a5d8e89
6
+ metadata.gz: 21699d887c9949bb73179cb98eb16baa4514e60e73762af17bb3aea17c7ef5c45aa8c56c1d307b4dd3aa53b4aebf69ab7a0f1474b3deb9198cb3115954731b85
7
+ data.tar.gz: 1d8c939636302e7558f810955a292337a6bfe0ce3eda0af424a39db3564f6b81f3f7341e0d7a0b0992eeb57d6601c5d67c0c77cf4914b0826211a82c7a400390
@@ -0,0 +1,35 @@
1
+ class HtmlExpectationsHook < Mumukit::Hook
2
+ def compile(request)
3
+ request
4
+ end
5
+
6
+ def run!(request)
7
+ document = Nokogiri::HTML(request.content)
8
+ request.expectations.map do |raw|
9
+ expectation = Mumukit::Inspection::Expectation.parse(raw.with_indifferent_access)
10
+ matches = document.xpath "#{compile_scope expectation}//#{compile_target expectation.inspection}"
11
+ {expectation: raw, result: negate(expectation, matches)}
12
+ end
13
+ end
14
+
15
+ private
16
+
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
+ def negate(expectation, matches)
33
+ expectation.inspection.negated? ? matches.blank? : matches.present?
34
+ end
35
+ end
data/lib/html_runner.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'mumukit'
2
2
  require 'yaml'
3
+ require 'nokogiri'
4
+ require 'hexp'
3
5
 
4
6
  I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
5
7
 
@@ -10,3 +12,4 @@ end
10
12
 
11
13
  require_relative './metadata_hook'
12
14
  require_relative './test_hook'
15
+ require_relative './expectations_hook'
data/lib/test_hook.rb CHANGED
@@ -15,13 +15,24 @@ class HtmlTestHook < Mumukit::Hook
15
15
  expected = request[:test]
16
16
  actual = request[:content]
17
17
 
18
- if expected.visible_chars == actual.visible_chars
18
+ if contents_match?(expected, actual)
19
19
  [render_html(actual), :passed]
20
20
  else
21
21
  [render_fail_html(actual, expected), :failed]
22
22
  end
23
23
  end
24
24
 
25
+ def contents_match?(expected, actual)
26
+ hexp(expected) == hexp(actual)
27
+ rescue
28
+ expected == actual
29
+ end
30
+
31
+ def hexp(content)
32
+ squeezed_content = [' ', "\n", "\t"].reduce(content, :squeeze)
33
+ Hexp::Node.new(:html, Hexp.parse(squeezed_content))
34
+ end
35
+
25
36
  def render_html(actual)
26
37
  build_iframe actual
27
38
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HtmlVersionHook
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
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.2.0
4
+ version: 1.3.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: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hexp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mumukit-content-type
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +143,7 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
146
+ - lib/expectations_hook.rb
132
147
  - lib/html_runner.rb
133
148
  - lib/locales/en.yml
134
149
  - lib/locales/es.yml