monet 0.2.3 → 0.2.5

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.
data/spec/config_spec.rb CHANGED
@@ -8,15 +8,21 @@ describe Monet::Config do
8
8
  And { config.capture_dir.should == File.expand_path("./captures") }
9
9
  end
10
10
 
11
- context "can pass config to init" do
12
- When(:config) { Monet::Config.new(capture_dir: "./faker", base_url: "http://hoodie.io") }
13
- Then { config.driver.should == :poltergeist }
14
- And { config.capture_dir.should == File.expand_path("./faker") }
15
- And { config.base_url.to_s.should == "http://hoodie.io" }
11
+ context "can load yaml" do
12
+ When(:config) { Monet::Config.load }
13
+ Then { config.base_url.to_s.should == "http://lance.com" }
14
+ And { config.map.size.should == 3 }
15
+ end
16
+
17
+ context "can load a yaml from a path for spidering", vcr: { cassette_name: "spider-config", record: :new_episodes } do
18
+ When(:config) { Monet::Config.load("./spec/fixtures/spider-config.yaml") }
19
+ Then { config.base_url.to_s.should == "https://staging.lance.com" }
20
+ And { config.map.type.should == :spider }
21
+ And { config.map.size.should == 64 }
16
22
  end
17
23
 
18
24
  context "can set options" do
19
- When(:config) do
25
+ When(:config) {
20
26
  Monet::Config.config do |config|
21
27
  config.driver = :poltergeist
22
28
  config.dimensions = [1440,900]
@@ -27,7 +33,7 @@ describe Monet::Config do
27
33
  map.add 'home/show'
28
34
  end
29
35
  end
30
- end
36
+ }
31
37
  Then { config.driver.should == :poltergeist }
32
38
  And { config.dimensions.should == [1440,900] }
33
39
  And { config.map.paths.should == ["home/index", "home/show"] }
@@ -48,7 +54,7 @@ describe Monet::Config do
48
54
  context "can request spider agent instead of explicit paths" do
49
55
  When(:config) do
50
56
  Monet::Config.config do |config|
51
- config.base_url = "http://www.spider.io/"
57
+ config.base_url = "http://staging.lance.com"
52
58
  config.map :spider
53
59
  end
54
60
  end
