boson 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,9 +34,10 @@ module Boson
34
34
  # Handles all Scientist errors.
35
35
  class Error < StandardError; end
36
36
 
37
- attr_accessor :global_options, :rendered
37
+ attr_accessor :global_options, :rendered, :render
38
38
  @no_option_commands ||= []
39
39
  @option_commands ||= {}
40
+ @object_methods = {}
40
41
 
41
42
  # Redefines an object's method with a Command of the same name.
42
43
  def redefine_command(obj, command)
@@ -45,6 +46,8 @@ module Boson
45
46
  [command.name, command.alias].compact.each {|e|
46
47
  obj.instance_eval("class<<self;self;end").send(:define_method, e, cmd_block)
47
48
  }
49
+ rescue Error
50
+ $stderr.puts "Error: #{$!.message}"
48
51
  end
49
52
 
50
53
  # A wrapper around redefine_command that doesn't depend on a Command object. Rather you
@@ -72,12 +75,23 @@ module Boson
72
75
 
73
76
  # The actual method which redefines a command's original method
74
77
  def redefine_command_block(obj, command)
78
+ object_methods(obj)[command.name] ||= begin
79
+ obj.method(command.name)
80
+ rescue NameError
81
+ raise Error, "No method exists to redefine command '#{command.name}'."
82
+ end
75
83
  lambda {|*args|
76
- Boson::Scientist.translate_and_render(obj, command, args) {|args| super(*args) }
84
+ Scientist.translate_and_render(obj, command, args) {|args|
85
+ Scientist.object_methods(obj)[command.name].call(*args)
86
+ }
77
87
  }
78
88
  end
79
89
 
80
90
  #:stopdoc:
91
+ def object_methods(obj)
92
+ @object_methods[obj] ||= {}
93
+ end
94
+
81
95
  def option_command(cmd=@command)
82
96
  @option_commands[cmd] ||= OptionCommand.new(cmd)
83
97
  end
@@ -144,7 +158,7 @@ module Boson
144
158
  end
145
159
 
146
160
  def render_or_raw(result)
147
- if (@rendered = render?)
161
+ if (@rendered = can_render?)
148
162
  if @global_options.key?(:class) || @global_options.key?(:method)
149
163
  result = Pipe.scientist_process(result, @global_options, :config=>@command.config, :args=>@args, :options=>@current_options)
150
164
  end
@@ -156,7 +170,11 @@ module Boson
156
170
  raise Error, $!.message, $!.backtrace
157
171
  end
158
172
 
159
- def render?
173
+ def can_render?
174
+ render.nil? ? command_renders? : render
175
+ end
176
+
177
+ def command_renders?
160
178
  (!!@command.render_options ^ @global_options[:render]) && !Pipe.any_no_render_pipes?(@global_options)
161
179
  end
162
180
  #:startdoc:
data/lib/boson/util.rb CHANGED
@@ -35,7 +35,7 @@ module Boson
35
35
  # Valid options and possible returned keys are :methods, :object_methods, :modules, :gems.
36
36
  def detect(options={}, &block)
37
37
  options = {:methods=>true, :object_methods=>true}.merge!(options)
38
- original_gems = Gem.loaded_specs.keys if Object.const_defined? :Gem
38
+ original_gems = Object.const_defined?(:Gem) ? Gem.loaded_specs.keys : []
39
39
  original_object_methods = Object.instance_methods
40
40
  original_instance_methods = class << Boson.main_object; instance_methods end
41
41
  original_modules = modules if options[:modules]
