Permalink
Browse files

Raise if cmd string returns empty string

  • Loading branch information...
1 parent a804dba commit da74a17a9d61e7be1a9822dc425e0a4d27098685 @bfaloona committed Nov 28, 2011
Showing with 10 additions and 5 deletions.
  1. +2 −2 lib/indy/source.rb
  2. +8 −3 spec/source_spec.rb
View
4 lib/indy/source.rb
@@ -88,7 +88,7 @@ def open(time_search=nil)
def exec_command(command_string)
begin
io = IO.popen(command_string)
- return nil if io.eof?
+ raise Indy::Source::Invalid, "No data returned from command string execution" if io.eof?
rescue
nil
end
@@ -126,4 +126,4 @@ def load_data
end
end
-end
+end
View
11 spec/source_spec.rb
@@ -17,6 +17,11 @@ class NotString;end
lambda{ Source.new(NotString.new) }.should raise_error( Indy::Source::Invalid )
end
+ it "should raise if #execute_command returns empty string" do
+ IO.stub!(:popen).and_return('')
+ lambda{ Source.new(:cmd => 'a faux command').open }.should raise_error(Indy::Source::Invalid)
+ end
+
it "should return Indy::Source object" do
Source.new('logdata').class.should == Indy::Source
end
@@ -39,15 +44,15 @@ class NotString;end
end
context "instance" do
-
+
before(:each) do
log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
"2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
"2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."
].join("\n")
@source = Source.new(log)
end
-
+
it "should return StringIO from :open" do
@source.open.class.should == StringIO
end
@@ -82,4 +87,4 @@ class NotString;end
end
-end
+end

0 comments on commit da74a17

Please sign in to comment.