From 4d27b63fedaab1f7b663a0fb597acc5814a20beb Mon Sep 17 00:00:00 2001 From: KUOKA Yusuke Date: Thu, 5 Dec 2013 20:57:55 +0900 Subject: [PATCH] Cover `parse_argv!` method in Observed::System --- lib/observed/application/oneshot.rb | 2 +- spec/oneshot_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/observed/application/oneshot.rb b/lib/observed/application/oneshot.rb index d00b65e..6bf9f5c 100644 --- a/lib/observed/application/oneshot.rb +++ b/lib/observed/application/oneshot.rb @@ -47,7 +47,7 @@ def parse_argv!(argv) opts.parse!(command_line_args) - if command_line_args.size != 1 + unless command_line_args.size == 1 || command_line_args.size == 2 fail InvalidArgumentError, "Invalid number of arguments #{command_line_args.size} where arguments are #{command_line_args}" end diff --git a/spec/oneshot_spec.rb b/spec/oneshot_spec.rb index c802020..ac4e1e9 100644 --- a/spec/oneshot_spec.rb +++ b/spec/oneshot_spec.rb @@ -52,7 +52,12 @@ def observe end end end - context 'with configuration directories' do - + describe '#parse_argv!' do + it 'parses ARGV like arrays and extracts Hash objects containing initialization parameters' do + argv = %w| -l logfile -d observed.rb foo1 | + params = Observed::Application::Oneshot.parse_argv! argv + expect(params).to eq({log_file: Pathname.new('logfile'), debug: true, config_file: 'observed.rb'}) + expect(argv).to eq(%w| foo1 |) + end end end