Skip to content

Commit

Permalink
Raise if cmd string returns empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Faloona committed Nov 28, 2011
1 parent a804dba commit da74a17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/indy/source.rb
Expand Up @@ -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
Expand Down Expand Up @@ -126,4 +126,4 @@ def load_data
end

end
end
end
11 changes: 8 additions & 3 deletions spec/source_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -82,4 +87,4 @@ class NotString;end

end

end
end

0 comments on commit da74a17

Please sign in to comment.