@@ -103,6 +103,14 @@ module Boson
103
103
  (conflicting_module =~ /^#{base_module}.*::([^:]+)/) && Object.const_defined?($1) && $1
104
104
  end
105
105
 
106
+ # Splits array into array of arrays with given element
107
+ def split_array_by(arr, divider)
108
+ arr.inject([[]]) {|results, element|
109
+ (divider == element) ? (results << []) : (results.last << element)
110
+ results
111
+ }
112
+ end
113
+
106
114
  # Regular expression search of a list with underscore anchoring of words.
107
115
  # For example 'some_dang_long_word' can be specified as 's_d_l_w'.
108
116
  def underscore_search(input, list, first_match=false)
@@ -0,0 +1,3 @@
1
+ module Boson
2
+ VERSION = '0.2.4'
3
+ end
@@ -1,66 +1,62 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Boson
4
- class ArgumentInspectorTest < Test::Unit::TestCase
5
- context "scrape_with_text" do
6
- def args_from(file_string)
7
- ArgumentInspector.scrape_with_text(file_string, "blah")
8
- end
9
-
10
- test "parses arguments of class method" do
11
- args_from(" def YAML.blah( filepath )\n").should == [['filepath']]
12
- end
3
+ describe "scrape_with_text" do
4
+ def args_from(file_string)
5
+ ArgumentInspector.scrape_with_text(file_string, "blah")
6
+ end
13
7
 
14
- test "parses arguments with no spacing" do
15
- args_from("def bong; end\ndef blah(arg1,arg2='val2')\nend").should == [["arg1"], ['arg2', "'val2'"]]
16
- end
8
+ it "parses arguments of class method" do
9
+ args_from(" def YAML.blah( filepath )\n").should == [['filepath']]
10
+ end
17
11
 
18
- test "parses arguments with spacing" do
19
- args_from("\t def blah( arg1=val1, arg2 = val2)").should == [["arg1","val1"], ["arg2", "val2"]]
20
- end
12
+ it "parses arguments with no spacing" do
13
+ args_from("def bong; end\ndef blah(arg1,arg2='val2')\nend").should == [["arg1"], ['arg2', "'val2'"]]
14
+ end
21
15
 
22
- test "parses arguments without parenthesis" do
23
- args_from(" def blah arg1, arg2, arg3={}").should == [['arg1'], ['arg2'], ['arg3','{}']]
24
- end
25
- end
16
+ it "parses arguments with spacing" do
17
+ args_from("\t def blah( arg1=val1, arg2 = val2)").should == [["arg1","val1"], ["arg2", "val2"]]
18
+ end
26
19
 
27
- context "scrape_with_eval" do
28
- def args_from(string)
29
- # methods need options to have their args parsed with ArgumentInspector
30
- string.gsub!(/(def blah)/, 'options :a=>1; \1')
31
- Inspector.enable
32
- ::Boson::Commands::Aaa.module_eval(string)
33
- Inspector.disable
34
- MethodInspector.store[:args]['blah']
35
- end
20
+ it "parses arguments without parenthesis" do
21
+ args_from(" def blah arg1, arg2, arg3={}").should == [['arg1'], ['arg2'], ['arg3','{}']]
22
+ end
23
+ end
24
+
25
+ describe "scrape_with_eval" do
26
+ def args_from(string)
27
+ # methods need options to have their args parsed with ArgumentInspector
28
+ string.gsub!(/(def blah)/, 'options :a=>1; \1')
29
+ Inspector.enable
30
+ ::Boson::Commands::Aaa.module_eval(string)
31
+ Inspector.disable
32
+ MethodInspector.store[:args]['blah']
33
+ end
36
34
 
37
- before(:all) { eval "module ::Boson::Commands::Aaa; end"; }
38
- before(:each) { MethodInspector.mod_store[::Boson::Commands::Aaa] = {} }
35
+ before_all { eval "module ::Boson::Commands::Aaa; end"; }
36
+ before { MethodInspector.mod_store[::Boson::Commands::Aaa] = {} }
39
37
 
40
- test "determines arguments with literal defaults" do
41
- args_from("def blah(arg1,arg2='val2'); end").should == [['arg1'], ['arg2','val2']]
42
- end
38
+ it "determines arguments with literal defaults" do
39
+ args_from("def blah(arg1,arg2='val2'); end").should == [['arg1'], ['arg2','val2']]
40
+ end
43
41
 
44
- test "determines splat arguments" do
45
- args_from("def blah(arg1, *args); end").should == [['arg1'], ["*args"]]
46
- end
42
+ it "determines splat arguments" do
43
+ args_from("def blah(arg1, *args); end").should == [['arg1'], ["*args"]]
44
+ end
47
45
 
48
- test "determines arguments with local values before a method" do
49
- body = "AWESOME='awesome'; def sweet; 'ok'; end; def blah(arg1=AWESOME, arg2=sweet); end"
50
- args_from(body).should == [['arg1', 'awesome'], ['arg2', 'ok']]
51
- end
46
+ it "determines arguments with local values before a method" do
47
+ body = "AWESOME='awesome'; def sweet; 'ok'; end; def blah(arg1=AWESOME, arg2=sweet); end"
48
+ args_from(body).should == [['arg1', 'awesome'], ['arg2', 'ok']]
49
+ end
52
50
 
53
- test "doesn't get arguments with local values after a method" do
54
- args_from("def blah(arg1=nope) end; def nope; 'nope'; end").should == nil
55
- end
51
+ it "doesn't get arguments with local values after a method" do
52
+ args_from("def blah(arg1=nope) end; def nope; 'nope'; end").should == nil
53
+ end
56
54
 
57
- test "doesn't determine arguments of a private method" do
58
- args_from("private; def blah(arg1,arg2); end").should == nil
59
- end
55
+ it "doesn't determine arguments of a private method" do
56
+ args_from("private; def blah(arg1,arg2); end").should == nil
57
+ end
60
58
 
61
- test "doesn't determine arguments if an error occurs" do
62
- args_from("def blah(arg1,arg2=raise); end").should == nil
63
- end
64
- end
59
+ it "doesn't determine arguments if an error occurs" do
60
+ args_from("def blah(arg1,arg2=raise); end").should == nil
65
61
  end
66
62
  end
@@ -0,0 +1,26 @@
1
+ module BaconExtensions
2
+ def self.included(mod)
3
+ mod.module_eval do
4
+ # nested context methods automatically inherit methods from parent contexts
5
+ def describe(*args, &block)
6
+ context = Bacon::Context.new(args.join(' '), &block)
7
+ (parent_context = self).methods(false).each {|e|
8
+ class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
9
+ }
10
+ @before.each { |b| context.before(&b) }
11
+ @after.each { |b| context.after(&b) }
12
+ context.run
13
+ end
14
+ end
15
+ end
16
+
17
+ def xit(*args); end
18
+ def xdescribe(*args); end
19
+ def before_all; yield; end
20
+ def after_all; yield; end
21
+ def assert(description, &block)
22
+ it(description) do
23
+ block.call.should == true
24
+ end
25
+ end
26
+ end
@@ -1,203 +1,203 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require 'boson/runners/bin_runner'
3
+ BinRunner = Boson::BinRunner
3
4
 
4
- module Boson
5
- class BinRunnerTest < Test::Unit::TestCase
6
- def start(*args)
7
- Hirb.stubs(:enable)
8
- BinRunner.start(args)
9
- end
10
-
11
- before(:each) {|e|
12
- Boson::BinRunner.instance_variables.each {|e| Boson::BinRunner.instance_variable_set(e, nil)}
13
- }
14
- context "at commandline" do
15
- before(:all) { reset }
16
-
17
- test "no arguments prints usage" do
18
- capture_stdout { start }.should =~ /^boson/
19
- end
5
+ describe "BinRunner" do
6
+ def start(*args)
7
+ Hirb.stubs(:enable)
8
+ BinRunner.start(args)
9
+ end
20
10
 
21
- test "invalid option value prints error" do
22
- capture_stderr { start("-l") }.should =~ /Error:/
23
- end
11
+ before {|e|
12
+ BinRunner.instance_variables.each {|e| BinRunner.instance_variable_set(e, nil)}
13
+ }
14
+ describe "at commandline" do
15
+ before_all { reset }
24
16
 
25
- test "help option but no arguments prints usage" do
26
- capture_stdout { start '-h' }.should =~ /^boson/
27
- end
17
+ it "no arguments prints usage" do
18
+ capture_stdout { start }.should =~ /^boson/
19
+ end
28
20
 
29
- test "help option and command prints help" do
30
- capture_stdout { start('-h', 'commands') } =~ /^commands/
31
- end
21
+ it "invalid option value prints error" do
22
+ capture_stderr { start("-l") }.should =~ /Error:/
23
+ end
32
24
 
33
- test "load option loads libraries" do
34
- Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0][0] == 'blah'}.times(2)
35
- BinRunner.stubs(:execute_command)
36
- start('-l', 'blah', 'libraries')
37
- end
25
+ it "help option but no arguments prints usage" do
26
+ capture_stdout { start '-h' }.should =~ /^boson/
27
+ end
38
28
 
