|
1 | 1 | require File.dirname(__FILE__) + "/../spec_helper"
|
2 | 2 |
|
3 | 3 | describe AlchemyApi::TextExtraction do
|
4 |
| - shared_examples_for 'error handler' do |
5 |
| - before(:each) do |
6 |
| - @response = mock('response') |
7 |
| - @response.stub!(:code).and_return(200) |
8 |
| - @json = { |
9 |
| - 'status' => 'ERROR', |
10 |
| - 'url' => 'http://google.com', |
11 |
| - 'statusInfo' => nil # replace in each test. |
12 |
| - } |
13 |
| - end |
14 |
| - |
15 |
| - it "should raise an error if the API key is invalid" do |
16 |
| - @json['statusInfo'] = 'invalid-api-key' |
17 |
| - @response.stub!(:body).and_return(@json.to_json) |
18 |
| - lambda { |
19 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
20 |
| - }.should raise_error(AlchemyApi::InvalidApiKeyError) |
21 |
| - end |
22 |
| - |
23 |
| - it "should raise an error if the page is not retrievable" do |
24 |
| - @json['statusInfo'] = 'cannot-retrieve' |
25 |
| - @response.stub!(:body).and_return(@json.to_json) |
26 |
| - lambda { |
27 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
28 |
| - }.should raise_error(AlchemyApi::CannotRetrieveUrlError) |
29 |
| - end |
30 |
| - |
31 |
| - it "should raise an error if the page is not valid HTML" do |
32 |
| - @json['statusInfo'] = 'page-is-not-html' |
33 |
| - @response.stub!(:body).and_return(@json.to_json) |
34 |
| - lambda { |
35 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
36 |
| - }.should raise_error(AlchemyApi::PageIsNotValidHtmlError) |
37 |
| - end |
38 |
| - |
39 |
| - it "should raise an error if the sent HTML was not valid" do |
40 |
| - @json['statusInfo'] = 'invalid-html' |
41 |
| - @response.stub!(:body).and_return(@json.to_json) |
42 |
| - lambda { |
43 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
44 |
| - }.should raise_error(AlchemyApi::InvalidHtmlError) |
45 |
| - end |
46 |
| - |
47 |
| - it "should raise an error if the content exceeds the max limit" do |
48 |
| - @json['statusInfo'] = 'content-exceeds-size-limit' |
49 |
| - @response.stub!(:body).and_return(@json.to_json) |
50 |
| - lambda { |
51 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
52 |
| - }.should raise_error(AlchemyApi::ContentExceedsMaxLimitError) |
53 |
| - end |
54 |
| - |
55 |
| - it "should raise an error if the content cannot be retrieve due to redirection limit" do |
56 |
| - @json['statusInfo'] = 'cannot-retrieve:http-redirect-limit' |
57 |
| - @response.stub!(:body).and_return(@json.to_json) |
58 |
| - lambda { |
59 |
| - AlchemyApi::TextExtraction.send(@method, @response) |
60 |
| - }.should raise_error(AlchemyApi::RedirectionLimitError) |
61 |
| - end |
62 |
| - end |
63 |
| - |
64 | 4 | typhoeus_spec_cache('spec/cache/text_extraction/get_text_from_url') do |hydra|
|
65 | 5 | describe "#get_text_from_url" do
|
66 | 6 | it "should extract text" do
|
|
151 | 91 | end
|
152 | 92 | end
|
153 | 93 | end
|
154 |
| - |
155 |
| - |
156 |
| - describe "#get_title_from_url_handler" do |
157 |
| - describe "error handling" do |
158 |
| - before(:each) do |
159 |
| - @method = :get_title_from_url_handler |
160 |
| - end |
161 |
| - |
162 |
| - it_should_behave_like 'error handler' |
163 |
| - end |
164 |
| - end |
165 |
| - |
166 |
| - describe "#get_text_from_url_handler" do |
167 |
| - describe "error handling" do |
168 |
| - before(:each) do |
169 |
| - @method = :get_text_from_url_handler |
170 |
| - end |
171 |
| - it_should_behave_like 'error handler' |
172 |
| - end |
173 |
| - end |
174 | 94 | end
|
0 commit comments