@@ -0,0 +1,8 @@
1
+ :driver: :poltergeist
2
+ :dimensions:
3
+ - 1024
4
+
5
+ :base_url: "https://staging.lance.com"
6
+
7
+ :compare_type: Highlight
8
+ :map: :spider
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'monet'
3
+ require 'monet/image'
4
+
5
+ describe Monet::Image do
6
+ Given(:img) { Monet::Image.new("./spec/fixtures/baselines/lance.com/lance.com-1024.png") }
7
+
8
+ context "knows width" do
9
+ Then { img.width.should == 1024 }
10
+ end
11
+
12
+ context "can create an image" do
13
+ Then { img.to_image.should be_a(ChunkyPNG::Image) }
14
+ end
15
+
16
+ context "generates files" do
17
+ Given(:img) { Monet::Image.new("./spec/tmp/test.png") }
18
+
19
+ after(:all) do
20
+ tmp = Dir.glob("./spec/tmp/**/*-thumb.png")
21
+ tmp.each {|f| File.delete f }
22
+ end
23
+
24
+ context "can thumbnail self without a path" do
25
+ When(:path) { img.thumbnail! }
26
+ Then { path.should_not have_failed }
27
+ And { File.exists?(path).should be_true }
28
+ end
29
+
30
+ context "can thumbnail self with a path" do
31
+ When(:path) { img.thumbnail!("./spec/tmp/output/thumbnails") }
32
+ Then { path.should_not have_failed }
33
+ And { File.exists?(path).should be_true }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'monet/router'
3
+
4
+ describe "Monet::Router" do
5
+ Given(:config) { Monet::Config.new({
6
+ base_url: "http://lance.com",
7
+ capture_dir: "./spec/fixtures/captures",
8
+ baseline_dir: "./spec/fixtures/baselines",
9
+ thumbnail_dir: "./spec/fixtures/thumbnails"
10
+ })}
11
+ Given(:router) { Monet::Router.new config }
12
+
13
+
14
+ def expand *parts
15
+ File.expand_path File.join(*parts)
16
+ end
17
+
18
+ shared_examples "type routing" do |type|
19
+ context "can get the #{type} for a path" do
20
+ When(:route) { router.send "#{type}_dir", "about-500.png" }
21
+ Then { route.should == expand(config.send("#{type}_dir"), "lance.com", "about-500.png") }
22
+ end
23
+
24
+ context "can get the #{type} url for a path" do
25
+ When(:route) { router.send "#{type}_url", "about-500.png" }
26
+ Then { route.should == "/#{type}s/#{config.site}/about-500.png" }
27
+ end
28
+
29
+ context "can get the root dir for a #{type}" do
30
+ When(:route) { router.send "#{type}_dir" }
31
+ Then { route.should == expand(config.send("#{type}_dir"), "lance.com") }
32
+ end
33
+
34
+ context "can get the diff dir for a path" do
35
+ When(:route) { router.diff_dir "lance.com|about-500.png" }
36
+ Then { route.should == expand(config.baseline_dir, "lance.com", "lance.com|about-500-diff.png") }
37
+ end
38
+
39
+ context "can get the diff url for a path" do
40
+ When(:route) { router.diff_url "lance.com|about-500.png" }
41
+ Then { route.should == "/baselines/lance.com/lance.com|about-500-diff.png" }
42
+ end
43
+ end
44
+
45
+ context "can convert url path to capture path" do
46
+ When(:path) { router.url_to_filepath("http://lance.com/my-fake-url/chromist", 2000) }
47
+ Then { path.should == File.join(config.capture_dir, "lance.com", "lance.com|my-fake-url|chromist-2000.png") }
48
+ end
49
+
50
+ context "can list out urls" do
51
+ Given do
52
+ config.dimensions = [1440,900]
53
+ config.map = ['/home/index', '/home/show']
54
+ end
55
+
56
+ When(:urls) { router.capture_routes }
57
+ Then { urls.should == {
58
+ "http://lance.com/home/index" => [
59
+ expand(config.capture_dir, "lance.com", "lance.com|home|index-1440.png"),
60
+ expand(config.capture_dir, "lance.com", "lance.com|home|index-900.png")
61
+ ],
62
+ "http://lance.com/home/show" => [
63
+ expand(config.capture_dir, "lance.com", "lance.com|home|show-1440.png"),
64
+ expand(config.capture_dir, "lance.com", "lance.com|home|show-900.png")
65
+ ]}
66
+ }
67
+ end
68
+
69
+ context "original url" do
70
+ When(:route) { router.original_url "lance.com/lance.com|about-500.png" }
71
+ Then { route.should == "http://lance.com/about" }
72
+ end
73
+
74
+ context "baseline" do
75
+ it_should_behave_like "type routing", "baseline"
76
+ end
77
+
78
+ context "capture" do
79
+ it_should_behave_like "type routing", "capture"
80
+ end
81
+
82
+ context "thumbnail" do
83
+ it_should_behave_like "type routing", "thumbnail"
84
+ end
85
+
86
+ context "knows how to get the base diff dir" do
87
+ When(:route) { router.diff_dir }
88
+ Then { route.should == expand(config.baseline_dir, "lance.com") }
89
+ end
90
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,8 @@ require 'rspec/given'
3
3
  require 'timecop'
4
4
  require 'pry'
5
5
 
6
+ require 'monet/config'
7
+
6
8
  VCR.configure do |c|
7
9
  c.cassette_library_dir = 'spec/cassettes'
8
10
  c.hook_into :webmock
data/spec/tmp/test.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke van der Hoeven
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -148,7 +148,8 @@ files:
148
148
  - lib/monet/config.rb
149
149
  - lib/monet/diff_strategy.rb
150
150
  - lib/monet/errors.rb
151
- - lib/monet/path_router.rb
151
+ - lib/monet/image.rb
152
+ - lib/monet/router.rb
152
153
  - lib/monet/tasks.rb
153
154
  - lib/monet/url_helpers.rb
154
155
  - lib/monet/version.rb
@@ -156,15 +157,26 @@ files:
156
157
  - spec/baseline_control_spec.rb
157
158
  - spec/capture_map_spec.rb
158
159
  - spec/capture_spec.rb
159
- - spec/cassettes/spider.yml
160
+ - spec/cassettes/spider-config.yml
161
+ - spec/cassettes/spider-map.yml
160
162
  - spec/compare_spec.rb
161
163
  - spec/config_spec.rb
162
164
  - spec/fixtures/base.png
165
+ - spec/fixtures/baselines/lance.com/.DS_Store
166
+ - spec/fixtures/baselines/lance.com/lance.com-1024-diff.png
167
+ - spec/fixtures/baselines/lance.com/lance.com-1024.png
168
+ - spec/fixtures/baselines/lance.com/lance.com|aboutus-1024.png
169
+ - spec/fixtures/captures/lance.com/lance.com-1024.png
163
170
  - spec/fixtures/diff.png
