Mange / roadie

@@ -43,25 +43,22 @@
Loading
43 43
    # Extra message
44 44
    attr_reader :extra_message
45 45
46 -
    # TODO: Change signature in the next major version of Roadie.
47 -
    def initialize(css_name, extra_message = nil, provider = nil)
46 +
    def initialize(css_name:, message: nil, provider: nil)
48 47
      @css_name = css_name
49 48
      @provider = provider
50 -
      @extra_message = extra_message
51 -
      super build_message(extra_message)
49 +
      @extra_message = message
50 +
      super build_message
52 51
    end
53 52
54 53
    protected
55 54
56 55
    def error_row
57 -
      "#{provider || "Unknown provider"}: #{extra_message || message}"
56 +
      "#{provider || "Unknown provider"}: #{extra_message}"
58 57
    end
59 58
60 59
    private
61 60
62 -
    # Redundant method argument is to keep API compatability without major version bump.
63 -
    # TODO: Remove argument on version 4.0.
64 -
    def build_message(extra_message = @extra_message)
61 +
    def build_message
65 62
      message = +%(Could not find stylesheet "#{css_name}")
66 63
      message << ": #{extra_message}" if extra_message
67 64
      message << "\nUsed provider:\n#{provider}" if provider
@@ -72,14 +69,18 @@
Loading
72 69
  class ProvidersFailed < CssNotFound
73 70
    attr_reader :errors
74 71
75 -
    def initialize(css_name, provider_list, errors)
72 +
    def initialize(css_name:, providers:, errors:)
76 73
      @errors = errors
77 -
      super(css_name, "All providers failed", provider_list)
74 +
      super(
75 +
        css_name: css_name,
76 +
        message: "All providers failed",
77 +
        provider: providers
78 +
      )
78 79
    end
79 80
80 81
    private
81 82
82 -
    def build_message(extra_message)
83 +
    def build_message
83 84
      message = +%(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n)
84 85
      each_error_row(errors) do |row|
85 86
        message << "\t" << row << "\n"

@@ -206,13 +206,7 @@
Loading
206 206
207 207
    def callback(callable, dom)
208 208
      if callable.respond_to?(:call)
209 -
        # Arity checking is to support the API without bumping a major version.
210 -
        # TODO: Remove on next major version (v4.0)
211 -
        if !callable.respond_to?(:parameters) || callable.parameters.size == 1
212 -
          callable.call(dom)
213 -
        else
214 -
          callable.call(dom, self)
215 -
        end
209 +
        callable.call(dom, self)
216 210
      end
217 211
    end
218 212

@@ -106,21 +106,6 @@
Loading
106 106
        document.transform
107 107
      end
108 108
109 -
      # TODO: Remove on next major version.
110 -
      it "works on callables that don't expect more than one argument" do
111 -
        document = Document.new "<body></body>"
112 -
        document.before_transformation = ->(first) {}
113 -
        document.after_transformation = ->(first = nil) {}
114 -
115 -
        expect { document.transform }.to_not raise_error
116 -
117 -
        # It still supplies the second argument, if possible.
118 -
        document.after_transformation = ->(first, second = nil) {
119 -
          raise "Oops" unless second
120 -
        }
121 -
        expect { document.transform }.to_not raise_error
122 -
      end
123 -
124 109
      context "in HTML mode" do
125 110
        it "does not escape curly braces" do
126 111
          document = Document.new "<body><a href='https://google.com/{{hello}}'>Hello</a></body>"

@@ -120,7 +120,9 @@
Loading
120 120
        </html>
121 121
      HTML
122 122
123 -
      expect { document.transform }.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
123 +
      expect {
124 +
        document.transform
125 +
      }.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
124 126
125 127
      document.asset_providers << Roadie::NullProvider.new
126 128
      expect { document.transform }.to_not raise_error
@@ -524,7 +526,9 @@
Loading
524 526
        <link rel="stylesheet" href="/spec/fixtures/does_not_exist.css">
525 527
      HTML
526 528
527 -
      expect { document.transform_partial }.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
529 +
      expect {
530 +
        document.transform_partial
531 +
      }.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
528 532
529 533
      document.asset_providers << Roadie::NullProvider.new
530 534
      expect { document.transform_partial }.to_not raise_error

@@ -37,10 +37,14 @@
Loading
37 37
      if response.is_a? Net::HTTPSuccess
38 38
        Stylesheet.new(url, response_body(response))
39 39
      else
40 -
        raise CssNotFound.new(url, "Server returned #{response.code}: #{truncate response.body}", self)
40 +
        raise CssNotFound.new(
41 +
          css_name: url,
42 +
          message: "Server returned #{response.code}: #{truncate response.body}",
43 +
          provider: self
44 +
        )
41 45
      end
42 46
    rescue Timeout::Error
43 -
      raise CssNotFound.new(url, "Timeout", self)
47 +
      raise CssNotFound.new(css_name: url, message: "Timeout", provider: self)
