Mange / roadie

Compare b9270f0 ... +3 ... ecacd10

Coverage Reach
spec/lib/roadie/document_spec.rb spec/lib/roadie/inliner_spec.rb spec/lib/roadie/asset_scanner_spec.rb spec/lib/roadie/net_http_provider_spec.rb spec/lib/roadie/url_generator_spec.rb spec/lib/roadie/provider_list_spec.rb spec/lib/roadie/url_rewriter_spec.rb spec/lib/roadie/filesystem_provider_spec.rb spec/lib/roadie/markup_improver_spec.rb spec/lib/roadie/cached_provider_spec.rb spec/lib/roadie/style_property_spec.rb spec/lib/roadie/stylesheet_spec.rb spec/lib/roadie/style_block_spec.rb spec/lib/roadie/selector_spec.rb spec/lib/roadie/path_rewriter_provider_spec.rb spec/lib/roadie/style_attribute_builder_spec.rb spec/lib/roadie/utils_spec.rb spec/lib/roadie/test_provider_spec.rb spec/lib/roadie/null_provider_spec.rb spec/lib/roadie/css_not_found_spec.rb spec/lib/roadie/null_url_rewriter_spec.rb spec/lib/roadie/deduplicator_spec.rb spec/integration_spec.rb spec/support/have_styling_matcher.rb spec/support/have_attribute_matcher.rb spec/support/have_node_matcher.rb spec/support/test_provider.rb spec/support/have_xpath_matcher.rb spec/support/have_selector_matcher.rb spec/shared_examples/url_rewriter.rb spec/shared_examples/asset_provider.rb lib/roadie/inliner.rb lib/roadie/document.rb lib/roadie/url_generator.rb lib/roadie/net_http_provider.rb lib/roadie/markup_improver.rb lib/roadie/errors.rb lib/roadie/rspec/asset_provider.rb lib/roadie/rspec/cache_store.rb lib/roadie/asset_scanner.rb lib/roadie/provider_list.rb lib/roadie/stylesheet.rb lib/roadie/selector.rb lib/roadie/style_property.rb lib/roadie/filesystem_provider.rb lib/roadie/deduplicator.rb lib/roadie/url_rewriter.rb lib/roadie/style_block.rb lib/roadie/cached_provider.rb lib/roadie/path_rewriter_provider.rb lib/roadie/null_provider.rb lib/roadie/style_attribute_builder.rb lib/roadie/utils.rb lib/roadie/null_url_rewriter.rb lib/roadie/asset_provider.rb lib/roadie/rspec.rb lib/roadie.rb

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 49 of 60 files from the diff.
Other files ignored by Codecov

@@ -1,6 +1,6 @@
Loading
1 1
# frozen_string_literal: true
2 2
3 -
require 'set'
3 +
require "set"
4 4
5 5
module Roadie
6 6
  # @api private
@@ -23,8 +23,15 @@
Loading
23 23
    # @option url_options [String] :scheme URL scheme ("http" is default)
24 24
    # @option url_options [String] :protocol alias for :scheme
25 25
    def initialize(url_options)
26 -
      raise ArgumentError, "No URL options were specified" unless url_options
27 -
      raise ArgumentError, "No :host was specified; options are: #{url_options.inspect}" unless url_options[:host]
26 +
      unless url_options
27 +
        raise ArgumentError, "No URL options were specified"
28 +
      end
29 +
30 +
      unless url_options[:host]
31 +
        raise ArgumentError,
32 +
          "No :host was specified; options were: #{url_options.inspect}"
33 +
      end
34 +
28 35
      validate_options url_options
29 36
30 37
      @url_options = url_options
@@ -58,7 +65,7 @@
Loading
58 65
    # @param [String] base The base which the relative path comes from
59 66
    # @return [String] an absolute URL
60 67
    def generate_url(path, base = "/")
61 -
      return root_uri.to_s if path.nil? or path.empty?
68 +
      return root_uri.to_s if path.nil? || path.empty?
62 69
      return path if path_is_anchor?(path)
63 70
      return add_scheme(path) if path_is_schemeless?(path)
64 71
      return path if Utils.path_is_absolute?(path)
@@ -67,13 +74,20 @@
Loading
67 74
    end
68 75
69 76
    protected
77 +
70 78
    attr_reader :root_uri, :scheme
71 79
72 80
    private
81 +
73 82
    def build_root_uri
74 83
      path = make_absolute url_options[:path]
