color_parser 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +2 -0
  2. data/Guardfile +9 -0
  3. data/README.md +22 -22
  4. data/Rakefile +18 -6
  5. data/color_parser.gemspec +9 -1
  6. data/lib/color_parser/color.rb +154 -0
  7. data/lib/color_parser/errors.rb +3 -0
  8. data/lib/color_parser/request.rb +21 -0
  9. data/lib/color_parser/stylesheet.rb +4 -11
  10. data/lib/color_parser/version.rb +1 -1
  11. data/lib/color_parser.rb +4 -89
  12. data/{test/color_parser_test.rb → spec/color_parser_spec.rb} +19 -14
  13. data/spec/color_spec.rb +10 -0
  14. data/{test → spec}/fixtures/css/absolute.html +0 -0
  15. data/{test → spec}/fixtures/css/inline.html +0 -0
  16. data/{test → spec}/fixtures/css/inline_import.html +0 -0
  17. data/{test → spec}/fixtures/css/invalid.html +0 -0
  18. data/{test → spec}/fixtures/css/relative.html +0 -0
  19. data/{test → spec}/fixtures/css/relative_root.html +0 -0
  20. data/{test → spec}/fixtures/css/stylesheets/colors.css +0 -0
  21. data/{test → spec}/fixtures/css/stylesheets/fonts.css +0 -0
  22. data/{test → spec}/fixtures/css/stylesheets/print.css +0 -0
  23. data/{test → spec}/fixtures/css/stylesheets/screen.css +0 -0
  24. data/{test → spec}/fixtures/css_color/frequency.html +0 -0
  25. data/{test → spec}/fixtures/css_color/stylesheets/color_styles.css +0 -0
  26. data/{test → spec}/fixtures/css_color/stylesheets/css_elements.css +0 -0
  27. data/{test → spec}/fixtures/css_color/stylesheets/frequency.css +0 -0
  28. data/{test → spec}/fixtures/css_color/stylesheets/imported_selectors.css +0 -0
  29. data/{test → spec}/fixtures/css_color/stylesheets/properties.css +0 -0
  30. data/{test → spec}/fixtures/css_images/images/apple.png +0 -0
  31. data/{test → spec}/fixtures/css_images/images/cantaloupe.png +0 -0
  32. data/{test → spec}/fixtures/css_images/images/kiwi.jpg +0 -0
  33. data/{test → spec}/fixtures/css_images/images/mango.png +0 -0
  34. data/{test → spec}/fixtures/css_images/images/pineapple.png +0 -0
  35. data/{test → spec}/fixtures/css_images/paths.html +0 -0
  36. data/{test → spec}/fixtures/css_images/stylesheets/import_paths.css +0 -0
  37. data/{test → spec}/fixtures/css_images/stylesheets/paths.css +0 -0
  38. data/{test → spec}/fixtures/css_images/stylesheets/quotes.css +0 -0
  39. data/{test → spec}/fixtures/css_import/index.html +0 -0
  40. data/{test → spec}/fixtures/css_import/stylesheets/borders.css +0 -0
  41. data/{test → spec}/fixtures/css_import/stylesheets/colors.css +0 -0
  42. data/{test → spec}/fixtures/css_import/stylesheets/fonts.css +0 -0
  43. data/{test → spec}/fixtures/css_import/stylesheets/ie.css +0 -0
  44. data/{test → spec}/fixtures/css_import/stylesheets/images.css +0 -0
  45. data/{test → spec}/fixtures/css_import/stylesheets/master.css +0 -0
  46. data/{test → spec}/fixtures/css_import/stylesheets/print.css +0 -0
  47. data/{test → spec}/fixtures/css_import/stylesheets/screen.css +0 -0
  48. data/{test → spec}/fixtures/inline_images/absolute.html +0 -0
  49. data/{test → spec}/fixtures/inline_images/images/apple.png +0 -0
  50. data/{test → spec}/fixtures/inline_images/images/kiwi.jpg +0 -0
  51. data/{test → spec}/fixtures/inline_images/relative.html +0 -0
  52. data/{test → spec}/fixtures/inline_images/relative_root.html +0 -0
  53. data/spec/image_spec.rb +33 -0
  54. data/{test/page_test.rb → spec/page_spec.rb} +57 -57
  55. data/spec/request_spec.rb +12 -0
  56. data/spec/spec_helper.rb +10 -0
  57. data/{test/test_request.rb → spec/stubs/fake_request.rb} +2 -2
  58. data/spec/stylesheet_spec.rb +235 -0
  59. data/spec/version_spec.rb +9 -0
  60. metadata +186 -100
  61. data/test/image_test.rb +0 -27
  62. data/test/stylesheet_test.rb +0 -257
  63. data/test/test_helper.rb +0 -6
  64. data/test/version_test.rb +0 -7
