test/scientist_test.rb in boson-0.2.1 vs test/scientist_test.rb in boson-0.2.2

- old
+ new

@@ -23,10 +23,11 @@ end EOF end @opt_cmd = Object.new.extend Blah } + after(:all) { Runner.in_shell = false } def command(hash, args) hash = {:name=>'blah', :lib=>'bling', :options=>{:force=>:boolean, :level=>2}}.merge(hash) @cmd = Command.new hash @cmd.instance_variable_set("@file_parsed_args", true) if hash[:file_parsed_args] @@ -129,22 +130,17 @@ context "prints error" do test "with option error" do capture_stderr { command_with_args('a1 -l') }.should =~ /Error.*level/ end - test "with unexpected error in translation" do - Scientist.expects(:option_command).raises("unexpected") - capture_stderr { command_with_args('a1') }.should =~ /Error.*unexpected/ - end - test "with unexpected error in render" do Scientist.expects(:render?).raises("unexpected") capture_stderr { command_with_args('a1') }.should =~ /Error.*unexpected/ end test "with no argument defined for options" do - assert_error(ArgumentError, '2 for 1') { command({:args=>1}, 'ok') } + assert_error(OptionCommand::CommandArgumentError, '2 for 1') { command({:args=>1}, 'ok') } end end test "translates stringfied args + options starting at second arg" do command_with_arg_defaults(1, 'nada -l3').should == [1, "nada", {:level=>3}] @@ -168,21 +164,21 @@ test "with pretend option prints arguments and returns early" do Scientist.expects(:render_or_raw).never capture_stdout { command_with_args("-p ok") } =~ /Arguments.*ok/ end - test "with not enough args raises ArgumentError" do - args = [ArgumentError, '0 for 1'] + test "with not enough args raises CommandArgumentError" do + args = [OptionCommand::CommandArgumentError, '0 for 1'] assert_error(*args) { command_with_args } assert_error(*args) { command_with_args '' } assert_error(*args) { command_with_arg_size } assert_error(*args) { command_with_arg_size '' } end - test "with too many args raises ArgumentError" do + test "with too many args raises CommandArgumentError" do args3 = [ArgumentError, '3 for 2'] - args4 = [ArgumentError, '4 for 2'] + args4 = [OptionCommand::CommandArgumentError, '4 for 2'] assert_error(*args3) { command_with_args 1,2,3 } assert_error(*args4) { command_with_args '1 2 3' } assert_error(*args3) { command_with_arg_size 1,2,3 } assert_error(*args4) { command_with_arg_size '1 2 3' } end @@ -250,11 +246,11 @@ test "parses normally from irb" do command(@cmd_attributes, '-f --level=3').should == {:level=>3, :force=>true} end test "parses normally from cmdline" do - Boson.expects(:const_defined?).returns true + Runner.expects(:in_shell?).times(2).returns true command(@cmd_attributes, ['--force', '--level=3']).should == {:level=>3, :force=>true} end test "parses no arguments normally" do command(@cmd_attributes, '').should == {:level=>2} @@ -267,11 +263,11 @@ test "prepends correctly from irb" do command(@cmd_attributes, '3 -f').should == {:level=>3, :force=>true} end test "prepends correctly from cmdline" do - Boson.expects(:const_defined?).returns true + Runner.expects(:in_shell?).times(2).returns true command(@cmd_attributes, ['3','-f']).should == {:level=>3, :force=>true} end end test "optionless command renders" do @@ -305,24 +301,33 @@ local_and_global(*args).should == [{:foo=>true}, {:dude=>true}] @non_opts.should == @expected_non_opts[i] end end + test "delete_options deletes global options" do + local_and_global('--delete_options=r,p -rp -f').should == + [{:foo=>true}, {:delete_options=>["r", "p"]}] + end + test "global option after local one is invalid" do args_arr = ['-f --dude', '-f doh --dude', '-f --dude doh', [:doh, '-f --dude'] ] args_arr.each_with_index do |args, i| capture_stderr { local_and_global(*args).should == [{:foo=>true}, {}] @non_opts.should == @expected_non_opts[i] }.should =~ /invalid.*dude/ end end - test "--global option adds additional global options" do - local_and_global('-g=d -d').should == [{:do=>true}, {:dude=>true, :global=>'d'}] - local_and_global('-g "r dude" -d').should == [{:do=>true}, - {:global=>"r dude", :dude=>true, :render=>true}] + test "global option after local one and -" do + local_and_global("doh -r -f - --dude").should == [{:foo=>true}, {:dude=>true, :render=>true}] end - end + test "no options parsed after --" do + local_and_global('doh -f -- -r').should == [{:foo=>true}, {}] + local_and_global('doh -- -r -f').should == [{}, {}] + local_and_global('-- -r -f').should == [{}, {}] + local_and_global('doh -r -- -f').should == [{}, {:render=>true}] + end + end end end