39
- test "console option starts irb" do
40
- ConsoleRunner.expects(:start)
41
- Util.expects(:which).returns("/usr/bin/irb")
42
- Kernel.expects(:load).with("/usr/bin/irb")
43
- start("--console")
44
- end
29
+ it "help option and command prints help" do
30
+ capture_stdout { start('-h', 'commands') }.should =~ /^commands/
31
+ end
45
32
 
46
- test "console option but no irb found prints error" do
47
- ConsoleRunner.expects(:start)
48
- Util.expects(:which).returns(nil)
49
- capture_stderr { start("--console") }.should =~ /Console not found/
50
- end
33
+ it "load option loads libraries" do
34
+ Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0][0] == 'blah'}.times(2)
35
+ BinRunner.stubs(:execute_command)
36
+ start('-l', 'blah', 'libraries')
37
+ end
51
38
 
52
- test "execute option executes string" do
53
- BinRunner.expects(:define_autoloader)
54
- capture_stdout { start("-e", "p 1 + 1") }.should == "2\n"
55
- end
39
+ # it "console option starts irb" do
40
+ # ConsoleRunner.expects(:start)
41
+ # Util.expects(:which).returns("/usr/bin/irb")
42
+ # Kernel.expects(:load).with("/usr/bin/irb")
43
+ # start("--console")
44
+ # end
45
+
46
+ it "console option but no irb found prints error" do
47
+ ConsoleRunner.expects(:start)
48
+ Util.expects(:which).returns(nil)
49
+ capture_stderr { start("--console") }.should =~ /Console not found/
50
+ end
56
51
 
