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

- old
+ new

@@ -107,51 +107,92 @@ 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) + Index.indexes[0].expects(:write) end test "with index option, no existing index and core command updates index and prints index message" do index :load=>Runner.all_libraries - Index.stubs(:exists?).returns(false) + Index.indexes[0].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 :load=>['changed'] - Index.stubs(:exists?).returns(true) + Index.indexes[0].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) + Index.indexes[0].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) + Index.indexes[0].expects(:write) Boson.main_object.expects(:send).with('libraries') capture_stdout { start 'libraries'}.should_not =~ /index/i end test "with non-core command finding library doesn't update index" do Index.expects(:find_library).returns('sweet_lib') Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1) - Index.expects(:update).never + Index.indexes[0].expects(:update).never capture_stderr { start("sweet") }.should =~ /sweet/ end test "with non-core command not finding library, does update index" do Index.expects(:find_library).returns(nil, 'sweet_lib').times(2) Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1) - Index.expects(:update).returns(true) + Index.indexes[0].expects(:update).returns(true) capture_stderr { start("sweet") }.should =~ /sweet/ + end + end + + context "render_output" do + before(:each) { Scientist.rendered = false; BinRunner.instance_eval "@options = {}" } + + test "doesn't render when nil, false or true" do + View.expects(:render).never + [nil, false, true].each do |e| + BinRunner.render_output e + end + end + + test "doesn't render when rendered with Scientist" do + Scientist.rendered = true + View.expects(:render).never + BinRunner.render_output 'blah' + end + + test "render with puts when non-string" do + View.expects(:render).with('dude', {:method => 'puts'}) + BinRunner.render_output 'dude' + end + + test "renders with inspect when non-array and non-string" do + [{:a=>true}, :ok].each do |e| + View.expects(:puts).with(e.inspect) + BinRunner.render_output e + end + end + + test "renders with inspect when Scientist rendering toggled off with :render" do + Scientist.global_options = {:render=>true} + View.expects(:puts).with([1,2].inspect) + BinRunner.render_output [1,2] + Scientist.global_options = nil + end + + test "renders with hirb when array" do + View.expects(:render_object) + BinRunner.render_output [1,2,3] end end test "parse_args only translates options before command" do BinRunner.parse_args(['-v', 'com', '-v']).should == ["com", {:verbose=>true}, ['-v']] \ No newline at end of file