File without changes
File without changes
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Image do
4
+ before(:each) do
5
+ ColorParser.request = FakeRequest.new
6
+ end
7
+
8
+ describe "" do
9
+ it "should assign url" do
10
+ image = ColorParser::Image.new("http://example.com/foo/bar.png")
11
+
12
+ expect(image.url).to eq "http://example.com/foo/bar.png"
13
+ end
14
+ end
15
+
16
+ describe "" do
17
+ it "should parse host path and query from url" do
18
+ image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
19
+
20
+ expect(image.host).to eq "example.com"
21
+ expect(image.path).to eq "/foo/bar.png"
22
+ expect(image.query).to eq "baz=bar"
23
+ end
24
+ end
25
+
26
+ describe "" do
27
+ it "should parse name" do
28
+ image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
29
+
30
+ expect("bar.png").to eq image.name
31
+ end
32
+ end
33
+ end
@@ -1,24 +1,24 @@
1
- require_relative "test_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Page do
4
- def setup
5
- ColorParser.request = ColorParser::TestRequest.new
4
+ before(:each) do
5
+ ColorParser.request = FakeRequest.new
6
6
  end
7
7
 
8
8
  it "should initialize url" do
9
9
  url = "http://example.com/css/inline.html?foo=bar"
10
10
  page = ColorParser::Page.new(url)
11
11
 
12
- page.url.must_equal url
12
+ expect(page.url).to eq url
13
13
  end
14
14
 
15
15
  it "should parse url" do
16
16
  url = "http://example.com/css/inline.html?foo=bar"
17
17
  page = ColorParser::Page.new(url)
18
18
 
19
- page.host.must_equal "example.com"
20
- page.path.must_equal "/css/inline.html"
21
- page.query.must_equal "foo=bar"
19
+ expect(page.host).to eq "example.com"
20
+ expect(page.path).to eq "/css/inline.html"
21
+ expect(page.query).to eq "foo=bar"
22
22
  end
23
23
 
24
24
  # Stylesheet sources
@@ -27,24 +27,24 @@ describe Page do
27
27
  page = ColorParser::Page.new(url)
28
28
 
29
29
  # 2 found
30
- page.stylesheets.length.must_equal 2
30
+ expect(page.stylesheets.length).to eq 2
31
31
 
32
32
  # stylesheet content
33
33
  sheet = page.stylesheets.first
34
- sheet.type.must_equal "inline"
35
- sheet.text.must_include "background"
34
+ expect(sheet.type).to eq "inline"
35
+ expect(sheet.text).to include "background"
36
36
  end
37
37
 
38
38
  it "should build styles with inine css with import" do
39
39
  url = "http://example.com/css/inline_import.html"
40
40
  page = ColorParser::Page.new(url)
41
41
 
42
- page.stylesheets.length.must_equal 1
42
+ expect(page.stylesheets.length).to eq 1
43
43
 
44
- page.stylesheets[0].name.must_equal "inline_import.html"
45
- page.stylesheets[0].stylesheets[0].name.must_equal "print.css"
46
- page.stylesheets[0].stylesheets[1].name.must_equal "fonts.css"
47
- page.stylesheets[0].stylesheets[2].name.must_equal "colors.css"
44
+ expect(page.stylesheets[0].name).to eq "inline_import.html"
45
+ expect(page.stylesheets[0].stylesheets[0].name).to eq "print.css"
46
+ expect(page.stylesheets[0].stylesheets[1].name).to eq "fonts.css"
47
+ expect(page.stylesheets[0].stylesheets[2].name).to eq "colors.css"
48
48
  end
49
49
 
50
50
  it "should build styles from external relative css" do
@@ -52,12 +52,12 @@ describe Page do
52
52
  page = ColorParser::Page.new(url)
53
53
 
54
54
  # 2 found
55
- page.stylesheets.length.must_equal 2
55
+ expect(page.stylesheets.length).to eq 2
56
56
 
57
57
  # stylesheet content
58
58
  sheet = page.stylesheets.first