57
- test "global option takes value with whitespace" do
58
- View.expects(:render).with {|*args| args[1][:fields] = %w{f1 f2} }
59
- start('commands', '-f', 'f1, f2')
60
- end
52
+ it "execute option executes string" do
53
+ BinRunner.expects(:define_autoloader)
54
+ capture_stdout { start("-e", "p 1 + 1") }.should == "2\n"
55
+ end
61
56
 
62
- test "execute option errors are caught" do
63
- capture_stderr { start("-e", "raise 'blah'") }.should =~ /^Error:/
64
- end
57
+ it "global option takes value with whitespace" do
58
+ View.expects(:render).with {|*args| args[1][:fields] = %w{f1 f2} }
59
+ start('commands', '-f', 'f1, f2')
60
+ end
65
61
 
66
- test "command and too many arguments prints error" do
67
- capture_stdout { capture_stderr { start('commands','1','2','3') }.should =~ /'commands'.*incorrect/ }
68
- end
62
+ it "execute option errors are caught" do
63
+ capture_stderr { start("-e", "raise 'blah'") }.should =~ /^Error:/
64
+ end
69
65
 
70
- test "failed subcommand prints error and not command not found" do
71
- BinRunner.expects(:execute_command).raises("bling")
72
- capture_stderr { start("commands.to_s") }.should =~ /Error: bling/
73
- end
66
+ it "option command and too many arguments prints error" do
67
+ capture_stdout {
68
+ capture_stderr { start('commands','1','2','3') }.should =~ /'commands'.*incorrect/
69
+ }
70
+ end
74
71
 
75
- test "nonexistant subcommand prints command not found" do
76
- capture_stderr { start("to_s.bling") }.should =~ /'to_s.bling' not found/
77
- end
72
+ it "normal command and too many arguments prints error" do
73
+ capture_stdout {
74
+ capture_stderr { start('render') }.should =~ /'render'.*incorrect/
75
+ }
76
+ end
78
77
 
79
- test "undiscovered command prints error" do
80
- BinRunner.expects(:load_command_by_index).returns(false)
81
- capture_stderr { start('blah') }.should =~ /Error.*not found/
82
- end
78
+ it "failed subcommand prints error and not command not found" do
79
+ BinRunner.expects(:execute_command).raises("bling")
80
+ capture_stderr { start("commands.to_s") }.should =~ /Error: bling/
81
+ end
83
82
 
84
- test "basic command executes" do
85
- BinRunner.expects(:init).returns(true)
86
- BinRunner.stubs(:render_output)
87
- Boson.main_object.expects(:send).with('kick','it')
88
- start 'kick','it'
89
- end
83
+ it "nonexistant subcommand prints command not found" do
84
+ capture_stderr { start("to_s.bling") }.should =~ /'to_s.bling' not found/
85
+ end
90
86
 
91
- test "sub command executes" do
92
- obj = Object.new
93
- Boson.main_object.extend Module.new { def phone; Struct.new(:home).new('done'); end }
94
- BinRunner.expects(:init).returns(true)
95
- BinRunner.expects(:render_output).with('done')
96
- start 'phone.home'
97
- end
87
+ it "undiscovered command prints error" do
88
+ BinRunner.expects(:autoload_command).returns(false)
89
+ capture_stderr { start('blah') }.should =~ /Error.*not found/
90
+ end
98
91
 
