test/bin_runner_test.rb in boson-0.2.5 vs test/bin_runner_test.rb in boson-0.3.0

- old
+ new

@@ -17,11 +17,11 @@ it "no arguments prints usage" do capture_stdout { start }.should =~ /^boson/ end it "invalid option value prints error" do - capture_stderr { start("-l") }.should =~ /Error:/ + aborts_with(/Error: no value/) { start("-l") } end it "help option but no arguments prints usage" do capture_stdout { start '-h' }.should =~ /^boson/ end @@ -34,21 +34,22 @@ Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0][0] == 'blah'}.times(2) BinRunner.stubs(:execute_command) start('-l', 'blah', 'libraries') end - # it "console option starts irb" do - # ConsoleRunner.expects(:start) - # Util.expects(:which).returns("/usr/bin/irb") - # Kernel.expects(:load).with("/usr/bin/irb") - # start("--console") - # end + it "console option starts irb" do + ConsoleRunner.expects(:start) + Util.expects(:which).returns("/usr/bin/irb") + ConsoleRunner.expects(:load_repl).with("/usr/bin/irb") + start("--console") + end it "console option but no irb found prints error" do ConsoleRunner.expects(:start) Util.expects(:which).returns(nil) - capture_stderr { start("--console") }.should =~ /Console not found/ + ConsoleRunner.expects(:abort).with {|arg| arg[/Console not found/] } + start '--console' end it "execute option executes string" do BinRunner.expects(:define_autoloader) capture_stdout { start("-e", "p 1 + 1") }.should == "2\n" @@ -57,38 +58,52 @@ it "global option takes value with whitespace" do View.expects(:render).with {|*args| args[1][:fields] = %w{f1 f2} } start('commands', '-f', 'f1, f2') end + it "debug option sets Runner.debug" do + View.expects(:render) + start('-d', 'commands') + Runner.debug.should == true + Runner.debug = nil + end + + it "ruby_debug option sets $DEBUG" do + View.expects(:render) + start('-D', 'commands') + $DEBUG.should == true + $DEBUG = nil + end + it "execute option errors are caught" do - capture_stderr { start("-e", "raise 'blah'") }.should =~ /^Error:/ + aborts_with(/^Error:/) { start("-e", "raise 'blah'") } end it "option command and too many arguments prints error" do capture_stdout { - capture_stderr { start('commands','1','2','3') }.should =~ /'commands'.*incorrect/ + aborts_with(/'commands'.*incorrect/) { start('commands','1','2','3') } } end it "normal command and too many arguments prints error" do capture_stdout { - capture_stderr { start('render') }.should =~ /'render'.*incorrect/ + aborts_with(/'render'.*incorrect/) { start('render') } } end it "failed subcommand prints error and not command not found" do BinRunner.expects(:execute_command).raises("bling") - capture_stderr { start("commands.to_s") }.should =~ /Error: bling/ + aborts_with(/Error: bling/) { start("commands.to_s") } end it "nonexistant subcommand prints command not found" do - capture_stderr { start("to_s.bling") }.should =~ /'to_s.bling' not found/ + aborts_with(/'to_s.bling' not found/) { start("to_s.bling") } end it "undiscovered command prints error" do - BinRunner.expects(:autoload_command).returns(false) - capture_stderr { start('blah') }.should =~ /Error.*not found/ + BinRunner.expects(:autoload_command).returns(false) + aborts_with(/Error.*not found/) { start 'blah' } end it "basic command executes" do BinRunner.expects(:init).returns(true) BinRunner.stubs(:render_output) @@ -106,11 +121,11 @@ it "bin_defaults config loads by default" do defaults = Runner.default_libraries + ['yo'] with_config(:bin_defaults=>['yo']) do Manager.expects(:load).with {|*args| args[0] == defaults } - capture_stderr { start 'blah' } + aborts_with(/blah/) { start 'blah' } end end end describe "autoload_command" do @@ -149,10 +164,10 @@ it "with non-core command not finding library, does update index" do Index.expects(:find_library).returns(nil, 'sweet_lib') Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1) Index.indexes[0].expects(:update).returns(true) - capture_stderr { start("sweet") }.should =~ /sweet/ + aborts_with(/sweet/) { start 'sweet' } end end describe "render_output" do before { Scientist.rendered = false; BinRunner.instance_eval "@options = {}" } \ No newline at end of file