test/bin_runner_test.rb in boson-0.1.0 vs test/bin_runner_test.rb in boson-0.2.0

- old
+ new

@@ -53,12 +53,12 @@ BinRunner.expects(:define_autoloader) capture_stdout { start("-e", "p 1 + 1") }.should == "2\n" end test "global option takes value with whitespace" do - View.expects(:render).with(anything, {:sort => :lib, :fields => [:name, :lib]}) - start('commands', '-g', 'f=name,lib s=lib') + View.expects(:render).with(anything, {:vertical=>true, :fields => [:name, :lib]}, anything) + start('commands', '-g', 'f=name,lib vertical') end test "execute option errors are caught" do capture_stderr { start("-e", "raise 'blah'") }.should =~ /^Error:/ end @@ -67,13 +67,17 @@ capture_stdout { capture_stderr { start('commands','1','2','3') }.should =~ /'commands'.*incorrect/ } end test "failed subcommand prints error and not command not found" do BinRunner.expects(:execute_command).raises("bling") - capture_stderr { start("commands.blah") }.should =~ /Error: bling/ + capture_stderr { start("commands.to_s") }.should =~ /Error: bling/ end + test "nonexistant subcommand prints command not found" do + capture_stderr { start("to_s.bling") }.should =~ /'to_s.bling' not found/ + end + test "undiscovered command prints error" do BinRunner.expects(:load_command_by_index).returns(false) capture_stderr { start('blah') }.should =~ /Error.*not found/ end @@ -100,22 +104,34 @@ end end end context "load_command_by_index" do + def index(options={}) + Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0] == options[:load] + }.at_least(1).returns(!options[:fails]) + Index.expects(:write) + end + test "with index option, no existing index and core command updates index and prints index message" do - Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0] == Runner.all_libraries }.at_least(1) - Index.expects(:exists?).returns(false) - Index.expects(:write) + index :load=>Runner.all_libraries + Index.stubs(:exists?).returns(false) capture_stdout { start("--index", "libraries") }.should =~ /Generating index/ end test "with index option, existing index and core command updates incremental index" do - Index.expects(:changed_libraries).returns(['changed']) - Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0] == ['changed'] }.at_least(1) - Index.expects(:exists?).returns(true) - Index.expects(:write) - capture_stdout { start("--index", "libraries")}.should =~ /Indexing.*changed/ + index :load=>['changed'] + Index.stubs(:exists?).returns(true) + capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/ + end + + test "with index option, failed indexing prints error" do + index :load=>['changed'], :fails=>true + Index.stubs(:exists?).returns(true) + Manager.stubs(:failed_libraries).returns(['changed']) + capture_stderr { + capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/ + }.should =~ /Error:.*failed.*changed/ end test "with core command updates index and doesn't print index message" do Index.expects(:write) Boson.main_object.expects(:send).with('libraries') \ No newline at end of file