99
- test "bin_defaults config loads by default" do
100
- defaults = Boson::Runner.default_libraries + ['yo']
101
- with_config(:bin_defaults=>['yo']) do
102
- Manager.expects(:load).with {|*args| args[0] == defaults }
103
- capture_stderr { start 'blah' }
104
- end
105
- end
92
+ it "basic command executes" do
93
+ BinRunner.expects(:init).returns(true)
94
+ BinRunner.stubs(:render_output)
95
+ Boson.main_object.expects(:send).with('kick','it')
96
+ start 'kick','it'
106
97
  end
107
98
 
108
- context "load_command_by_index" do
109
- def index(options={})
110
- Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0] == options[:load]
111
- }.at_least(1).returns(!options[:fails])
112
- Index.indexes[0].expects(:write)
113
- end
99
+ it "sub command executes" do
100
+ obj = Object.new
101
+ Boson.main_object.extend Module.new { def phone; Struct.new(:home).new('done'); end }
102
+ BinRunner.expects(:init).returns(true)
103
+ BinRunner.expects(:render_output).with('done')
104
+ start 'phone.home'
105
+ end
114
106
 
115
- test "with index option, no existing index and core command updates index and prints index message" do
116
- index :load=>Runner.all_libraries
117
- Index.indexes[0].stubs(:exists?).returns(false)
118
- capture_stdout { start("--index", "libraries") }.should =~ /Generating index/
107
+ it "bin_defaults config loads by default" do
108
+ defaults = Runner.default_libraries + ['yo']
109
+ with_config(:bin_defaults=>['yo']) do
110
+ Manager.expects(:load).with {|*args| args[0] == defaults }
111
+ capture_stderr { start 'blah' }
119
112
  end
113
+ end
114
+ end
120
115
 
121
- test "with index option, existing index and core command updates incremental index" do
122
- index :load=>['changed']
123
- Index.indexes[0].stubs(:exists?).returns(true)
124
- capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/
125
- end
116
+ describe "autoload_command" do
117
+ def index(options={})
118
+ Manager.expects(:load).with {|*args| args[0][0].is_a?(Module) ? true : args[0] == options[:load]
119
+ }.at_least(1).returns(!options[:fails])
120
+ Index.indexes[0].expects(:write)
121
+ end
126
122
 
127
- test "with index option, failed indexing prints error" do
128
- index :load=>['changed'], :fails=>true
129
- Index.indexes[0].stubs(:exists?).returns(true)
130
- Manager.stubs(:failed_libraries).returns(['changed'])
131
- capture_stderr {
132
- capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/
133
- }.should =~ /Error:.*failed.*changed/
134
- end
123
+ it "with index option, no existing index and core command updates index and prints index message" do
124
+ index :load=>Runner.all_libraries
125
+ Index.indexes[0].stubs(:exists?).returns(false)
126
+ capture_stdout { start("--index", "libraries") }.should =~ /Generating index/
127
+ end
135
128
 
136
- test "with core command updates index and doesn't print index message" do
137
- Index.indexes[0].expects(:write)
138
- Boson.main_object.expects(:send).with('libraries')
139
- capture_stdout { start 'libraries'}.should_not =~ /index/i
140
- end
129
+ it "with index option, existing index and core command updates incremental index" do
130
+ index :load=>['changed']
131
+ Index.indexes[0].stubs(:exists?).returns(true)
132
+ capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/
133
+ end
141
134
 
142
- test "with non-core command finding library doesn't update index" do
143
- Index.expects(:find_library).returns('sweet_lib')
144
- Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1)
145
- Index.indexes[0].expects(:update).never
146
- capture_stderr { start("sweet") }.should =~ /sweet/
147
- end
135
+ it "with index option, failed indexing prints error" do
136
+ index :load=>['changed'], :fails=>true
137
+ Index.indexes[0].stubs(:exists?).returns(true)
138
+ Manager.stubs(:failed_libraries).returns(['changed'])
139
+ capture_stderr {
140
+ capture_stdout { start("--index=changed", "libraries")}.should =~ /Indexing.*changed/
141
+ }.should =~ /Error:.*failed.*changed/
142
+ end
148
143
 
