web_crawler 0.5.3 → 0.5.4

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,7 +2,7 @@ module WebCrawler
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -38,9 +38,10 @@ module WebCrawler::View
38
38
 
39
39
  def draw(output=nil)
40
40
  begin
41
- present_output(output).puts render
41
+ io = present_output(output)
42
+ io.puts render
42
43
  ensure
43
- output.close if output.respond_to? :close
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 = StringIO.new(output)
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: web_crawler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.3
5
+ version: 0.5.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Anton Sozontov