web_crawler 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/web_crawler/version.rb +1 -1
- data/lib/web_crawler/view.rb +4 -3
- data/spec/web_crawler/view_spec.rb +15 -3
- metadata +1 -1
data/lib/web_crawler/version.rb
CHANGED
data/lib/web_crawler/view.rb
CHANGED
@@ -38,9 +38,10 @@ module WebCrawler::View
|
|
38
38
|
|
39
39
|
def draw(output=nil)
|
40
40
|
begin
|
41
|
-
present_output(output)
|
41
|
+
io = present_output(output)
|
42
|
+
io.puts render
|
42
43
|
ensure
|
43
|
-
|
44
|
+
io.close if io.respond_to? :close
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -62,7 +63,7 @@ module WebCrawler::View
|
|
62
63
|
|
63
64
|
def output_to_file(filename)
|
64
65
|
path = Pathname.new(filename)
|
65
|
-
|
66
|
+
|
66
67
|
unless path.dirname.exist?
|
67
68
|
logger.info("#{path.dirname} not exist, try to create...")
|
68
69
|
path.dirname.mkpath
|
@@ -15,8 +15,8 @@ describe WebCrawler::View::Csv do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should render input array to csv string with options" do
|
18
|
-
described_class.new(input, headers: [:title, :url, :author], csv: {col_sep: ";"}).render.should == "title;url;author\n1;2;3\nstring;\"other string\n\"\n"
|
19
|
-
described_class.new(input, headers: [:title, :url, :author], csv: {row_sep: "\n\n"}).render.should == "title,url,author\n\n1,2,3\n\nstring,\"other string\n\"\n\n"
|
18
|
+
described_class.new(input, headers: [:title, :url, :author], csv: { col_sep: ";" }).render.should == "title;url;author\n1;2;3\nstring;\"other string\n\"\n"
|
19
|
+
described_class.new(input, headers: [:title, :url, :author], csv: { row_sep: "\n\n" }).render.should == "title,url,author\n\n1,2,3\n\nstring,\"other string\n\"\n\n"
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -88,8 +88,20 @@ describe WebCrawler::View do
|
|
88
88
|
|
89
89
|
it "should draw view to custom output" do
|
90
90
|
output = ""
|
91
|
-
io
|
91
|
+
io = StringIO.new(output)
|
92
92
|
WebCrawler::View.factory('json', [[1, 2, 3]]).draw(io)
|
93
93
|
output.should == "[[1,2,3]]\n"
|
94
94
|
end
|
95
|
+
|
96
|
+
it "should draw view to file" do
|
97
|
+
output = "/tmp/rspec_temp_file.tmp"
|
98
|
+
WebCrawler::View.factory('json', [[1, 2, 3]], {'output' => output}).draw
|
99
|
+
File.read(output).should == "[[1,2,3]]\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should draw view to /dev/null" do
|
103
|
+
output = "/dev/null"
|
104
|
+
WebCrawler::View.factory('json', [[1, 2, 3]], {'output' => output}).draw
|
105
|
+
File.read(output).should be_empty
|
106
|
+
end
|
95
107
|
end
|