thumbnail_scraper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ module ThumbnailScraper
2
+ class NoValidThumbnail < StandardError
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module ThumbnailScraper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "thumbnail_scraper/version"
2
2
  require 'thumbnail_scraper/image'
3
3
  require 'thumbnail_scraper/http_receiver'
4
+ require 'thumbnail_scraper/no_valid_thumbnail'
4
5
 
5
6
  module ThumbnailScraper
6
7
  class ThumbnailScraper
@@ -29,7 +30,7 @@ module ThumbnailScraper
29
30
  def select_best_possible_image_to_scrap(images_urls)
30
31
  images = images_urls.map{|image_url| create_image(image_url)}
31
32
  valid_images = select_valid_images(images)
32
- return nil if valid_images.empty?
33
+ raise NoValidThumbnail.new if valid_images.empty?
33
34
  valid_images.max{|a, b| a.area <=> b.area}
34
35
  end
35
36
 
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ </head>
4
+ <body>
5
+ <p>No images</p>
6
+ </body>
7
+ </html>
8
+
9
+
@@ -49,4 +49,16 @@ describe ThumbnailScraper::ThumbnailScraper do
49
49
  end
50
50
  end
51
51
  end
52
+
53
+ context "for page without valid images" do
54
+ before :each do
55
+ stub_request(:get, "www.example.com/no_images.html").to_return(:body => asset_file("no_images.html"))
56
+ end
57
+
58
+ describe "#image_to_thumbnail_for_url" do
59
+ it "should raise NoValidThumbnail exception" do
60
+ expect{@thumbnail_scraper.image_to_thumbnail_for_url("http://www.example.com/no_images.html")}.to raise_error(ThumbnailScraper::NoValidThumbnail)
61
+ end
62
+ end
63
+ end
52
64
  end
@@ -97,9 +97,9 @@ module ThumbnailScraper
97
97
  end
98
98
 
99
99
  context "for all invalid images" do
100
- it "should be nil" do
100
+ it "should raise NoValidThumbnail error" do
101
101
  @thumbnail_scraper.should_receive(:select_valid_images).and_return([])
102
- @thumbnail_scraper.select_best_possible_image_to_scrap(@images_urls).should be_nil
102
+ expect{@thumbnail_scraper.select_best_possible_image_to_scrap(@images_urls)}.to raise_error(NoValidThumbnail)
103
103
  end
104
104
  end
105
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thumbnail_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-30 00:00:00.000000000 Z
13
+ date: 2012-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -108,6 +108,7 @@ files:
108
108
  - lib/thumbnail_scraper.rb
109
109
  - lib/thumbnail_scraper/http_receiver.rb
110
110
  - lib/thumbnail_scraper/image.rb
111
+ - lib/thumbnail_scraper/no_valid_thumbnail.rb
111
112
  - lib/thumbnail_scraper/version.rb
112
113
  - lib/thumbnail_scraper/webpage.rb
113
114
  - lib/thumbnail_scraper/with_smart_url.rb
@@ -116,6 +117,7 @@ files:
116
117
  - spec/sample_pages/images/kitty.jpg
117
118
  - spec/sample_pages/images/subcatalog/smallest.jpg
118
119
  - spec/sample_pages/img_src.html
120
+ - spec/sample_pages/no_images.html
119
121
  - spec/sample_pages/og_image.html
120
122
  - spec/thumbnail_scraper_helper.rb
121
123
  - spec/thumbnail_scraper_spec.rb
@@ -153,6 +155,7 @@ test_files:
153
155
  - spec/sample_pages/images/kitty.jpg
154
156
  - spec/sample_pages/images/subcatalog/smallest.jpg
155
157
  - spec/sample_pages/img_src.html
158
+ - spec/sample_pages/no_images.html
156
159
  - spec/sample_pages/og_image.html
157
160
  - spec/thumbnail_scraper_helper.rb
158
161
  - spec/thumbnail_scraper_spec.rb