/
document.rb
56 lines (46 loc) · 1.86 KB
/
document.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Treat::Specs::Entities
describe Treat::Entities::Document do
describe "Buildable" do
describe "#build" do
context "when supplied with a readable file name" do
it "opens the file and reads its " +
"content into a document" do
f = Treat.paths.spec +
'workers/examples/english/mathematicians/pythagoras.docx'
d = Treat::Entities::Document.build(f)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Pythagoras of Samos').should_not eql nil
end
end
context "when supplied with a url" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file" do
url = 'http://www.rubyinside.com/nethttp-cheat-sheet-2940.html'
d = Treat::Entities::Document.build(url)
d.format.should eql 'html'
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Rubyist').should_not eql nil
end
end
context "when supplied with a url with no file extension" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file, assuming " +
"the downloaded file to be in HTML format" do
url = 'http://www.economist.com/node/21552208'
d = Treat::Entities::Document.build(url)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Ronnie Lupe').should_not eql nil
end
end
context "when called with anything else than a " +
"readable file name or url" do
it "raises an exception" do
lambda do
Treat::Entities::Document.build('nonexistent')
end.should raise_error
end
end
end
end
end
end