monet 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/spec/capture_spec.rb CHANGED
@@ -1,12 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'chunky_png'
4
+ require 'monet'
4
5
  require 'monet/capture'
5
6
 
6
7
  describe Monet::Capture do
7
8
  Given(:path) { File.expand_path './spec/tmp/output' }
8
- Given(:url) { "http://google.com" }
9
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: url) }
9
+ Given(:url) { "https://google.com" }
10
+ Given(:capture_agent) { create_capture(config) }
11
+
12
+ def create_capture(config)
13
+ Monet::Capture.new config
14
+ end
10
15
 
11
16
  after(:all) do
12
17
  Dir.glob("#{path}/**/*.png").each do |file|
@@ -14,57 +19,78 @@ describe Monet::Capture do
14
19
  end
15
20
  end
16
21
 
17
- context "can pass config" do
18
- context "as a hash" do
19
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: url) }
20
- When(:config) { capture_agent.instance_variable_get :@config }
21
- Then { config.should be_a(Monet::Config) }
22
- Then { config.capture_dir.should == path }
22
+ context "simple config" do
23
+ Given(:config) do
24
+ Monet::Config.config do |c|
25
+ c.base_url = "https://google.com"
26
+ c.capture_dir = File.join(path, "captures")
27
+ c.thumbnail_dir = File.join(path, "thumbnails")
28
+ end
29
+ end
30
+
31
+ context "can capture a path" do
32
+ When { capture_agent.capture(url, "#{path}/google.com/google.com-280.png") }
33
+ Then { File.exist?("#{path}/google.com/google.com-280.png").should be_true }
23
34
  end
24
35
 
25
- context "as a Monet::Config" do
26
- Given(:config) { Monet::Config.new(capture_dir: path, base_url: url) }
27
- Given(:capture_agent) { Monet::Capture.new(config) }
28
- When(:final) { capture_agent.instance_variable_get :@config }
29
- Then { final.should be_a(Monet::Config) }
30
- Then { final.capture_dir.should == path }
36
+ context "can capture an image object" do
37
+ Given(:img) { Monet::Image.new(File.join(path, "google.com", "google.com|chrome-1024.png")) }
38
+ When { capture_agent.capture("#{url}/chrome", img) }
39
+ Then { File.exist?("#{path}/google.com/google.com|chrome-1024.png").should be_true }
31
40
  end
32
41
  end
33
42
 
34
43
  context "converts name properly" do
35
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: url, dimensions: [900]) }
36
- When { capture_agent.capture("/") }
37
- Then { File.exist?("#{path}/google.com/google.com|-900.png").should be_true }
44
+ Given(:config) { Monet::Config.config {|c|
45
+ c.base_url = url
46
+ c.capture_dir = path
47
+ c.dimensions = [900]
48
+ c.map = ["/"]
49
+ }}
50
+ When { capture_agent.capture_all }
51
+ Then { File.exist?("#{path}/google.com/google.com-900.png").should be_true }
38
52
  end
39
53
 
40
54
  context "captures all dimensions requested" do
41
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: url, dimensions: [900, 1400]) }
42
- When { capture_agent.capture("/") }
43
- Then { File.exist?("#{path}/google.com/google.com|-900.png").should be_true }
44
- Then { File.exist?("#{path}/google.com/google.com|-1400.png").should be_true }
55
+ Given(:config) { Monet::Config.config {|c|
56
+ c.base_url = url
57
+ c.capture_dir = path
58
+ c.dimensions = [900, 1400]
59
+ c.map = ["/"]
60
+ }}
61
+ When { capture_agent.capture_all }
62
+ Then { File.exist?("#{path}/google.com/google.com-900.png").should be_true }
63
+ Then { File.exist?("#{path}/google.com/google.com-1400.png").should be_true }
45
64
  end
46
65
 
47
66
  context "captures defualt size as 1024" do
48
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: "http://www.facebook.com") }
49
- When { capture_agent.capture('/') }
50
- Then { File.exist?("#{path}/www.facebook.com/www.facebook.com|-1024.png").should be_true }
67
+ Given(:config) { Monet::Config.config {|c|
68
+ c.base_url = "https://www.facebook.com"
69
+ c.capture_dir = path
70
+ c.map = ["/"]
71
+ }}
72
+ When { capture_agent.capture_all }
73
+ Then { File.exist?("#{path}/www.facebook.com/www.facebook.com-1024.png").should be_true }
51
74
  end
52
75
 
53
- context "captured" do
54
- Given(:thumb_path) { "#{path}/thumbnails/www.spider.io/www.spider.io|-1024.png" }
55
- Given(:capture_agent) { Monet::Capture.new(capture_dir: path,
56
- thumbnail_dir: File.join(path, "thumbnails"),
57
- base_url: "http://www.spider.io",
58
- thumbnail: true)
76
+ context "capturing" do
77
+ Given(:thumb_path) { "#{path}/thumbnails/www.spider.io/www.spider.io-1024.png" }
78
+ Given(:config) { Monet::Config.config do |c|
79
+ c.capture_dir = path
80
+ c.thumbnail_dir = File.join(path, "thumbnails")
81
+ c.base_url = "https://www.spider.io"
82
+ c.thumbnail = true
83
+ c.map = ["/"]
84
+ end
59
85
  }
60
- When { capture_agent.capture('/') }
86
+ When { capture_agent.capture_all }
61
87
 
62
88
  context "can thumbnail an image" do
63
- Then { File.exist?("#{path}/www.spider.io/www.spider.io|-1024.png").should be_true }
89
+ Then { File.exist?("#{path}/www.spider.io/www.spider.io-1024.png").should be_true }
64
90
  And { File.exist?(thumb_path).should be_true }
65
91
  end
66
92
 
67
- context "thumb is 200x200" do
93
+ context "thumbnail sizes to 200x200" do
68
94
  When(:thumb) { ChunkyPNG::Image.from_file(thumb_path) }
69
95
  Then { thumb.width.should == 200 }
70
96
  And { thumb.height.should == 200 }