boson 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +76 -0
- data/README.rdoc +6 -6
- data/Rakefile +24 -41
- data/gemspec +19 -0
- data/lib/boson.rb +4 -4
- data/lib/boson/command.rb +2 -2
- data/lib/boson/commands/core.rb +1 -1
- data/lib/boson/commands/web_core.rb +16 -12
- data/lib/boson/manager.rb +1 -1
- data/lib/boson/pipes.rb +6 -2
- data/lib/boson/repo_index.rb +1 -1
- data/lib/boson/runner.rb +2 -2
- data/lib/boson/runners/bin_runner.rb +72 -29
- data/lib/boson/scientist.rb +22 -4
- data/lib/boson/util.rb +9 -1
- data/lib/boson/version.rb +3 -0
- data/test/argument_inspector_test.rb +47 -51
- data/test/bacon_extensions.rb +26 -0
- data/test/bin_runner_test.rb +160 -160
- data/test/comment_inspector_test.rb +87 -89
- data/test/file_library_test.rb +32 -34
- data/test/loader_test.rb +181 -182
- data/test/manager_test.rb +76 -78
- data/test/method_inspector_test.rb +51 -53
- data/test/option_parser_test.rb +49 -42
- data/test/options_test.rb +168 -168
- data/test/pipes_test.rb +48 -46
- data/test/repo_index_test.rb +117 -113
- data/test/repo_test.rb +17 -17
- data/test/runner_test.rb +31 -34
- data/test/scientist_test.rb +258 -254
- data/test/test_helper.rb +21 -38
- data/test/util_test.rb +40 -42
- metadata +55 -46
- data/VERSION.yml +0 -5
data/lib/boson/scientist.rb
CHANGED
@@ -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
|
-
|
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 =
|
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
|
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
|
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)
|
@@ -1,66 +1,62 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
8
|
+
it "parses arguments of class method" do
|
9
|
+
args_from(" def YAML.blah( filepath )\n").should == [['filepath']]
|
10
|
+
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
35
|
+
before_all { eval "module ::Boson::Commands::Aaa; end"; }
|
36
|
+
before { MethodInspector.mod_store[::Boson::Commands::Aaa] = {} }
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
42
|
+
it "determines splat arguments" do
|
43
|
+
args_from("def blah(arg1, *args); end").should == [['arg1'], ["*args"]]
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
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
|
data/test/bin_runner_test.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
17
|
+
it "no arguments prints usage" do
|
18
|
+
capture_stdout { start }.should =~ /^boson/
|
19
|
+
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
it "invalid option value prints error" do
|
22
|
+
capture_stderr { start("-l") }.should =~ /Error:/
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
62
|
+
it "execute option errors are caught" do
|
63
|
+
capture_stderr { start("-e", "raise 'blah'") }.should =~ /^Error:/
|
64
|
+
end
|
69
65
|
|
70
|
-
|
71
|
-
|
72
|
-
capture_stderr { start(
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
158
|
-
|
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
|
-
|
161
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
170
|
-
BinRunner.render_output
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
186
|
-
|
187
|
-
View.expects(:puts).with(
|
188
|
-
BinRunner.render_output
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
199
|
-
|
200
|
-
BinRunner.
|
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
|