44 48
    end
45 49
46 50
    def to_s
@@ -69,7 +73,11 @@
Loading
69 73
      if access_granted_to?(uri.host)
70 74
        get_response(uri)
71 75
      else
72 -
        raise CssNotFound.new(url, "#{uri.host} is not part of whitelist!", self)
76 +
        raise CssNotFound.new(
77 +
          css_name: url,
78 +
          message: "#{uri.host} is not part of whitelist!",
79 +
          provider: self
80 +
        )
73 81
      end
74 82
    end
75 83

@@ -7,7 +7,9 @@
Loading
7 7
  # It helps you by declaring {#find_stylesheet!} in the terms of #find_stylesheet in your own class.
8 8
  module AssetProvider
9 9
    def find_stylesheet!(name)
10 -
      find_stylesheet(name) or raise CssNotFound.new(name, nil, self)
10 +
      find_stylesheet(name) or raise(
11 +
        CssNotFound.new(css_name: name, provider: self)
12 +
      )
11 13
    end
12 14
  end
13 15
end

@@ -84,7 +84,11 @@
Loading
84 84
    it "raises a readable error message" do
85 85
      provider = double("Provider", to_s: "Some provider")
86 86
      allow(provider).to receive(:find_stylesheet!).and_raise(
87 -
        CssNotFound.new("style.css", "I tripped", provider)
87 +
        CssNotFound.new(
88 +
          css_name: "style.css",
89 +
          message: "I tripped",
90 +
          provider: provider
91 +
        )
88 92
      )
89 93
90 94
      sublist = ProviderList.new([provider, provider])

@@ -61,7 +61,9 @@
Loading
61 61
      rescue CssNotFound => error
62 62
        errors << error
63 63
      end
64 -
      raise ProvidersFailed.new(name, self, errors)
64 +
      raise ProvidersFailed.new(
65 +
        css_name: name, providers: self, errors: errors
66 +
      )
65 67
    end
66 68
67 69
    def to_s

@@ -59,7 +59,10 @@
Loading
59 59
      if new_path
60 60
        provider.find_stylesheet!(new_path)
61 61
      else
62 -
        raise CssNotFound, "Filter returned #{new_path.inspect}"
62 +
        raise CssNotFound.new(
63 +
          css_name: path,
64 +
          message: "Filter returned #{new_path.inspect}"
65 +
        )
63 66
      end
64 67
    end
65 68
  end

@@ -5,20 +5,23 @@
Loading
5 5
module Roadie
6 6
  describe CssNotFound do
7 7
    it "is initialized with a name" do
8 -
      error = CssNotFound.new("style.css")
8 +
      error = CssNotFound.new(css_name: "style.css")
9 9
      expect(error.css_name).to eq("style.css")
10 10
      expect(error.message).to eq('Could not find stylesheet "style.css"')
11 11
    end
12 12
13 13
    it "can be initialized with an extra message" do
14 -
      expect(CssNotFound.new("file.css", "directory is missing").message).to eq(
14 +
      error = CssNotFound.new(css_name: "file.css", message: "directory is missing")
15 +
      expect(error.message).to eq(
15 16
        'Could not find stylesheet "file.css": directory is missing'
16 17
      )
17 18
    end
18 19
19 20
    it "shows information about used provider when given" do
20 21
      provider = double("Some cool provider")
21 -
      expect(CssNotFound.new("style.css", nil, provider).message).to eq(
22 +
      error = CssNotFound.new(css_name: "style.css", provider: provider)
23 +
24 +
      expect(error.message).to eq(
22 25
        %(Could not find stylesheet "style.css"\nUsed provider:\n#{provider})
23 26
      )
24 27
    end

@@ -32,7 +32,11 @@
Loading
32 32
        Stylesheet.new file_path, File.read(file_path)
33 33
      else
34 34
        basename = File.basename file_path
35 -
        raise CssNotFound.new(basename, %{#{file_path} does not exist. (Original name was "#{name}")}, self)
35 +
        raise CssNotFound.new(
36 +
          css_name: basename,
37 +
          message: %{#{file_path} does not exist. (Original name was "#{name}")},
38 +
          provider: self
39 +
        )
36 40
      end
37 41
    end
38 42

@@ -45,7 +45,10 @@
Loading
45 45
    it "raises Roadie::CssNotFound on invalid stylesheets" do
46 46
      expect {
47 47
        subject.find_stylesheet!(invalid_name)
48 -
      }.to raise_error Roadie::CssNotFound, Regexp.new(Regexp.quote(invalid_name))
48 +
      }.to raise_error(
49 +
        Roadie::CssNotFound,
50 +
        Regexp.new(Regexp.quote(invalid_name))
51 +
      )
49 52
    end
50 53
  end
51 54
end
Files Coverage
lib 98.76%
spec 97.52%
Project Totals (57 files) 97.97%
1786168905
1786168905
1786168905
1786168905

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading