color_parser 0.0.2 → 0.1.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.
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: nokogiri
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,7 +59,71 @@ dependencies:
43
59
  - - ! '>='
44
60
  - !ruby/object:Gem::Version
45
61
  version: '0'
46
- description: Color Parser finds the colors on a given webpage
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.9'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.9'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.7'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.7'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.5'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.5'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rb-fsevent
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.9'
126
+ description: Finds colors on a given webpage
47
127
  email:
48
128
  - derek@sportspyder.com
49
129
  executables: []
@@ -52,61 +132,67 @@ extra_rdoc_files: []
52
132
  files:
53
133
  - .gitignore
54
134
  - Gemfile
135
+ - Guardfile
55
136
  - LICENSE.txt
56
137
  - README.md
57
138
  - Rakefile
58
139
  - color_parser.gemspec
59
140
  - lib/color_parser.rb
141
+ - lib/color_parser/color.rb
142
+ - lib/color_parser/errors.rb
60
143
  - lib/color_parser/image.rb
61
144
  - lib/color_parser/page.rb
145
+ - lib/color_parser/request.rb
62
146
  - lib/color_parser/stylesheet.rb
63
147
  - lib/color_parser/version.rb
64
- - test/color_parser_test.rb
65
- - test/fixtures/css/absolute.html
66
- - test/fixtures/css/inline.html
67
- - test/fixtures/css/inline_import.html
68
- - test/fixtures/css/invalid.html
69
- - test/fixtures/css/relative.html
70
- - test/fixtures/css/relative_root.html
71
- - test/fixtures/css/stylesheets/colors.css
72
- - test/fixtures/css/stylesheets/fonts.css
73
- - test/fixtures/css/stylesheets/print.css
74
- - test/fixtures/css/stylesheets/screen.css
75
- - test/fixtures/css_color/frequency.html
76
- - test/fixtures/css_color/stylesheets/color_styles.css
77
- - test/fixtures/css_color/stylesheets/css_elements.css
78
- - test/fixtures/css_color/stylesheets/frequency.css
79
- - test/fixtures/css_color/stylesheets/imported_selectors.css
80
- - test/fixtures/css_color/stylesheets/properties.css
81
- - test/fixtures/css_images/images/apple.png
82
- - test/fixtures/css_images/images/cantaloupe.png
83
- - test/fixtures/css_images/images/kiwi.jpg
84
- - test/fixtures/css_images/images/mango.png
85
- - test/fixtures/css_images/images/pineapple.png
86
- - test/fixtures/css_images/paths.html
87
- - test/fixtures/css_images/stylesheets/import_paths.css
88
- - test/fixtures/css_images/stylesheets/paths.css
89
- - test/fixtures/css_images/stylesheets/quotes.css
90
- - test/fixtures/css_import/index.html
91
- - test/fixtures/css_import/stylesheets/borders.css
92
- - test/fixtures/css_import/stylesheets/colors.css
93
- - test/fixtures/css_import/stylesheets/fonts.css
94
- - test/fixtures/css_import/stylesheets/ie.css
95
- - test/fixtures/css_import/stylesheets/images.css
96
- - test/fixtures/css_import/stylesheets/master.css
97
- - test/fixtures/css_import/stylesheets/print.css
98
- - test/fixtures/css_import/stylesheets/screen.css
99
- - test/fixtures/inline_images/absolute.html
100
- - test/fixtures/inline_images/images/apple.png
101
- - test/fixtures/inline_images/images/kiwi.jpg
102
- - test/fixtures/inline_images/relative.html
103
- - test/fixtures/inline_images/relative_root.html
104
- - test/image_test.rb
105
- - test/page_test.rb
106
- - test/stylesheet_test.rb
107
- - test/test_helper.rb
108
- - test/test_request.rb
109
- - test/version_test.rb
148
+ - spec/color_parser_spec.rb
149
+ - spec/color_spec.rb
150
+ - spec/fixtures/css/absolute.html
151
+ - spec/fixtures/css/inline.html
152
+ - spec/fixtures/css/inline_import.html
153
+ - spec/fixtures/css/invalid.html
154
+ - spec/fixtures/css/relative.html
155
+ - spec/fixtures/css/relative_root.html
156
+ - spec/fixtures/css/stylesheets/colors.css
157
+ - spec/fixtures/css/stylesheets/fonts.css
158
+ - spec/fixtures/css/stylesheets/print.css
159
+ - spec/fixtures/css/stylesheets/screen.css
160
+ - spec/fixtures/css_color/frequency.html
161
+ - spec/fixtures/css_color/stylesheets/color_styles.css
162
+ - spec/fixtures/css_color/stylesheets/css_elements.css
163
+ - spec/fixtures/css_color/stylesheets/frequency.css
164
+ - spec/fixtures/css_color/stylesheets/imported_selectors.css
165
+ - spec/fixtures/css_color/stylesheets/properties.css
166
+ - spec/fixtures/css_images/images/apple.png
167
+ - spec/fixtures/css_images/images/cantaloupe.png
168
+ - spec/fixtures/css_images/images/kiwi.jpg
169
+ - spec/fixtures/css_images/images/mango.png
170
+ - spec/fixtures/css_images/images/pineapple.png
171
+ - spec/fixtures/css_images/paths.html
172
+ - spec/fixtures/css_images/stylesheets/import_paths.css
173
+ - spec/fixtures/css_images/stylesheets/paths.css
174
+ - spec/fixtures/css_images/stylesheets/quotes.css
175
+ - spec/fixtures/css_import/index.html
176
+ - spec/fixtures/css_import/stylesheets/borders.css
177
+ - spec/fixtures/css_import/stylesheets/colors.css
178
+ - spec/fixtures/css_import/stylesheets/fonts.css
179
+ - spec/fixtures/css_import/stylesheets/ie.css
180
+ - spec/fixtures/css_import/stylesheets/images.css
181
+ - spec/fixtures/css_import/stylesheets/master.css
182
+ - spec/fixtures/css_import/stylesheets/print.css
183
+ - spec/fixtures/css_import/stylesheets/screen.css
184
+ - spec/fixtures/inline_images/absolute.html
185
+ - spec/fixtures/inline_images/images/apple.png
186
+ - spec/fixtures/inline_images/images/kiwi.jpg
187
+ - spec/fixtures/inline_images/relative.html
188
+ - spec/fixtures/inline_images/relative_root.html
189
+ - spec/image_spec.rb
190
+ - spec/page_spec.rb
191
+ - spec/request_spec.rb
192
+ - spec/spec_helper.rb
193
+ - spec/stubs/fake_request.rb
194
+ - spec/stylesheet_spec.rb
195
+ - spec/version_spec.rb
110
196
  homepage: https://github.com/devrieda/color_parser
111
197
  licenses:
112
198
  - MIT
@@ -126,59 +212,59 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
212
  - - ! '>='
127
213
  - !ruby/object:Gem::Version
128
214
  version: '0'
129
- segments:
130
- - 0
131
- hash: -3886628688892773367
132
215
  requirements: []
133
216
  rubyforge_project:
134
- rubygems_version: 1.8.24
217
+ rubygems_version: 1.8.25
135
218
  signing_key:
136
219
  specification_version: 3
137
- summary: Color Parser finds the colors on a given webpage
220
+ summary: Finds colors on a given webpage
138
221
  test_files:
139
- - test/color_parser_test.rb
140
- - test/fixtures/css/absolute.html
141
- - test/fixtures/css/inline.html
142
- - test/fixtures/css/inline_import.html
143
- - test/fixtures/css/invalid.html
144
- - test/fixtures/css/relative.html
145
- - test/fixtures/css/relative_root.html
146
- - test/fixtures/css/stylesheets/colors.css
147
- - test/fixtures/css/stylesheets/fonts.css
148
- - test/fixtures/css/stylesheets/print.css
149
- - test/fixtures/css/stylesheets/screen.css
150
- - test/fixtures/css_color/frequency.html
151
- - test/fixtures/css_color/stylesheets/color_styles.css
152
- - test/fixtures/css_color/stylesheets/css_elements.css
153
- - test/fixtures/css_color/stylesheets/frequency.css
154
- - test/fixtures/css_color/stylesheets/imported_selectors.css
155
- - test/fixtures/css_color/stylesheets/properties.css
156
- - test/fixtures/css_images/images/apple.png
157
- - test/fixtures/css_images/images/cantaloupe.png
158
- - test/fixtures/css_images/images/kiwi.jpg
159
- - test/fixtures/css_images/images/mango.png
160
- - test/fixtures/css_images/images/pineapple.png
161
- - test/fixtures/css_images/paths.html
162
- - test/fixtures/css_images/stylesheets/import_paths.css
163
- - test/fixtures/css_images/stylesheets/paths.css
164
- - test/fixtures/css_images/stylesheets/quotes.css
165
- - test/fixtures/css_import/index.html
166
- - test/fixtures/css_import/stylesheets/borders.css
167
- - test/fixtures/css_import/stylesheets/colors.css
168
- - test/fixtures/css_import/stylesheets/fonts.css
169
- - test/fixtures/css_import/stylesheets/ie.css
170
- - test/fixtures/css_import/stylesheets/images.css
171
- - test/fixtures/css_import/stylesheets/master.css
172
- - test/fixtures/css_import/stylesheets/print.css
173
- - test/fixtures/css_import/stylesheets/screen.css
174
- - test/fixtures/inline_images/absolute.html
175
- - test/fixtures/inline_images/images/apple.png
176
- - test/fixtures/inline_images/images/kiwi.jpg
177
- - test/fixtures/inline_images/relative.html
178
- - test/fixtures/inline_images/relative_root.html
179
- - test/image_test.rb
180
- - test/page_test.rb
181
- - test/stylesheet_test.rb
182
- - test/test_helper.rb
183
- - test/test_request.rb
184
- - test/version_test.rb
222
+ - spec/color_parser_spec.rb
223
+ - spec/color_spec.rb
224
+ - spec/fixtures/css/absolute.html
225
+ - spec/fixtures/css/inline.html
226
+ - spec/fixtures/css/inline_import.html
227
+ - spec/fixtures/css/invalid.html
228
+ - spec/fixtures/css/relative.html
229
+ - spec/fixtures/css/relative_root.html
230
+ - spec/fixtures/css/stylesheets/colors.css
231
+ - spec/fixtures/css/stylesheets/fonts.css
232
+ - spec/fixtures/css/stylesheets/print.css
233
+ - spec/fixtures/css/stylesheets/screen.css
234
+ - spec/fixtures/css_color/frequency.html
235
+ - spec/fixtures/css_color/stylesheets/color_styles.css
236
+ - spec/fixtures/css_color/stylesheets/css_elements.css
237
+ - spec/fixtures/css_color/stylesheets/frequency.css
238
+ - spec/fixtures/css_color/stylesheets/imported_selectors.css
239
+ - spec/fixtures/css_color/stylesheets/properties.css
240
+ - spec/fixtures/css_images/images/apple.png
241
+ - spec/fixtures/css_images/images/cantaloupe.png
242
+ - spec/fixtures/css_images/images/kiwi.jpg
243
+ - spec/fixtures/css_images/images/mango.png
244
+ - spec/fixtures/css_images/images/pineapple.png
245
+ - spec/fixtures/css_images/paths.html
246
+ - spec/fixtures/css_images/stylesheets/import_paths.css
247
+ - spec/fixtures/css_images/stylesheets/paths.css
248
+ - spec/fixtures/css_images/stylesheets/quotes.css
249
+ - spec/fixtures/css_import/index.html
250
+ - spec/fixtures/css_import/stylesheets/borders.css
251
+ - spec/fixtures/css_import/stylesheets/colors.css
252
+ - spec/fixtures/css_import/stylesheets/fonts.css
253
+ - spec/fixtures/css_import/stylesheets/ie.css
254
+ - spec/fixtures/css_import/stylesheets/images.css
255
+ - spec/fixtures/css_import/stylesheets/master.css
256
+ - spec/fixtures/css_import/stylesheets/print.css
257
+ - spec/fixtures/css_import/stylesheets/screen.css
258
+ - spec/fixtures/inline_images/absolute.html
259
+ - spec/fixtures/inline_images/images/apple.png
260
+ - spec/fixtures/inline_images/images/kiwi.jpg
261
+ - spec/fixtures/inline_images/relative.html
262
+ - spec/fixtures/inline_images/relative_root.html
263
+ - spec/image_spec.rb
264
+ - spec/page_spec.rb
265
+ - spec/request_spec.rb
266
+ - spec/spec_helper.rb
267
+ - spec/stubs/fake_request.rb
268
+ - spec/stylesheet_spec.rb
269
+ - spec/version_spec.rb
270
+ has_rdoc:
data/test/image_test.rb DELETED
@@ -1,27 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- describe Image do
4
- def setup
5
- ColorParser.request = ColorParser::TestRequest.new
6
- end
7
-
8
- it "should assign url" do
9
- image = ColorParser::Image.new("http://example.com/foo/bar.png")
10
-
11
- image.url.must_equal "http://example.com/foo/bar.png"
12
- end
13
-
14
- it "should parse host path and query from url" do
15
- image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
16
-
17
- image.host.must_equal "example.com"
18
- image.path.must_equal "/foo/bar.png"
19
- image.query.must_equal "baz=bar"
20
- end
21
-
22
- it "should parse name" do
23
- image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
24
-
25
- "bar.png".must_equal image.name
26
- end
27
- end
@@ -1,257 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- describe Stylesheet do
4
- def setup
5
- ColorParser.request = ColorParser::TestRequest.new
6
- end
7
-
8
- it "must initialize params" do
9
- sheet = ColorParser::Stylesheet.new(text: "a { background: #fff; }",
10
- type: "inline",
11
- url: "http://example.com/css/inline.html?foo=bar")
12
- sheet.type.must_equal "inline"
13
- sheet.text.must_equal "a { background: #fff; }"
14
- sheet.url.must_equal "http://example.com/css/inline.html?foo=bar"
15
- sheet.host.must_equal "example.com"
16
- sheet.path.must_equal "/css/inline.html"
17
- sheet.query.must_equal "foo=bar"
18
- end
19
-
20
-
21
- # Import Quoting
22
-
23
- it "should import stylesheets with double quotes" do
24
- css = style("/css_import/stylesheets/screen.css")
25
-
26
- imported = css.stylesheets[0]
27
- imported.name.must_equal "master.css"
28
- imported.text.must_include "a:link"
29
- end
30
-
31
- it "should import stylesheets with single quotes" do
32
- css = style("/css_import/stylesheets/screen.css")
33
-
34
- imported = css.stylesheets[1]
35
- imported.name.must_equal "fonts.css"
36
- imported.text.must_include "font-family"
37
- end
38
-
39
- it "should import stylesheets with no quotes" do
40
- css = style("/css_import/stylesheets/screen.css")
41
-
42
- imported = css.stylesheets[2]
43
- imported.name.must_equal "ie.css"
44
- imported.text.must_include "background-color"
45
- end
46
-
47
-
48
- # Import Paths
49
-
50
- it "should import from relative path" do
51
- css = style("/css_import/stylesheets/screen.css")
52
-
53
- imported = css.stylesheets[0]
54
- imported.url.must_equal "http://example.com/css_import/stylesheets/master.css"
55
- end
56
-
57
- it "should import from relative root path" do
58
- css = style("/css_import/stylesheets/screen.css")
59
-
60
- imported = css.stylesheets[1]
61
- imported.url.must_equal "http://example.com/css_import/stylesheets/fonts.css"
62
- end
63
-
64
- it "should import from absolute path" do
65
- css = style("/css_import/stylesheets/screen.css")
66
-
67
- imported = css.stylesheets[2]
68
- imported.url.must_equal "http://example.com/css_import/stylesheets/ie.css"
69
- end
70
-
71
- it "should not fail on invalid import path" do
72
- css = style("/css_import/stylesheets/screen.css")
73
- css.stylesheets[6].must_be_nil
74
- end
75
-
76
-
77
- # Selector parsing
78
-
79
- it "should parse selectors" do
80
- css = style("/css_color/stylesheets/properties.css")
81
- selectors = css.selectors
82
-
83
- selectors.size.must_equal 4
84
-
85
- selectors["p"].size.must_equal 2
86
- selectors["div"].size.must_equal 1
87
- selectors["h1"].size.must_equal 2
88
-
89
- # imported
90
- selectors["dl"].size.must_equal 1
91
- end
92
-
93
- it "should parse properties" do
94
- css = style("/css_color/stylesheets/properties.css")
95
- props = css.properties
96
-
97
- props.size.must_equal 9
98
-
99
- props.must_include ["background", "#000"]
100
- props.must_include ["color", "#fff"]
101
- props.must_include ["margin", "0"]
102
- props.must_include ["background-color", "#ccc"]
103
- props.must_include ["font-size", "100%"]
104
- props.must_include ["border-color", "rgb(1,2,3)"]
105
-
106
- # imported
107
- props.must_include ["border", "1px solid red"]
108
- end
109
-
110
-
111
- # Color Parsing
112
-
113
- it "should parse hex colors" do
114
- css = style("/css_color/stylesheets/color_styles.css")
115
-
116
- css.colors["386ec0"].wont_be_nil # 386ec0
117
- end
118
-
119
- it "should parse hex short colors" do
120
- css = style("/css_color/stylesheets/color_styles.css")
121
-
122
- css.colors["cc00cc"].wont_be_nil # c0c
123
- end
124
-
125
- it "should parse textual colors" do
126
- css = style("/css_color/stylesheets/color_styles.css")
127
-
128
- css.colors["008080"].wont_be_nil # teal
129
- end
130
-
131
- it "should parse rgb colors" do
132
- css = style("/css_color/stylesheets/color_styles.css")
133
-
134
- css.colors["718ad7"].wont_be_nil # rgb(113,138,215)
135
- end
136
-
137
- it "should parse rgb colors with space" do
138
- css = style("/css_color/stylesheets/color_styles.css")
139
-
140
- css.colors["3a5dc4"].wont_be_nil # rgb(58, 93, 196)
141
- end
142
-
143
- it "should parse rgba colors" do
144
- css = style("/css_color/stylesheets/color_styles.css")
145
-
146
- css.colors["29469e"].wont_be_nil # rgba(41,70,158,0.5);
147
- end
148
-
149
- it "should parse rgba colors with space" do
150
- css = style("/css_color/stylesheets/color_styles.css")
151
-
152
- css.colors["3f6aeb"].wont_be_nil # rgba(63, 106, 235, 0.5);
153
- end
154
-
155
-
156
- # Color weighting
157
-
158
- it "should order colors by frequency" do
159
- css = style("/css_color/stylesheets/frequency.css")
160
-
161
- colors = {"386ec0" => 4, "3a5dc4" => 3,
162
- "718ad7" => 2, "ff0000" => 1}
163
- css.colors.must_equal colors
164
- end
165
-
166
- # BG colors
167
- it "should order background colors by frequency" do
168
- css = style("/css_color/stylesheets/frequency.css")
169
-
170
- colors = {"386ec0" => 2, "3a5dc4" => 1}
171
- css.bg_colors.must_equal colors
172
- end
173
-
174
- # Text colors
175
- it "should order text colors by frequency" do
176
- css = style("/css_color/stylesheets/frequency.css")
177
-
178
- colors = {"386ec0" => 2, "718ad7" => 1}
179
- css.text_colors.must_equal colors
180
- end
181
-
182
- # Border colors
183
- it "should order border colors by frequency" do
184
- css = style("/css_color/stylesheets/frequency.css")
185
-
186
- colors = {"3a5dc4" => 2, "ff0000" => 1, "718ad7" => 1}
187
- css.border_colors.must_equal colors
188
- end
189
-
190
-
191
- # Images Parsing
192
-
193
- it "should parse images with double quotes" do
194
- css = style("/css_images/stylesheets/quotes.css")
195
-
196
- css.images[0].name.must_equal "apple.png"
197
- end
198
-
199
- it "should parse images with single quotes" do
200
- css = style("/css_images/stylesheets/quotes.css")
201
-
202
- css.images[1].name.must_equal "kiwi.jpg"
203
- end
204
-
205
- it "should parse images with no quotes" do
206
- css = style("/css_images/stylesheets/quotes.css")
207
-
208
- css.images[2].name.must_equal "cantaloupe.png"
209
- end
210
-
211
-
212
- # Image paths
213
-
214
- it "should build image from absolute path" do
215
- css = style("/css_images/stylesheets/paths.css")
216
- urls = css.images.map {|image| image.url }
217
-
218
- urls.size.must_equal 4
219
- urls.must_include "http://example.com/css_images/images/apple.png"
220
- end
221
-
222
- it "should build image from relative path" do
223
- css = style("/css_images/stylesheets/paths.css")
224
- urls = css.images.map {|image| image.url }
225
-
226
- urls.size.must_equal 4
227
- urls.must_include "http://example.com/css_images/images/kiwi.jpg"
228
- end
229
-
230
- it "should build image from relative root path" do
231
- css = style("/css_images/stylesheets/paths.css")
232
- urls = css.images.map {|image| image.url }
233
-
234
- urls.size.must_equal 4
235
- urls.must_include "http://example.com/css_images/images/cantaloupe.png"
236
- end
237
-
238
- it "should build image from imported path" do
239
- css = style("/css_images/stylesheets/paths.css")
240
- urls = css.images.map {|image| image.url }
241
-
242
- urls.size.must_equal 4
243
- urls.must_include "http://example.com/css_images/images/pineapple.png"
244
- end
245
- end
246
-
247
- private
248
-
249
- def style(path)
250
- ColorParser::Stylesheet.new(text: fixture(path),
251
- url: "http://example.com#{path}")
252
- end
253
-
254
- def fixture(path)
255
- fixture = "#{File.dirname(__FILE__)}/../test/fixtures#{path}"
256
- File.read(fixture) if File.exist?(fixture)
257
- end
data/test/test_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require File.expand_path('../../lib/color_parser.rb', __FILE__)
4
- require File.expand_path('../../test/test_request.rb', __FILE__)
5
-
6
- include ColorParser
data/test/version_test.rb DELETED
@@ -1,7 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- describe VERSION do
4
- it "must be defined" do
5
- ColorParser::VERSION.wont_be_nil
6
- end
7
- end