149
- test "with non-core command not finding library, does update index" do
150
- Index.expects(:find_library).returns(nil, 'sweet_lib').times(2)
151
- Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1)
152
- Index.indexes[0].expects(:update).returns(true)
153
- capture_stderr { start("sweet") }.should =~ /sweet/
154
- end
144
+ it "with core command updates index and doesn't print index message" do
145
+ Index.indexes[0].expects(:write)
146
+ Boson.main_object.expects(:send).with('libraries')
147
+ capture_stdout { start 'libraries'}.should.not =~ /index/i
155
148
  end
156
149
 
157
- context "render_output" do
158
- before(:each) { Scientist.rendered = false; BinRunner.instance_eval "@options = {}" }
150
+ it "with non-core command not finding library, does update index" do
151
+ Index.expects(:find_library).returns(nil, 'sweet_lib')
152
+ Manager.expects(:load).with {|*args| args[0].is_a?(String) ? args[0] == 'sweet_lib' : true}.at_least(1)
153
+ Index.indexes[0].expects(:update).returns(true)
154
+ capture_stderr { start("sweet") }.should =~ /sweet/
155
+ end
156
+ end
159
157
 
160
- test "doesn't render when nil, false or true" do
161
- View.expects(:render).never
162
- [nil, false, true].each do |e|
163
- BinRunner.render_output e
164
- end
165
- end
158
+ describe "render_output" do
159
+ before { Scientist.rendered = false; BinRunner.instance_eval "@options = {}" }
166
160
 
167
- test "doesn't render when rendered with Scientist" do
168
- Scientist.rendered = true
169
- View.expects(:render).never
170
- BinRunner.render_output 'blah'
161
+ it "doesn't render when nil, false or true" do
162
+ View.expects(:render).never
163
+ [nil, false, true].each do |e|
164
+ BinRunner.render_output e
171
165
  end
166
+ end
172
167
 
173
- test "render with puts when non-string" do
174
- View.expects(:render).with('dude', {:method => 'puts'})
175
- BinRunner.render_output 'dude'
176
- end
168
+ it "doesn't render when rendered with Scientist" do
169
+ Scientist.rendered = true
170
+ View.expects(:render).never
171
+ BinRunner.render_output 'blah'
172
+ end
177
173
 
178
- test "renders with inspect when non-array and non-string" do
179
- [{:a=>true}, :ok].each do |e|
180
- View.expects(:puts).with(e.inspect)
181
- BinRunner.render_output e
182
- end
183
- end
174
+ it "render with puts when non-string" do
175
+ View.expects(:render).with('dude', {:method => 'puts'})
176
+ BinRunner.render_output 'dude'
177
+ end
184
178
 
185
- test "renders with inspect when Scientist rendering toggled off with :render" do
186
- Scientist.global_options = {:render=>true}
187
- View.expects(:puts).with([1,2].inspect)
188
- BinRunner.render_output [1,2]
189
- Scientist.global_options = nil
179
+ it "renders with inspect when non-array and non-string" do
180
+ [{:a=>true}, :ok].each do |e|
181
+ View.expects(:puts).with(e.inspect)
182
+ BinRunner.render_output e
190
183
  end
184
+ end
191
185
 
192
- test "renders with hirb when array" do
193
- View.expects(:render_object)
194
- BinRunner.render_output [1,2,3]
195
- end
186
+ it "renders with inspect when Scientist rendering toggled off with :render" do
187
+ Scientist.global_options = {:render=>true}
188
+ View.expects(:puts).with([1,2].inspect)
189
+ BinRunner.render_output [1,2]
190
+ Scientist.global_options = nil
196
191
  end
197
192
 
198
- test "parse_args only translates options before command" do
199
- BinRunner.parse_args(['-v', 'com', '-v']).should == ["com", {:verbose=>true}, ['-v']]
200
- BinRunner.parse_args(['com', '-v']).should == ["com", {}, ['-v']]
193
+ it "renders with hirb when array" do
194
+ View.expects(:render_object)
195
+ BinRunner.render_output [1,2,3]
201
196
  end
202
197
  end
198
+
199
+ it "parse_args only translates options before command" do
200
+ BinRunner.parse_args(['-v', 'com', '-v']).should == ["com", {:verbose=>true}, ['-v']]
201
+ BinRunner.parse_args(['com', '-v']).should == ["com", {}, ['-v']]
202
+ end
203
203
  end