link_thumbnailer 0.0.2 → 0.0.3

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.
@@ -2,98 +2,137 @@ require 'spec_helper'
2
2
 
3
3
  describe LinkThumbnailer do
4
4
 
5
+ let(:og_example) { File.open(File.dirname(__FILE__) + '/examples/og_example.html').read() }
6
+
7
+ it { should respond_to :configuration }
5
8
  it { should respond_to :configure }
9
+ it { should respond_to :config }
6
10
  it { should respond_to :generate }
7
11
 
8
- it { should respond_to :mandatory_attributes }
9
- it { should respond_to :strict }
10
- it { should respond_to :redirect_limit }
11
- it { should respond_to :blacklist_urls }
12
- it { should respond_to :max }
13
- it { should respond_to :top }
12
+ describe "configuration" do
14
13
 
15
- context "default values" do
14
+ context "#configure" do
16
15
 
17
- context ".mandatory_attributes" do
16
+ it "should yields self" do
17
+ LinkThumbnailer.should_receive(:configure).and_yield(LinkThumbnailer)
18
+ LinkThumbnailer.configure {|config|}
19
+ end
18
20
 
19
- specify { LinkThumbnailer.mandatory_attributes.should eq(%w(url title images)) }
21
+ before do
22
+ LinkThumbnailer.configure {|config|
23
+ config.mandatory_attributes = %w(foo bar)
24
+ config.strict = false
25
+ config.redirect_limit = 5
26
+ config.blacklist_urls = []
27
+ config.limit = 5
28
+ config.top = 10
29
+ }
30
+ end
31
+
32
+ after do
33
+ LinkThumbnailer.configuration = nil
34
+ end
35
+
36
+ specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(foo bar)) }
37
+ specify { LinkThumbnailer.configuration.strict.should be_false }
38
+ specify { LinkThumbnailer.configuration.redirect_limit.should eq(5) }
39
+ specify { LinkThumbnailer.configuration.blacklist_urls.should eq([]) }
40
+ specify { LinkThumbnailer.configuration.limit.should eq(5) }
41
+ specify { LinkThumbnailer.configuration.top.should eq(10) }
20
42
 
21
43
  end
22
44
 
23
- context ".strict" do
45
+ end
24
46
 
25
- specify { LinkThumbnailer.strict.should be_true }
47
+ context "default values" do
26
48
 
49
+ before do
50
+ LinkThumbnailer.configure {|config| }
27
51
  end
28
52
 