59
- sheet.type.must_equal "external"
60
- sheet.text.must_include "background"
59
+ expect(sheet.type).to eq "external"
60
+ expect(sheet.text).to include "background"
61
61
  end
62
62
 
63
63
  it "should build styles from external relative root css" do
@@ -65,12 +65,12 @@ describe Page do
65
65
  page = ColorParser::Page.new(url)
66
66
 
67
67
  # 2 found
68
- page.stylesheets.length.must_equal 2
68
+ expect(page.stylesheets.length).to eq 2
69
69
 
70
70
  # stylesheet content
71
71
  sheet = page.stylesheets.first
72
- sheet.type.must_equal "external"
73
- sheet.text.must_include "background"
72
+ expect(sheet.type).to eq "external"
73
+ expect(sheet.text).to include "background"
74
74
  end
75
75
 
76
76
  it "should build styles from external absolute css" do
@@ -78,12 +78,12 @@ describe Page do
78
78
  page = ColorParser::Page.new(url)
79
79
 
80
80
  # 2 found
81
- page.stylesheets.length.must_equal 2
81
+ expect(page.stylesheets.length).to eq 2
82
82
 
83
83
  # stylesheet content
84
84
  sheet = page.stylesheets.first
85
- sheet.type.must_equal "external"
86
- sheet.text.must_include "background"
85
+ expect(sheet.type).to eq "external"
86
+ expect(sheet.text).to include "background"
87
87
  end
88
88
 
89
89
  it "should build styles from imported css" do
@@ -91,18 +91,18 @@ describe Page do
91
91
  page = ColorParser::Page.new(url)
92
92
  css = page.stylesheets
93
93
 
94
- css.length.must_equal 2
94
+ expect(css.length).to eq 2
95
95
 
96
96
  # 5 found
97
- css[0].name.must_include "screen.css"
98
- css[1].name.must_include "print.css"
97
+ expect(css[0].name).to include "screen.css"
98
+ expect(css[1].name).to include "print.css"
99
99
 
100
- css[0].stylesheets[0].name.must_include "master.css"
101
- css[0].stylesheets[1].name.must_include "fonts.css"
102
- css[0].stylesheets[2].name.must_include "ie.css"
103
- css[0].stylesheets[3].name.must_include "images.css"
104
- css[0].stylesheets[4].name.must_include "borders.css"
105
- css[0].stylesheets[5].name.must_include "colors.css"
100
+ expect(css[0].stylesheets[0].name).to include "master.css"
101
+ expect(css[0].stylesheets[1].name).to include "fonts.css"
102
+ expect(css[0].stylesheets[2].name).to include "ie.css"
103
+ expect(css[0].stylesheets[3].name).to include "images.css"
104
+ expect(css[0].stylesheets[4].name).to include "borders.css"
105
+ expect(css[0].stylesheets[5].name).to include "colors.css"
106
106
  end
107
107
 
108
108
  it "should not fail from an invalid css path" do
@@ -110,8 +110,8 @@ describe Page do
110
110
  page = ColorParser::Page.new(url)
111
111
 
112
112
  # 1 found
113
- page.stylesheets.length.must_equal 1
114
- page.stylesheets[0].name.must_include "screen.css"
113
+ expect(page.stylesheets.length).to eq 1
114
+ expect(page.stylesheets[0].name).to include "screen.css"
115
115
  end
116
116
 
117
117
 
@@ -122,10 +122,10 @@ describe Page do
122
122
  page = ColorParser::Page.new(url)
123
123
  images = page.images
124
124
 
125
- images.size.must_equal 2
125
+ expect(images.size).to eq 2
126
126
 
127
- images[0].url.must_equal "http://example.com/inline_images/images/apple.png"
128
- images[1].url.must_equal "http://example.com/inline_images/images/kiwi.jpg"
127
+ expect(images[0].url).to eq "http://example.com/inline_images/images/apple.png"
128
+ expect(images[1].url).to eq "http://example.com/inline_images/images/kiwi.jpg"
129
129
  end
130
130
 
131
131
  it "should build images from inline images with relative root paths" do
@@ -133,10 +133,10 @@ describe Page do
133
133
  page = ColorParser::Page.new(url)
134
134
  images = page.images
135
135
 
136
- images.size.must_equal 2
136
+ expect(images.size).to eq 2
137
137
 
138
- images[0].url.must_equal "http://example.com/inline_images/images/apple.png"
139
- images[1].url.must_equal "http://example.com/inline_images/images/kiwi.jpg"
138
+ expect(images[0].url).to eq "http://example.com/inline_images/images/apple.png"
139
+ expect(images[1].url).to eq "http://example.com/inline_images/images/kiwi.jpg"
140
140
  end
141
141
 
142
142
  it "should build images from inline images with absolute paths" do
@@ -144,10 +144,10 @@ describe Page do
144
144
  page = ColorParser::Page.new(url)
145
145
  images = page.images
146
146
 
147
- images.size.must_equal 2
147
+ expect(images.size).to eq 2
148
148
 
149
- images[0].url.must_equal "http://example.com/inline_images/images/apple.png"
150
- images[1].url.must_equal "http://example.com/inline_images/images/kiwi.jpg"
149
+ expect(images[0].url).to eq "http://example.com/inline_images/images/apple.png"
150
+ expect(images[1].url).to eq "http://example.com/inline_images/images/kiwi.jpg"
151
151
  end
152
152
 
153
153
 
@@ -158,13 +158,13 @@ describe Page do
158
158
  page = ColorParser::Page.new(url)
159
159
  images = page.images
160
160
 
161
- images.size.must_equal 5
161
+ expect(images.size).to eq 5
162
162
 
163
- images[0].name.must_equal "mango.png"
164
- images[1].name.must_equal "apple.png"
165
- images[2].name.must_equal "kiwi.jpg"
166
- images[3].name.must_equal "cantaloupe.png"
167
- images[4].name.must_equal "pineapple.png"
163
+ expect(images[0].name).to eq "mango.png"
164
+ expect(images[1].name).to eq "apple.png"
165
+ expect(images[2].name).to eq "kiwi.jpg"
166
+ expect(images[3].name).to eq "cantaloupe.png"
167
+ expect(images[4].name).to eq "pineapple.png"
168
168
  end
169
169
 
170
170
 
@@ -175,12 +175,12 @@ describe Page do
175
175
  page = ColorParser::Page.new(url)
176
176
  colors = page.colors
177
177
 
178
- colors["386ec0"].must_equal 4
179
- colors["3a5dc4"].must_equal 3
180
- colors["718ad7"].must_equal 2
181
- colors["ff0000"].must_equal 1
182
- colors["357ad1"].must_equal 1
183
- colors["535353"].must_equal 1
178
+ expect(colors["386ec0"]).to eq 4
179
+ expect(colors["3a5dc4"]).to eq 3
180
+ expect(colors["718ad7"]).to eq 2
181
+ expect(colors["ff0000"]).to eq 1
182
+ expect(colors["357ad1"]).to eq 1
183
+ expect(colors["535353"]).to eq 1
184
184
  end
185
185
 
186
186
  it "should solot colors by frequency" do
@@ -188,7 +188,7 @@ describe Page do
188
188
  page = ColorParser::Page.new(url)
189
189
 
190
190
  colors = ["386ec0", "3a5dc4", "718ad7", "535353", "357ad1", "ff0000"]
191
- page.colors_by_frequency.must_equal colors
191
+ expect(page.colors_by_frequency).to eq colors
192
192
  end
193
193
 
194
194
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ColorParser do
4
+ describe "#get" do
5
+ it "must return results" do
6
+ request = Request.new
7
+
8
+ # body = request.get("http://google.com")
9
+ # expect(body).to include "<html"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require_relative '../lib/color_parser.rb'
5
+ require_relative '../spec/stubs/fake_request.rb'
6
+
7
+ include ColorParser
8
+
9
+ RSpec.configure do |config|
10
+ end
@@ -1,5 +1,5 @@
1
1
  module ColorParser
2
- class TestRequest
2
+ class FakeRequest
3
3
  def initialize(params={})
4
4
  end
5
5
 
@@ -12,7 +12,7 @@ module ColorParser
12
12
  end
13
13
 
14
14
  # simple hack to read in fixtures instead of url for tests
15
- fixture = "#{File.dirname(__FILE__)}/../test/fixtures#{uri.path}"
15
+ fixture = "#{File.dirname(__FILE__)}/../fixtures#{uri.path}"
16
16
  File.read(fixture) if File.exist?(fixture)
17
17
  end
18
18
  end