164
171
  - spec/fixtures/diff_size.png
165
172
  - spec/fixtures/same.png
166
- - spec/path_router_spec.rb
173
+ - spec/fixtures/spider-config.yaml
174
+ - spec/fixtures/thumbnails/lance.com/.DS_Store
175
+ - spec/fixtures/thumbnails/lance.com/lance.com-1024.png
176
+ - spec/image_spec.rb
177
+ - spec/router_spec.rb
167
178
  - spec/spec_helper.rb
179
+ - spec/tmp/test.png
168
180
  homepage: http://plukevdh.github.com/monet
169
181
  licenses: []
170
182
  metadata: {}
@@ -195,12 +207,24 @@ test_files:
195
207
  - spec/baseline_control_spec.rb
196
208
  - spec/capture_map_spec.rb
197
209
  - spec/capture_spec.rb
198
- - spec/cassettes/spider.yml
210
+ - spec/cassettes/spider-config.yml
211
+ - spec/cassettes/spider-map.yml
199
212
  - spec/compare_spec.rb
200
213
  - spec/config_spec.rb
201
214
  - spec/fixtures/base.png
215
+ - spec/fixtures/baselines/lance.com/.DS_Store
216
+ - spec/fixtures/baselines/lance.com/lance.com-1024-diff.png
217
+ - spec/fixtures/baselines/lance.com/lance.com-1024.png
218
+ - spec/fixtures/baselines/lance.com/lance.com|aboutus-1024.png
219
+ - spec/fixtures/captures/lance.com/lance.com-1024.png
202
220
  - spec/fixtures/diff.png
203
221
  - spec/fixtures/diff_size.png
204
222
  - spec/fixtures/same.png
205
- - spec/path_router_spec.rb
223
+ - spec/fixtures/spider-config.yaml
224
+ - spec/fixtures/thumbnails/lance.com/.DS_Store
225
+ - spec/fixtures/thumbnails/lance.com/lance.com-1024.png
226
+ - spec/image_spec.rb
227
+ - spec/router_spec.rb
206
228
  - spec/spec_helper.rb
229
+ - spec/tmp/test.png
230
+ has_rdoc:
@@ -1,70 +0,0 @@
1
- require 'monet/url_helpers'
2
-
3
- module Monet
4
- class PathRouter
5
- include URLHelpers
6
-
7
- def initialize(config)
8
- @base_url = parse_uri(config.base_url)
9
- @capture_path = config.capture_dir
10
- @baseline_path = config.baseline_dir
11
- @thumbnail_path = config.thumbnail_dir
12
- end
13
-
14
- def build_url(path)
15
- "#{@base_url}#{path}"
16
- end
17
-
18
- # takes a url, gives the image path
19
- def route_url(url, width="*")
20
- uri = parse_uri(url)
21
- route_url_path(uri.path, width)
22
- end
23
-
24
- # takes a url path, gives the image path
25
- def route_url_path(path, width="*")
26
- image_name(@capture_path, path, width)
27
- end
28
-
29
- def url_to_baseline(url, width)
30
- uri = parse_uri(url)
31
- url_path_to_baseline(uri.path, width)
32
- end
33
-
34
- def url_path_to_baseline(path, width)
35
- image_name(@baseline_path, path, width)
36
- end
37
-
38
- def capture_to_baseline(path)
39
- path.gsub(@capture_path, @baseline_path)
40
- end
41
-
42
- def to_thumbnail_path(path)
43
- image_path = path.split(File::SEPARATOR)[-2..-1].join(File::SEPARATOR)
44
- File.join @thumbnail_path, image_path
45
- end
46
-
47
- # takes a path, returns the URL used to generate the image
48
- def route_path(path)
49
- url = path.split("/").last
50
- path = url.split('|')[1..-1].join("/").gsub(/-\d+\.png/, "")
51
-
52
- "#{@base_url}/#{path}"
53
- end
54
-
55
- def host
56
- @base_url.host
57
- end
58
- alias :root_dir :host
59
-
60
- private
61
- def image_name(base_dir, path, width)
62
- name = normalize_path(path).gsub(/\//, '|')
63
- "#{base_dir}/#{host}/#{name}-#{width}.png"
64
- end
65
-
66
- def normalize_path(path)
67
- "#{host}#{path}"
68
- end
69
- end
70
- end