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 +4 -4
 - data/lib/checker/css.rb +11 -6
 - data/lib/expectations_hook.rb +13 -5
 - data/lib/version.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 300794e63c7cac26dd6c8f769f2e36002c7e867f779cf860c17b64479ed02848
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9ffb85ae1c11f1f541e73181cd41e04e77bc2fa88ecfb69bd16e857e4ae01ae6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b6a24b9db3a79f97793dec247313eb79961c6890e614767bbe5a0150fbc007701c8a305c0740a4d29d98a35ec18bafd3c7bf613fbb18062ff8281d931c82bce2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1012c8f4c91dbf9ab91616288df728a7ddee93ad904cf3efc9ab77e08998a3ee284c6fc23a8ae767690ced81a2e3cfe1169e0f0c123dad655a26d827c9abf0a2
         
     | 
    
        data/lib/checker/css.rb
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class CssParser::Parser
         
     | 
| 
       2 
     | 
    
         
            -
              def  
     | 
| 
       3 
     | 
    
         
            -
                to_h['all']. 
     | 
| 
      
 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 " 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 44 
     | 
    
         
            +
                  parser.dig(binding, property)&.words&.include? value
         
     | 
| 
       40 
45 
     | 
    
         
             
                end
         
     | 
| 
       41 
46 
     | 
    
         | 
| 
       42 
47 
     | 
    
         
             
                def self.parse_target(target)
         
     | 
    
        data/lib/expectations_hook.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                   
     | 
| 
       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
         
     | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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. 
     | 
| 
      
 176 
     | 
    
         
            +
            rubygems_version: 2.7.7
         
     | 
| 
       177 
177 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       178 
178 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       179 
179 
     | 
    
         
             
            summary: HTML Runner for Mumuki
         
     |