Skip to content

Commit

Permalink
ensure that yahoo xml parser binary works without options
Browse files Browse the repository at this point in the history
also, ensure that binary works when actually run from the command-line
  • Loading branch information
rick committed Oct 6, 2009
1 parent b79ce74 commit 572cc03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 9 additions & 2 deletions bin/process_yahoo_xml.rb
@@ -1,13 +1,20 @@
#!/usr/bin/env ruby

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'optparse'
require 'yahoo_xml_parser'

options = {}
OptionParser.new do |opts|
opts.on('-v', '--verbose', 'verbosely display progress and errors')
opts.on('-v', '--verbose', 'verbosely display progress and errors') do |v|
options[:verbose] = true
end

opts.on_tail('-h', '--help', 'show this message') do
puts opts
options[:help] = true
end
end.parse!

YahooXMLParser.new(:verbose => true) unless options[:help]
YahooXMLParser.new(options) unless options[:help]
exit(0)
20 changes: 16 additions & 4 deletions spec/bin/process_yahoo_xml_spec.rb
Expand Up @@ -12,10 +12,22 @@ def run_command
self.stub!(:puts)
end

it 'should run when no command-line arguments are specified' do
Object.send(:remove_const, :ARGV)
ARGV = []
lambda { run_command }.should.not.raise(Errno::ENOENT)
describe 'when no command-line arguments are specified' do
it 'should run successfully' do
Object.send(:remove_const, :ARGV)
ARGV = []
lambda { run_command }.should.not.raise(Errno::ENOENT)
end

it 'should create a yahoo xml parser' do
YahooXMLParser.should.receive(:new).and_return(@parser)
run_command
end

it "should pass an empty set of options" do
YahooXMLParser.should.receive(:new).with({}).and_return(@parser)
run_command
end
end

describe "when -v is specified on the command-line" do
Expand Down

0 comments on commit 572cc03

Please sign in to comment.