@@ -0,0 +1,235 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stylesheet do
4
+ before(:each) do
5
+ ColorParser.request = FakeRequest.new
6
+ end
7
+
8
+ describe "#new" do
9
+ it "must initialize params" do
10
+ sheet = ColorParser::Stylesheet.new(text: "a { background: #fff; }",
11
+ type: "inline",
12
+ url: "http://example.com/css/inline.html?foo=bar")
13
+ expect(sheet.type).to eq "inline"
14
+ expect(sheet.text).to eq "a { background: #fff; }"
15
+ expect(sheet.url).to eq "http://example.com/css/inline.html?foo=bar"
16
+ expect(sheet.host).to eq "example.com"
17
+ expect(sheet.path).to eq "/css/inline.html"
18
+ expect(sheet.query).to eq "foo=bar"
19
+ end
20
+ end
21
+
22
+ describe "import quoting" do
23
+ let :style do
24
+ ColorParser::Stylesheet.new(text: fixture("/css_import/stylesheets/screen.css"),
25
+ url: "http://example.com/css_import/stylesheets/screen.css")
26
+ end
27
+
28
+ it "should import stylesheets with double quotes" do
29
+ imported = style.stylesheets[0]
30
+ expect(imported.name).to eq "master.css"
31
+ expect(imported.text).to include "a:link"
32
+ end
33
+
34
+ it "should import stylesheets with single quotes" do
35
+ imported = style.stylesheets[1]
36
+ expect(imported.name).to eq "fonts.css"
37
+ expect(imported.text).to include "font-family"
38
+ end
39
+
40
+ it "should import stylesheets with no quotes" do
41
+ imported = style.stylesheets[2]
42
+ expect(imported.name).to eq "ie.css"
43
+ expect(imported.text).to include "background-color"
44
+ end
45
+ end
46
+
47
+ describe "import paths" do
48
+ let :style do
49
+ ColorParser::Stylesheet.new(text: fixture("/css_import/stylesheets/screen.css"),
50
+ url: "http://example.com/css_import/stylesheets/screen.css")
51
+ end
52
+
53
+ it "should import from relative path" do
54
+ imported = style.stylesheets[0]
55
+ expect(imported.url).to eq "http://example.com/css_import/stylesheets/master.css"
56
+ end
57
+
58
+ it "should import from relative root path" do
59
+ imported = style.stylesheets[1]
60
+ expect(imported.url).to eq "http://example.com/css_import/stylesheets/fonts.css"
61
+ end
62
+
63
+ it "should import from absolute path" do
64
+ imported = style.stylesheets[2]
65
+ expect(imported.url).to eq "http://example.com/css_import/stylesheets/ie.css"
66
+ end
67
+
68
+ it "should not fail on invalid import path" do
69
+ expect(style.stylesheets[6]).to be_nil
70
+ end
71
+ end
72
+
73
+ describe "selector parsing" do
74
+ let :style do
75
+ ColorParser::Stylesheet.new(text: fixture("/css_color/stylesheets/properties.css"),
76
+ url: "http://example.com/css_color/stylesheets/properties.css")
77
+ end
78
+
79
+ it "should parse selectors" do
80
+ selectors = style.selectors
81
+
82
+ expect(selectors.size).to eq 4
83
+
84
+ expect(selectors["p"].size).to eq 2
85
+ expect(selectors["div"].size).to eq 1
86
+ expect(selectors["h1"].size).to eq 2
87
+
88
+ # imported
89
+ expect(selectors["dl"].size).to eq 1
90
+ end
91
+
92
+ it "should parse properties" do
93
+ props = style.properties
94
+
95
+ expect(props.size).to eq 9
96
+
97
+ expect(props).to include ["background", "#000"]
98
+ expect(props).to include ["color", "#fff"]
99
+ expect(props).to include ["margin", "0"]
100
+ expect(props).to include ["background-color", "#ccc"]
101
+ expect(props).to include ["font-size", "100%"]
102
+ expect(props).to include ["border-color", "rgb(1,2,3)"]
103
+
104
+ # imported
105
+ expect(props).to include ["border", "1px solid red"]
106
+ end
107
+ end
108
+
109
+ describe "color parsing" do
110
+ let :style do
111
+ ColorParser::Stylesheet.new(text: fixture("/css_color/stylesheets/color_styles.css"),
112
+ url: "http://example.com/css_color/stylesheets/color_styles.css")
113
+ end
114
+
115
+ it "should parse hex colors" do
116
+ expect(style.colors["386ec0"]).to be # 386ec0
117
+ end
118
+
119
+ it "should parse hex short colors" do
120
+ expect(style.colors["cc00cc"]).to be # c0c
121
+ end
122
+
123
+ it "should parse textual colors" do
124
+ expect(style.colors["008080"]).to be # teal
125
+ end
126
+
127
+ it "should parse rgb colors" do
128
+ expect(style.colors["718ad7"]).to be # rgb(113,138,215)
129
+ end
130
+
131
+ it "should parse rgb colors with space" do
132
+ expect(style.colors["3a5dc4"]).to be # rgb(58, 93, 196)
133
+ end
134
+
135
+ it "should parse rgba colors" do
136
+ expect(style.colors["29469e"]).to be # rgba(41,70,158,0.5);
137
+ end
138
+
139
+ it "should parse rgba colors with space" do
140
+ expect(style.colors["3f6aeb"]).to be # rgba(63, 106, 235, 0.5);
141
+ end
142
+ end
143
+
144
+ describe "color weighting" do
145
+ let :style do
146
+ ColorParser::Stylesheet.new(text: fixture("/css_color/stylesheets/frequency.css"),
147
+ url: "http://example.com/css_color/stylesheets/frequency.css")
148
+ end
149
+
150
+ it "should order colors by frequency" do
151
+ colors = {"386ec0" => 4, "3a5dc4" => 3,
152
+ "718ad7" => 2, "ff0000" => 1}
153
+ expect(style.colors).to eq colors
154
+ end
155
+
156
+ # BG colors
157
+ it "should order background colors by frequency" do
158
+ colors = {"386ec0" => 2, "3a5dc4" => 1}
159
+ expect(style.bg_colors).to eq colors
160
+ end
161
+
162
+ # Text colors
163
+ it "should order text colors by frequency" do
164
+ colors = {"386ec0" => 2, "718ad7" => 1}
165
+ expect(style.text_colors).to eq colors
166
+ end
167
+
168
+ # Border colors
169
+ it "should order border colors by frequency" do
170
+ colors = {"3a5dc4" => 2, "ff0000" => 1, "718ad7" => 1}
171
+ expect(style.border_colors).to eq colors
172
+ end
173
+ end
174
+
175
+ describe "image parsing" do
176
+ let :style do
177
+ ColorParser::Stylesheet.new(text: fixture("/css_images/stylesheets/quotes.css"),
178
+ url: "http://example.com/css_images/stylesheets/quotes.css")
179
+ end
180
+
181
+ it "should parse images with double quotes" do
182
+ expect(style.images[0].name).to eq "apple.png"
183
+ end
184
+
185
+ it "should parse images with single quotes" do
186
+ expect(style.images[1].name).to eq "kiwi.jpg"
187
+ end
188
+
189
+ it "should parse images with no quotes" do
190
+ expect(style.images[2].name).to eq "cantaloupe.png"
191
+ end
192
+ end
193
+
194
+ describe "image paths" do
195
+ let :style do
196
+ ColorParser::Stylesheet.new(text: fixture("/css_images/stylesheets/paths.css"),
197
+ url: "http://example.com/css_images/stylesheets/paths.css")
198
+ end
199
+
200
+ it "should build image from absolute path" do
201
+ urls = style.images.map {|image| image.url }
202
+
203
+ expect(urls.size).to eq 4
204
+ expect(urls).to include "http://example.com/css_images/images/apple.png"
205
+ end
206
+
207
+ it "should build image from relative path" do
208
+ urls = style.images.map {|image| image.url }
209
+
210
+ expect(urls.size).to eq 4
211
+ expect(urls).to include "http://example.com/css_images/images/kiwi.jpg"
212
+ end
213
+
214
+ it "should build image from relative root path" do
215
+ urls = style.images.map {|image| image.url }
216
+
217
+ expect(urls.size).to eq 4
218
+ expect(urls).to include "http://example.com/css_images/images/cantaloupe.png"
219
+ end
220
+
221
+ it "should build image from imported path" do
222
+ urls = style.images.map {|image| image.url }
223
+
224
+ expect(urls.size).to eq 4
225
+ expect(urls).to include "http://example.com/css_images/images/pineapple.png"
226
+ end
227
+ end
228
+ end
229
+
230
+ private
231
+
232
+ def fixture(path)
233
+ fixture = "#{File.dirname(__FILE__)}/../spec/fixtures#{path}"
234
+ File.read(fixture) if File.exist?(fixture)
235
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe VERSION do
4
+ describe "version" do
5
+ it "should be present" do
6
+ expect(ColorParser::VERSION).not_to be_nil
7
+ end
8
+ end
9
+ end