75 84
      port = parse_port url_options[:port]
76 -
      URI::Generic.build(scheme: scheme, host: url_options[:host], port: port, path: path)
85 +
      URI::Generic.build(
86 +
        scheme: scheme,
87 +
        host: url_options[:host],
88 +
        port: port,
89 +
        path: path
90 +
      )
77 91
    end
78 92
79 93
    def add_scheme(path)
@@ -98,7 +112,7 @@
Loading
98 112
99 113
    # Strip :// from any scheme, if present
100 114
    def normalize_scheme(scheme)
101 -
      return 'http' unless scheme
115 +
      return "http" unless scheme
102 116
      scheme.to_s[/^\w+/]
103 117
    end
104 118
@@ -119,15 +133,17 @@
Loading
119 133
    end
120 134
121 135
    def path_is_anchor?(path)
122 -
      path.start_with? '#'
136 +
      path.start_with? "#"
123 137
    end
124 138
125 139
    VALID_OPTIONS = Set[:host, :port, :path, :protocol, :scheme].freeze
126 140
127 141
    def validate_options(options)
128 142
      keys = Set.new(options.keys)
129 143
      unless keys.subset? VALID_OPTIONS
130 -
        raise ArgumentError, "Passed invalid options: #{(keys - VALID_OPTIONS).to_a}, valid options are: #{VALID_OPTIONS.to_a}"
144 +
        raise ArgumentError,
145 +
          "Passed invalid options: #{(keys - VALID_OPTIONS).to_a}, " \
146 +
            "valid options are: #{VALID_OPTIONS.to_a}"
131 147
      end
132 148
    end
133 149
  end

@@ -1,16 +1,16 @@
Loading
1 1
# frozen_string_literal: true
2 2
3 -
require 'spec_helper'
4 -
require 'roadie/rspec'
5 -
require 'shared_examples/asset_provider'
3 +
require "spec_helper"
4 +
require "roadie/rspec"
5 +
require "shared_examples/asset_provider"
6 6
7 7
module Roadie
8 8
  describe PathRewriterProvider do
9 9
    let(:upstream) { TestProvider.new "good.css" => "body { color: green; }" }
10 10
11 11
    subject(:provider) do
12 12
      PathRewriterProvider.new(upstream) do |path|
13 -
        path.gsub('well', 'good')
13 +
        path.gsub("well", "good")
14 14
      end
15 15
    end
16 16

@@ -1,7 +1,7 @@
Loading
1 1
# frozen_string_literal: true
2 2
3 3
RSpec::Matchers.define :have_attribute do |attribute|
4 -
  @selector = 'body > *:first'
4 +
  @selector = "body > *:first"
5 5
6 6
  chain :at_selector do |selector|
7 7
    @selector = selector
@@ -27,4 +27,3 @@
Loading
27 27
    node && node[attribute_name]
28 28
  end
29 29
end
30 -

@@ -7,10 +7,10 @@
Loading
7 7
  # This class will improve the following aspects of the DOM:
8 8
  # * A HTML5 doctype will be added if missing, other doctypes will be left as-is.
9 9
  # * Basic HTML elements will be added if missing.
10 -
  #   * +<html>+
11 -
  #   * +<head>+
12 -
  #   * +<body>+
13 -
  #   * +<meta>+ declaring charset and content-type (text/html)
10 +
  #   * `<html>`
11 +
  #   * `<head>`
12 +
  #   * `<body>`
13 +
  #   * `<meta>` declaring charset and content-type (text/html)
14 14
  #
15 15
  # @note Due to a Nokogiri bug, the HTML5 doctype cannot be added under JRuby. No doctype is outputted under JRuby.
16 16
  #   See https://github.com/sparklemotion/nokogiri/issues/984
@@ -33,15 +33,17 @@
Loading
33 33
    end
34 34
35 35
    protected
36 +
36 37
    attr_reader :dom
37 38
38 39
    private
40 +
39 41
    def ensure_doctype_present
40 42
      return if uses_buggy_jruby?
41 -
      return if @html.include?('<!DOCTYPE ')
43 +
      return if @html.include?("<!DOCTYPE ")
42 44
      # Nokogiri adds a "default" doctype to the DOM, which we will remove
43 -
      dom.internal_subset.remove unless dom.internal_subset.nil?
44 -
      dom.create_internal_subset 'html', nil, nil
45 +
      dom.internal_subset&.remove
46 +
      dom.create_internal_subset "html", nil, nil
45 47
    end
46 48
47 49
    # JRuby up to at least 1.6.0 has a bug where the doctype of a document cannot be changed.
@@ -52,26 +54,26 @@
Loading
52 54
    end
53 55
54 56
    def ensure_html_element_present
55 -
      return if dom.at_xpath('html')
56 -
      html = Nokogiri::XML::Node.new 'html', dom
57 +
      return if dom.at_xpath("html")
58 +
      html = Nokogiri::XML::Node.new "html", dom
57 59
      dom << html
58 60
    end
59 61
60 62
    def ensure_head_element_present
61 -
      if (head = dom.at_xpath('html/head'))
63 +
      if (head = dom.at_xpath("html/head"))
62 64
        head
63 65
      else
64 -
        create_head_element dom.at_xpath('html')
66 +
        create_head_element dom.at_xpath("html")
65 67
      end
66 68
    end
67 69
68 70
    def create_head_element(parent)
69 -
      head = Nokogiri::XML::Node.new 'head', dom
70 -
      unless parent.children.empty?
71 +
      head = Nokogiri::XML::Node.new "head", dom
72 +
      if parent.children.empty?
73 +
        parent << head
74 +
      else
71 75
        # Crashes when no children are present
72 76
        parent.children.before head
73 -
      else
74 -
        parent << head
75 77
      end
76 78
      head
77 79
    end
@@ -83,15 +85,15 @@
Loading
83 85
    end
84 86
85 87
    def content_type_meta_element_missing?
86 -
      dom.xpath('html/head/meta').none? do |meta|
87 -
        meta['http-equiv'].to_s.downcase == 'content-type'
88 +
      dom.xpath("html/head/meta").none? do |meta|
89 +
        meta["http-equiv"].to_s.downcase == "content-type"
88 90
      end
89 91
    end
90 92
91 93
    def make_content_type_element
92 -
      meta = Nokogiri::XML::Node.new('meta', dom)
93 -
      meta['http-equiv'] = 'Content-Type'
94 -
      meta['content'] = 'text/html; charset=UTF-8'
94 +
      meta = Nokogiri::XML::Node.new("meta", dom)
95 +
      meta["http-equiv"] = "Content-Type"
96 +
      meta["content"] = "text/html; charset=UTF-8"
95 97
      meta
96 98
    end
97 99
  end

@@ -1,7 +1,7 @@
Loading
1 1
# frozen_string_literal: true
2 2
3 -
require 'spec_helper'
4 -
require 'shared_examples/url_rewriter'
3 +
require "spec_helper"
4 +
require "shared_examples/url_rewriter"
5 5
6 6
module Roadie
7 7
  describe NullUrlRewriter do

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 19 files with coverage changes found.

Changes in spec/lib/roadie/inliner_spec.rb
-1
+1
Loading file...
Changes in lib/roadie/inliner.rb
-2
Loading file...
Changes in spec/shared_examples/url_rewriter.rb
-1
Loading file...
Changes in spec/integration_spec.rb
-4
Loading file...
Changes in lib/roadie/provider_list.rb
-1
Loading file...
Changes in lib/roadie/deduplicator.rb
-1
Loading file...
Changes in spec/lib/roadie/deduplicator_spec.rb
-1
Loading file...
Changes in lib/roadie/rspec/asset_provider.rb
-1
Loading file...
Changes in spec/lib/roadie/selector_spec.rb
-2
Loading file...
Changes in spec/lib/roadie/document_spec.rb
-1
Loading file...
Changes in spec/lib/roadie/filesystem_provider_spec.rb
-1
Loading file...
Changes in lib/roadie/asset_scanner.rb
-1
-1
Loading file...
Changes in spec/lib/roadie/url_generator_spec.rb
-4
Loading file...
Changes in lib/roadie/rspec/cache_store.rb
-1
Loading file...
Changes in spec/lib/roadie/provider_list_spec.rb
-5
Loading file...
Changes in spec/lib/roadie/net_http_provider_spec.rb
-1
-6
Loading file...
Changes in spec/lib/roadie/path_rewriter_provider_spec.rb
-2
Loading file...
Changes in spec/lib/roadie/null_url_rewriter_spec.rb
-1
Loading file...
Changes in spec/lib/roadie/cached_provider_spec.rb
-3
Loading file...
Files Coverage
lib 0.13% 98.77%
spec +2.09% 97.46%
Project Totals (57 files) 97.94%
Loading