29
- context ".redirect_limit" do
53
+ specify { LinkThumbnailer.configuration.mandatory_attributes.should eq(%w(url title images)) }
54
+ specify { LinkThumbnailer.configuration.strict.should be_true }
55
+ specify { LinkThumbnailer.configuration.redirect_limit.should eq(3) }
56
+ specify { LinkThumbnailer.configuration.blacklist_urls.should eq([
57
+ %r{^http://ad\.doubleclick\.net/},
58
+ %r{^http://b\.scorecardresearch\.com/},
59
+ %r{^http://pixel\.quantserve\.com/},
60
+ %r{^http://s7\.addthis\.com/}
61
+ ]) }
62
+ specify { LinkThumbnailer.configuration.limit.should eq(10) }
63
+ specify { LinkThumbnailer.configuration.top.should eq(5) }
30
64
 
31
- specify { LinkThumbnailer.redirect_limit.should eq(3) }
65
+ end
32
66
 
33
- end
67
+ context ".generate" do
34
68
 
35
- context ".blacklist_urls" do
69
+ context "with valid arguments" do
36
70
 
37
- specify { LinkThumbnailer.blacklist_urls.should eq([
38
- %r{^http://ad\.doubleclick\.net/},
39
- %r{^http://b\.scorecardresearch\.com/},
40
- %r{^http://pixel\.quantserve\.com/},
41
- %r{^http://s7\.addthis\.com/}
42
- ]) }
71
+ context "and options" do
43
72
 
44
- end
73
+ it "should set top option" do
74
+ expect { LinkThumbnailer.generate('foo', :top => 20).to change(LinkThumbnailer.configuration.top).from(5).to(20) }
75
+ end
45
76
 
46
- context ".max" do
77
+ it "should set limit option" do
78
+ expect { LinkThumbnailer.generate('foo', :limit => 20).to change(LinkThumbnailer.configuration.top).from(10).to(20) }
79
+ end
47
80
 
48
- specify { LinkThumbnailer.max.should eq(10) }
81
+ end
49
82
 
50
- end
83
+ context "when strict" do
51
84
 
52
- context ".top" do
85
+ context "and not valid" do
53
86
 
54
- specify { LinkThumbnailer.top.should eq(5) }
87
+ subject { LinkThumbnailer.generate('foo') }
55
88
 
56
- end
89
+ it { should be_nil }
57
90
 
58
- end
91
+ end
59
92
 
60
- context ".configure" do
93
+ context "and valid" do
61
94
 
62
- it "should yields self" do
63
- LinkThumbnailer.should_receive(:configure).and_yield(LinkThumbnailer)
64
- LinkThumbnailer.configure {|config|}
65
- end
95
+ before do
96
+ stub_request(:get, "http://zerply.com/").to_return(:status => 200, :body => og_example, :headers => {})
97
+ end
66
98
 
67
- context "attributes" do
99
+ subject { LinkThumbnailer.generate('http://zerply.com') }
100
+
101
+ it { should_not be_nil }
102
+ it { subject.valid?.should be_true }
103
+
104
+ end
68
105
 
69
- before do
70
- LinkThumbnailer.configure {|config|
71
- config.mandatory_attributes = %w(foo bar)
72
- config.strict = false
73
- config.redirect_limit = 5
74
- config.blacklist_urls = []
75
- config.max = 5
76
- config.top = 10
77
- }
78
106
  end
79
107
 
80
- specify { LinkThumbnailer.mandatory_attributes.should eq(%w(foo bar)) }
81
- specify { LinkThumbnailer.strict.should be_false }
82
- specify { LinkThumbnailer.redirect_limit.should eq(5) }
83
- specify { LinkThumbnailer.blacklist_urls.should eq([]) }
84
- specify { LinkThumbnailer.max.should eq(5) }
85
- specify { LinkThumbnailer.top.should eq(10) }
108
+ context "when not strict" do
86
109
 
87
- end
110
+ before do
111
+ LinkThumbnailer.configure {|config| config.strict = false}
112
+ end
88
113
 
89
- end
114
+ context "and not valid" do
90
115
 
91
- context ".generate" do
116
+ subject { LinkThumbnailer.generate('foo') }
117
+
118
+ it { should_not be_nil }
119
+ it { subject.valid?.should be_true }
120
+
121
+ end
122
+
123
+ context "and valid" do
124
+
125
+ before do
126
+ stub_request(:get, "http://zerply.com/").to_return(:status => 200, :body => og_example, :headers => {})
127
+ end
128
+
129
+ subject { LinkThumbnailer.generate('http://zerply.com') }
130
+
131
+ it { should_not be_nil }
132
+ it { subject.valid?.should be_true }
92
133
 
93
- context "with invalid arguments" do
134
+ end
94
135
 
95
- it "should return nil" do
96
- LinkThumbnailer.generate('foo').should be_nil
97
136
  end
98
137
 
99
138
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rails'
2
2
  require 'rspec'
3
+ require 'webmock/rspec'
4
+
3
5
  require 'link_thumbnailer'
4
6
 
5
7
  RSpec.configure do |config|
6
-
7
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-19 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -83,7 +83,7 @@ dependencies:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
85
  version: 2.11.0
86
- type: :runtime
86
+ type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 2.11.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.10
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: 1.8.10
94
110
  description: Ruby gem generating thumbnail images from a given URL.
95
111
  email:
96
112
  - pierrelouis.gottfrois@gmail.com
@@ -100,6 +116,7 @@ extra_rdoc_files: []
100
116
  files:
101
117
  - .gitignore
102
118
  - .rspec
119
+ - CHANGELOG.md
103
120
  - Gemfile
104
121
  - LICENSE
105
122
  - README.md
@@ -107,6 +124,7 @@ files:
107
124
  - lib/generators/link_thumbnailer/install_generator.rb
108
125
  - lib/generators/templates/initializer.rb
109
126
  - lib/link_thumbnailer.rb
127
+ - lib/link_thumbnailer/config.rb
110
128
  - lib/link_thumbnailer/doc.rb
111
129
  - lib/link_thumbnailer/doc_parser.rb
112
130
  - lib/link_thumbnailer/fetcher.rb
@@ -118,6 +136,7 @@ files:
118
136
  - lib/link_thumbnailer/version.rb
119
137
  - lib/link_thumbnailer/web_image.rb
120
138
  - link_thumbnailer.gemspec
139
+ - spec/examples/og_example.html
121
140
  - spec/link_thumbnailer_spec.rb
122
141
  - spec/spec_helper.rb
123
142
  homepage: https://github.com/gottfrois/link_thumbnailer
@@ -146,5 +165,6 @@ specification_version: 3
146
165
  summary: Ruby gem ranking images from a given URL returning an object containing images
147
166
  and website informations.
148
167
  test_files:
168
+ - spec/examples/og_example.html
149
169
  - spec/link_thumbnailer_spec.rb
150
170
  - spec/spec_helper.rb