bbcloud 0.6.2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bbcloud.gemspec +1 -3
- data/lib/bbcloud/commands/servers-show.rb +1 -1
- data/lib/bbcloud/version.rb +1 -1
- metadata +26 -61
- data/lib/bbcloud/commands/servers-restart.rb +0 -30
- data/lib/bbcloud/vendor/hirb/.gemspec +0 -22
- data/lib/bbcloud/vendor/hirb/CHANGELOG.rdoc +0 -106
- data/lib/bbcloud/vendor/hirb/LICENSE.txt +0 -22
- data/lib/bbcloud/vendor/hirb/README.rdoc +0 -182
- data/lib/bbcloud/vendor/hirb/Rakefile +0 -35
- data/lib/bbcloud/vendor/hirb/lib/bond/completions/hirb.rb +0 -15
- data/lib/bbcloud/vendor/hirb/lib/hirb/console.rb +0 -43
- data/lib/bbcloud/vendor/hirb/lib/hirb/dynamic_view.rb +0 -113
- data/lib/bbcloud/vendor/hirb/lib/hirb/formatter.rb +0 -116
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/auto_table.rb +0 -24
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/object_table.rb +0 -14
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/parent_child_tree.rb +0 -24
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/filters.rb +0 -10
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/resizer.rb +0 -82
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table.rb +0 -323
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/tree.rb +0 -181
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/vertical_table.rb +0 -37
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers.rb +0 -17
- data/lib/bbcloud/vendor/hirb/lib/hirb/import_object.rb +0 -10
- data/lib/bbcloud/vendor/hirb/lib/hirb/menu.rb +0 -221
- data/lib/bbcloud/vendor/hirb/lib/hirb/pager.rb +0 -95
- data/lib/bbcloud/vendor/hirb/lib/hirb/string.rb +0 -44
- data/lib/bbcloud/vendor/hirb/lib/hirb/util.rb +0 -96
- data/lib/bbcloud/vendor/hirb/lib/hirb/version.rb +0 -3
- data/lib/bbcloud/vendor/hirb/lib/hirb/view.rb +0 -284
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/couch_db.rb +0 -11
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/misc_db.rb +0 -15
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/mongo_db.rb +0 -14
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/orm.rb +0 -11
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/rails.rb +0 -19
- data/lib/bbcloud/vendor/hirb/lib/hirb/views.rb +0 -8
- data/lib/bbcloud/vendor/hirb/lib/hirb.rb +0 -81
- data/lib/bbcloud/vendor/hirb/test/auto_table_test.rb +0 -30
- data/lib/bbcloud/vendor/hirb/test/console_test.rb +0 -27
- data/lib/bbcloud/vendor/hirb/test/deps.rip +0 -4
- data/lib/bbcloud/vendor/hirb/test/dynamic_view_test.rb +0 -94
- data/lib/bbcloud/vendor/hirb/test/formatter_test.rb +0 -171
- data/lib/bbcloud/vendor/hirb/test/hirb_test.rb +0 -39
- data/lib/bbcloud/vendor/hirb/test/import_test.rb +0 -9
- data/lib/bbcloud/vendor/hirb/test/menu_test.rb +0 -239
- data/lib/bbcloud/vendor/hirb/test/object_table_test.rb +0 -79
- data/lib/bbcloud/vendor/hirb/test/pager_test.rb +0 -162
- data/lib/bbcloud/vendor/hirb/test/resizer_test.rb +0 -62
- data/lib/bbcloud/vendor/hirb/test/table_test.rb +0 -550
- data/lib/bbcloud/vendor/hirb/test/test_helper.rb +0 -61
- data/lib/bbcloud/vendor/hirb/test/tree_test.rb +0 -184
- data/lib/bbcloud/vendor/hirb/test/util_test.rb +0 -59
- data/lib/bbcloud/vendor/hirb/test/view_test.rb +0 -172
- data/lib/bbcloud/vendor/hirb/test/views_test.rb +0 -13
@@ -1,171 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "Formatter" do
|
4
|
-
def set_formatter(hash={})
|
5
|
-
@formatter = Formatter.new(hash)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "klass_config" do
|
9
|
-
it "recursively merges ancestor options" do
|
10
|
-
@formatter = set_formatter "String"=>{:args=>[1,2], :options=>{:fields=>[:to_s]}},
|
11
|
-
"Object"=>{:method=>:object_output, :ancestor=>true, :options=>{:vertical=>true}},
|
12
|
-
"Kernel"=>{:method=>:default_output}
|
13
|
-
expected_result = {:method=>:object_output, :args=>[1, 2], :ancestor=>true, :options=>{:fields=>[:to_s], :vertical=>true}}
|
14
|
-
@formatter.klass_config(::String).should == expected_result
|
15
|
-
end
|
16
|
-
|
17
|
-
it "doesn't merge ancestor options" do
|
18
|
-
@formatter = set_formatter "String"=>{:args=>[1,2]}, "Object"=>{:method=>:object_output},
|
19
|
-
"Kernel"=>{:method=>:default_output}
|
20
|
-
@formatter.klass_config(::String).should == {:args=>[1, 2]}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns hash when nothing found" do
|
24
|
-
set_formatter.klass_config(::String).should == {}
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "with dynamic_config" do
|
28
|
-
def set_formatter(hash={})
|
29
|
-
@formatter = Formatter.new(hash)
|
30
|
-
end
|
31
|
-
after { Formatter.dynamic_config = {}}
|
32
|
-
|
33
|
-
it "merges ancestor options and sets local config" do
|
34
|
-
Formatter.dynamic_config = {"Object"=>{:method=>:blah}, "Kernel"=>{:args=>[1,2], :ancestor=>true}}
|
35
|
-
set_formatter.klass_config(::String).should == {:args=>[1,2], :ancestor=>true}
|
36
|
-
@formatter.config['Kernel'].should == {:args=>[1,2], :ancestor=>true}
|
37
|
-
end
|
38
|
-
|
39
|
-
it "uses local config over dynamic_config" do
|
40
|
-
Formatter.dynamic_config = {"String"=>{:method=>:blah}}
|
41
|
-
set_formatter "String"=>{:args=>[1,2]}
|
42
|
-
@formatter.klass_config(::String).should == {:args=>[1,2]}
|
43
|
-
end
|
44
|
-
|
45
|
-
it "uses dynamic_config and sets local config" do
|
46
|
-
Formatter.dynamic_config = {"String"=>{:method=>:blah}}
|
47
|
-
set_formatter.klass_config(::String).should == {:method=>:blah}
|
48
|
-
@formatter.config['String'].should == {:method=>:blah}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "formatter methods:" do
|
54
|
-
before_all { eval "module ::Dooda; end" }
|
55
|
-
|
56
|
-
it "add_view sets formatter config" do
|
57
|
-
@formatter = set_formatter
|
58
|
-
@formatter.add_view ::Dooda, :class=>"DoodaView"
|
59
|
-
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView"}
|
60
|
-
end
|
61
|
-
|
62
|
-
it "add_view overwrites existing formatter config" do
|
63
|
-
@formatter = set_formatter "Dooda"=>{:class=>"DoodaView"}
|
64
|
-
@formatter.add_view ::Dooda, :class=>"DoodaView2"
|
65
|
-
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView2"}
|
66
|
-
end
|
67
|
-
|
68
|
-
it "parse_console_options passes all options except for formatter options into :options" do
|
69
|
-
@formatter = set_formatter
|
70
|
-
options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :blah=>'blah'}
|
71
|
-
expected_options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :options=>{:blah=>'blah'}}
|
72
|
-
@formatter.parse_console_options(options).should == expected_options
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "format_output" do
|
77
|
-
def view_output(*args, &block); View.view_output(*args, &block); end
|
78
|
-
def render_method(*args); View.render_method(*args); end
|
79
|
-
|
80
|
-
def enable_with_output(value)
|
81
|
-
Hirb.enable :output=>value
|
82
|
-
end
|
83
|
-
|
84
|
-
before_all {
|
85
|
-
eval %[module ::Commify
|
86
|
-
def self.render(strings)
|
87
|
-
strings = Array(strings)
|
88
|
-
strings.map {|e| e.split('').join(',')}.join("\n")
|
89
|
-
end
|
90
|
-
end]
|
91
|
-
reset_config
|
92
|
-
}
|
93
|
-
before { View.formatter = nil; reset_config }
|
94
|
-
after { Hirb.disable }
|
95
|
-
|
96
|
-
it "formats with method option" do
|
97
|
-
eval "module ::Kernel; def commify(string); string.split('').join(','); end; end"
|
98
|
-
enable_with_output "String"=>{:method=>:commify}
|
99
|
-
render_method.expects(:call).with('d,u,d,e')
|
100
|
-
view_output('dude')
|
101
|
-
end
|
102
|
-
|
103
|
-
it "formats with class option" do
|
104
|
-
enable_with_output "String"=>{:class=>"Commify"}
|
105
|
-
render_method.expects(:call).with('d,u,d,e')
|
106
|
-
view_output('dude')
|
107
|
-
end
|
108
|
-
|
109
|
-
it "formats with class option as symbol" do
|
110
|
-
enable_with_output "String"=>{:class=>:auto_table}
|
111
|
-
Helpers::AutoTable.expects(:render)
|
112
|
-
view_output('dude')
|
113
|
-
end
|
114
|
-
|
115
|
-
it "formats arrays" do
|
116
|
-
enable_with_output "String"=>{:class=>"Commify"}
|
117
|
-
render_method.expects(:call).with('d,u,d,e')
|
118
|
-
view_output(['dude'])
|
119
|
-
end
|
120
|
-
|
121
|
-
it "formats array-like objects" do
|
122
|
-
enable_with_output "String"=>{:class=>"Commify"}
|
123
|
-
render_method.expects(:call).with('d,u,d,e')
|
124
|
-
require 'set'
|
125
|
-
view_output Set.new(['dude'])
|
126
|
-
end
|
127
|
-
|
128
|
-
it "formats with options option" do
|
129
|
-
eval "module ::Blahify; def self.render(*args); end; end"
|
130
|
-
enable_with_output "String"=>{:class=>"Blahify", :options=>{:fields=>%w{a b}}}
|
131
|
-
Blahify.expects(:render).with('dude', :fields=>%w{a b})
|
132
|
-
view_output('dude')
|
133
|
-
end
|
134
|
-
|
135
|
-
it "doesn't format and returns false when no format method found" do
|
136
|
-
Hirb.enable
|
137
|
-
render_method.expects(:call).never
|
138
|
-
view_output(Date.today).should == false
|
139
|
-
end
|
140
|
-
|
141
|
-
it "formats with output_method option as method" do
|
142
|
-
enable_with_output 'String'=>{:class=>"Commify", :output_method=>:chop}
|
143
|
-
render_method.expects(:call).with('d,u,d')
|
144
|
-
view_output('dude')
|
145
|
-
end
|
146
|
-
|
147
|
-
it "formats with output_method option as proc" do
|
148
|
-
enable_with_output 'String'=>{:class=>"Commify", :output_method=>lambda {|e| e.chop}}
|
149
|
-
render_method.expects(:call).with('d,u,d')
|
150
|
-
view_output('dude')
|
151
|
-
end
|
152
|
-
|
153
|
-
it "formats output array with output_method option" do
|
154
|
-
enable_with_output 'String'=>{:class=>"Commify", :output_method=>:chop}
|
155
|
-
render_method.expects(:call).with("d,u,d\nm,a")
|
156
|
-
view_output(['dude', 'man'])
|
157
|
-
end
|
158
|
-
|
159
|
-
it "formats with explicit class option" do
|
160
|
-
enable_with_output 'String'=>{:class=>"Blahify"}
|
161
|
-
render_method.expects(:call).with('d,u,d,e')
|
162
|
-
view_output('dude', :class=>"Commify")
|
163
|
-
end
|
164
|
-
|
165
|
-
it "formats with explicit options option merges with existing options" do
|
166
|
-
enable_with_output "String"=>{:class=>"Commify", :options=>{:fields=>%w{f1 f2}}}
|
167
|
-
Commify.expects(:render).with('dude', :max_width=>10, :fields=>%w{f1 f2})
|
168
|
-
view_output('dude', :options=>{:max_width=>10})
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "Hirb" do
|
4
|
-
before_all { Hirb.config_files = nil }
|
5
|
-
before { Hirb.config = nil }
|
6
|
-
|
7
|
-
it "config converts yaml when config file exists" do
|
8
|
-
yaml_data = {:blah=>'blah'}
|
9
|
-
File.stubs('exists?').returns(true)
|
10
|
-
Hirb.config_files = ['ok']
|
11
|
-
YAML::expects(:load_file).returns(yaml_data)
|
12
|
-
Hirb.config.should == yaml_data
|
13
|
-
end
|
14
|
-
|
15
|
-
it "config defaults to hash when no config file" do
|
16
|
-
File.stubs('exists?').returns(false)
|
17
|
-
Hirb.config.should == {}
|
18
|
-
end
|
19
|
-
|
20
|
-
it "config reloads if given explicit reload" do
|
21
|
-
Hirb.config
|
22
|
-
Hirb.expects(:read_config_file).returns({})
|
23
|
-
Hirb.config(true)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "config reads multiple config files and merges them" do
|
27
|
-
Hirb.config_files = %w{one two}
|
28
|
-
Hirb.expects(:read_config_file).times(2).returns({:output=>{"String"=>:auto_table}}, {:output=>{"Array"=>:auto_table}})
|
29
|
-
Hirb.config.should == {:output=>{"Array"=>:auto_table, "String"=>:auto_table}}
|
30
|
-
Hirb.config_files = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "config_file sets correctly when no ENV['HOME']" do
|
34
|
-
Hirb.config_files = nil
|
35
|
-
home = ENV.delete('HOME')
|
36
|
-
Hirb.config_files[0].class.should == String
|
37
|
-
ENV["HOME"] = home
|
38
|
-
end
|
39
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "import" do
|
4
|
-
it "require import_object extends Object" do
|
5
|
-
Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should == false
|
6
|
-
require 'hirb/import_object'
|
7
|
-
Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should == true
|
8
|
-
end
|
9
|
-
end
|
@@ -1,239 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "Menu" do
|
4
|
-
before_all { View.instance_variable_set("@config", :width=>Hirb::View::DEFAULT_WIDTH) }
|
5
|
-
|
6
|
-
def menu(*args, &block)
|
7
|
-
# testing via menu's main use case (through console) instead of Menu.render
|
8
|
-
@console ||= Object.new.extend(Hirb::Console)
|
9
|
-
@console.menu(*args, &block)
|
10
|
-
end
|
11
|
-
|
12
|
-
def basic_menu(*args, &block)
|
13
|
-
menu_input('1')
|
14
|
-
capture_stdout { menu(*args, &block).should == [1] }
|
15
|
-
end
|
16
|
-
|
17
|
-
def menu_input(input='')
|
18
|
-
$stdin.expects(:gets).returns(input)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "menu" do
|
22
|
-
it "by default renders table menu" do
|
23
|
-
expected_menu = <<-MENU.unindent
|
24
|
-
+--------+-------+
|
25
|
-
| number | value |
|
26
|
-
+--------+-------+
|
27
|
-
| 1 | 1 |
|
28
|
-
| 2 | 2 |
|
29
|
-
| 3 | 3 |
|
30
|
-
+--------+-------+
|
31
|
-
3 rows in set
|
32
|
-
MENU
|
33
|
-
basic_menu([1,2,3]).include?(expected_menu).should == true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "with block renders" do
|
37
|
-
menu_input "1,2"
|
38
|
-
expected_result = [1,2]
|
39
|
-
capture_stdout {
|
40
|
-
menu([1,2,3]) {|e| e.should == expected_result }.should == expected_result
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
it "with block and no chosen doesn't call block" do
|
45
|
-
menu_input ""
|
46
|
-
block = lambda {|e| @called = true }
|
47
|
-
capture_stdout {
|
48
|
-
menu([1,2,3], &block).should == []
|
49
|
-
}
|
50
|
-
assert !@called
|
51
|
-
end
|
52
|
-
|
53
|
-
it "with valid helper_class option renders" do
|
54
|
-
Helpers::Table.expects(:render)
|
55
|
-
basic_menu [1,2,3], :helper_class=>"Hirb::Helpers::Table"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "with invalid helper_class option renders default menu" do
|
59
|
-
expected_menu = <<-MENU.unindent
|
60
|
-
1: 1
|
61
|
-
2: 2
|
62
|
-
3: 3
|
63
|
-
MENU
|
64
|
-
basic_menu([1,2,3], :helper_class=>"SomeHelper").include?(expected_menu).should == true
|
65
|
-
end
|
66
|
-
|
67
|
-
it "with false helper_class option renders default menu" do
|
68
|
-
expected_menu = <<-MENU.unindent
|
69
|
-
1: 1
|
70
|
-
2: 2
|
71
|
-
3: 3
|
72
|
-
MENU
|
73
|
-
basic_menu([1,2,3], :helper_class=>false).include?(expected_menu).should == true
|
74
|
-
end
|
75
|
-
|
76
|
-
it "prints prompt option" do
|
77
|
-
prompt = "Input or else ..."
|
78
|
-
basic_menu([1,2,3], :prompt=>prompt).include?(prompt).should == true
|
79
|
-
end
|
80
|
-
|
81
|
-
it "converts non-array inputs to array" do
|
82
|
-
Helpers::AutoTable.expects(:render).with([1], anything)
|
83
|
-
basic_menu 1
|
84
|
-
end
|
85
|
-
|
86
|
-
it "with false ask option returns one choice without asking" do
|
87
|
-
$stdin.expects(:gets).never
|
88
|
-
menu([1], :ask=>false).should == [1]
|
89
|
-
end
|
90
|
-
|
91
|
-
it "with no items to choose from always return without asking" do
|
92
|
-
$stdin.expects(:gets).never
|
93
|
-
menu([], :ask=>false).should == []
|
94
|
-
menu([], :ask=>true).should == []
|
95
|
-
end
|
96
|
-
|
97
|
-
it "with directions option turns off directions" do
|
98
|
-
menu_input('blah')
|
99
|
-
capture_stdout { menu([1], :directions=>false) }.should.not =~ /range.*all/
|
100
|
-
end
|
101
|
-
|
102
|
-
it "with true reopen option reopens" do
|
103
|
-
$stdin.expects(:reopen).with('/dev/tty')
|
104
|
-
basic_menu [1], :reopen=>true
|
105
|
-
end
|
106
|
-
|
107
|
-
it "with string reopen option reopens" do
|
108
|
-
$stdin.expects(:reopen).with('/dev/blah')
|
109
|
-
basic_menu [1], :reopen=>'/dev/blah'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def two_d_menu(options={})
|
114
|
-
if options[:invokes] || options[:invoke]
|
115
|
-
cmd = options[:command] || 'p'
|
116
|
-
(options[:invokes] || [options[:invoke]]).each {|e|
|
117
|
-
Menu.any_instance.expects(:invoke).with(cmd, e)
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
capture_stdout {
|
122
|
-
return menu(options[:output] || [{:a=>1, :bro=>2}, {:a=>3, :bro=>4}],
|
123
|
-
{:two_d=>true}.merge(options))
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "2d menu" do
|
128
|
-
it "with default field from last_table renders" do
|
129
|
-
menu_input "1"
|
130
|
-
two_d_menu.should == [1]
|
131
|
-
end
|
132
|
-
|
133
|
-
it "with default field from fields option renders" do
|
134
|
-
menu_input "1"
|
135
|
-
two_d_menu(:fields=>[:bro, :a]).should == [2]
|
136
|
-
end
|
137
|
-
|
138
|
-
it "with default field option renders" do
|
139
|
-
menu_input "1"
|
140
|
-
two_d_menu(:default_field=>:bro).should == [2]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "with non-table helper class renders" do
|
144
|
-
menu_input "1"
|
145
|
-
two_d_menu(:helper_class=>false, :fields=>[:a,:bro]).should == [1]
|
146
|
-
end
|
147
|
-
|
148
|
-
it "with no default field prints error" do
|
149
|
-
menu_input "1"
|
150
|
-
capture_stderr { two_d_menu(:fields=>[]) }.should =~ /No default.*found/
|
151
|
-
end
|
152
|
-
|
153
|
-
it "with invalid field prints error" do
|
154
|
-
menu_input "1:z"
|
155
|
-
capture_stderr { two_d_menu }.should =~ /Invalid.*'z'/
|
156
|
-
end
|
157
|
-
|
158
|
-
it "with choice from abbreviated field" do
|
159
|
-
menu_input "2:b"
|
160
|
-
two_d_menu.should == [4]
|
161
|
-
end
|
162
|
-
|
163
|
-
it "with choices from multiple fields renders" do
|
164
|
-
menu_input "1 2:bro"
|
165
|
-
two_d_menu.should == [1,4]
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "action menu" do
|
170
|
-
it "invokes" do
|
171
|
-
menu_input "p 1 2:bro"
|
172
|
-
two_d_menu(:action=>true, :invoke=>[[1,4]])
|
173
|
-
end
|
174
|
-
|
175
|
-
it "with 1d invokes" do
|
176
|
-
menu_input "p 1"
|
177
|
-
two_d_menu(:action=>true, :two_d=>nil, :invoke=>[[{:a=>1, :bro=>2}]])
|
178
|
-
end
|
179
|
-
|
180
|
-
it "with non-choice arguments invokes" do
|
181
|
-
menu_input "p arg1 1"
|
182
|
-
two_d_menu :action=>true, :invoke=>['arg1', [1]]
|
183
|
-
end
|
184
|
-
|
185
|
-
it "with multiple choice arguments flattens them into arg" do
|
186
|
-
menu_input "p arg1 1 2:bro arg2"
|
187
|
-
two_d_menu :action=>true, :invoke=>['arg1', [1,4], 'arg2']
|
188
|
-
end
|
189
|
-
|
190
|
-
it "with nothing chosen prints error" do
|
191
|
-
menu_input "cmd"
|
192
|
-
capture_stderr { two_d_menu(:action=>true) }.should =~ /No rows chosen/
|
193
|
-
end
|
194
|
-
|
195
|
-
it "with no command given prints error" do
|
196
|
-
menu_input "1"
|
197
|
-
capture_stderr { two_d_menu(:action=>true) }.should =~ /No command given/
|
198
|
-
end
|
199
|
-
|
200
|
-
it "with array menu items" do
|
201
|
-
menu_input "p 1"
|
202
|
-
two_d_menu :action=>true, :output=>[['some', 'choice'], ['and', 'another']],
|
203
|
-
:invokes=>[[['some']]]
|
204
|
-
end
|
205
|
-
|
206
|
-
it "with multi_action option invokes" do
|
207
|
-
menu_input "p 1 2:bro"
|
208
|
-
two_d_menu(:action=>true, :multi_action=>true, :invokes=>[[1], [4]])
|
209
|
-
end
|
210
|
-
|
211
|
-
it "with command option invokes" do
|
212
|
-
menu_input "1"
|
213
|
-
two_d_menu(:action=>true, :command=>'p', :invoke=>[[1]])
|
214
|
-
end
|
215
|
-
|
216
|
-
it "with command option and empty input doesn't invoke action and exists silently" do
|
217
|
-
Menu.any_instance.expects(:invoke).never
|
218
|
-
menu_input ""
|
219
|
-
two_d_menu(:action=>true, :command=>'p').should == nil
|
220
|
-
end
|
221
|
-
|
222
|
-
it "with action_object option invokes" do
|
223
|
-
obj = mock(:blah=>true)
|
224
|
-
menu_input "blah 1"
|
225
|
-
two_d_menu(:action=>true, :action_object=>obj)
|
226
|
-
end
|
227
|
-
|
228
|
-
it "with ask false and defaults invokes" do
|
229
|
-
two_d_menu(:output=>[{:a=>1, :bro=>2}], :action=>true, :ask=>false, :default_field=>:a,
|
230
|
-
:command=>'p', :invoke=>[[1]])
|
231
|
-
end
|
232
|
-
|
233
|
-
it "with ask false and no defaults prints error" do
|
234
|
-
capture_stderr {
|
235
|
-
two_d_menu(:output=>[{:a=>1, :bro=>2}], :action=>true, :ask=>false, :command=>'p')
|
236
|
-
}.should =~ /Default.*required/
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "object table" do
|
4
|
-
def table(*args)
|
5
|
-
Helpers::ObjectTable.render(*args)
|
6
|
-
end
|
7
|
-
|
8
|
-
before_all {
|
9
|
-
@pets = [stub(:name=>'rufus', :age=>7, :to_s=>'rufus'), stub(:name=>'alf', :age=>101, :to_s=>'alf')]
|
10
|
-
}
|
11
|
-
it "renders" do
|
12
|
-
expected_table = <<-TABLE.unindent
|
13
|
-
+-------+-----+
|
14
|
-
| name | age |
|
15
|
-
+-------+-----+
|
16
|
-
| rufus | 7 |
|
17
|
-
| alf | 101 |
|
18
|
-
+-------+-----+
|
19
|
-
2 rows in set
|
20
|
-
TABLE
|
21
|
-
table(@pets, :fields=>[:name, :age]).should == expected_table
|
22
|
-
end
|
23
|
-
|
24
|
-
it "with no options defaults to to_s field" do
|
25
|
-
expected_table = <<-TABLE.unindent
|
26
|
-
+-------+
|
27
|
-
| value |
|
28
|
-
+-------+
|
29
|
-
| rufus |
|
30
|
-
| alf |
|
31
|
-
+-------+
|
32
|
-
2 rows in set
|
33
|
-
TABLE
|
34
|
-
table(@pets).should == expected_table
|
35
|
-
end
|
36
|
-
|
37
|
-
it "renders simple arrays" do
|
38
|
-
expected_table = <<-TABLE.unindent
|
39
|
-
+-------+
|
40
|
-
| value |
|
41
|
-
+-------+
|
42
|
-
| 1 |
|
43
|
-
| 2 |
|
44
|
-
| 3 |
|
45
|
-
| 4 |
|
46
|
-
+-------+
|
47
|
-
4 rows in set
|
48
|
-
TABLE
|
49
|
-
table([1,2,3,4]).should == expected_table
|
50
|
-
end
|
51
|
-
|
52
|
-
it "renders simple arrays with custom header" do
|
53
|
-
expected_table = <<-TABLE.unindent
|
54
|
-
+-----+
|
55
|
-
| num |
|
56
|
-
+-----+
|
57
|
-
| 1 |
|
58
|
-
| 2 |
|
59
|
-
| 3 |
|
60
|
-
| 4 |
|
61
|
-
+-----+
|
62
|
-
4 rows in set
|
63
|
-
TABLE
|
64
|
-
table([1,2,3,4], :headers=>{:to_s=>'num'}).should == expected_table
|
65
|
-
end
|
66
|
-
|
67
|
-
it "with empty fields" do
|
68
|
-
expected_table = <<-TABLE.unindent
|
69
|
-
0 rows in set
|
70
|
-
TABLE
|
71
|
-
table(@pets, :fields => []).should == expected_table
|
72
|
-
end
|
73
|
-
|
74
|
-
it "doesn't raise error for objects that don't have :send defined" do
|
75
|
-
object = Object.new
|
76
|
-
class<<object; self; end.send :undef_method, :send
|
77
|
-
should.not.raise(NoMethodError) { table([object], :fields=>[:to_s]) }
|
78
|
-
end
|
79
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "Pager" do
|
4
|
-
def pager; View.pager; end
|
5
|
-
|
6
|
-
def create_pageable_string(inspect_mode=false, size={})
|
7
|
-
size = {:width=>pager.width, :height=>pager.height}.merge(size)
|
8
|
-
seed = inspect_mode ? "a" : "a\n"
|
9
|
-
if inspect_mode
|
10
|
-
seed * (size[:width] * size[:height] + 1)
|
11
|
-
else
|
12
|
-
seed * (size[:height] + 1)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "command_pager sets pager_command when command exists" do
|
17
|
-
Util.expects(:command_exists?).returns(true)
|
18
|
-
Pager.expects(:basic_pager)
|
19
|
-
Pager.command_pager 'blah', :pager_command=>'less'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "command_pager doesn't set pager_command when command doesn't exist" do
|
23
|
-
Util.expects(:command_exists?).returns(false)
|
24
|
-
Pager.expects(:basic_pager).never
|
25
|
-
Pager.command_pager 'blah', :pager_command=>'moreless'
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "default_pager" do
|
29
|
-
before_all { reset_config; Hirb.enable :pager=>true }
|
30
|
-
before { View.pager = nil; Pager.stubs(:pager_command).returns(nil) }
|
31
|
-
|
32
|
-
it "pages once in normal mode" do
|
33
|
-
$stdin.expects(:gets).returns("\n")
|
34
|
-
output = capture_stdout { pager.page(create_pageable_string, false) }
|
35
|
-
output.include?('quit').should == true
|
36
|
-
output.include?('finished').should == true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "doesn't page in normal mode" do
|
40
|
-
$stdin.expects(:gets).never
|
41
|
-
output = capture_stdout { pager.page("a\n", false) }
|
42
|
-
output.include?("a\n=== Pager finished. ===\n").should == true
|
43
|
-
end
|
44
|
-
|
45
|
-
it "pages once in inspect mode" do
|
46
|
-
$stdin.expects(:gets).returns("\n")
|
47
|
-
output = capture_stdout { pager.page(create_pageable_string(true), true) }
|
48
|
-
output.include?('quit').should == true
|
49
|
-
output.include?('finished').should == true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "doesn't page in inspect mode" do
|
53
|
-
$stdin.expects(:gets).never
|
54
|
-
output = capture_stdout { pager.page("a", true) }
|
55
|
-
output.include?("a\n=== Pager finished. ===\n").should == true
|
56
|
-
end
|
57
|
-
after_all { Hirb.disable }
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "pager" do
|
61
|
-
before_all { reset_config; Hirb.enable }
|
62
|
-
before { View.pager = nil; View.formatter = nil }
|
63
|
-
|
64
|
-
def irb_eval(string)
|
65
|
-
context_stub = stub(:last_value=>string)
|
66
|
-
::IRB::Irb.new(context_stub).output_value
|
67
|
-
end
|
68
|
-
|
69
|
-
# this mode is called within @irb.output_value
|
70
|
-
describe "in inspect_mode" do
|
71
|
-
it "activates when output is wide enough" do
|
72
|
-
output = create_pageable_string(true)
|
73
|
-
pager.expects(:page).with(output.inspect, true)
|
74
|
-
View.expects(:render_output).returns(false)
|
75
|
-
irb_eval output
|
76
|
-
end
|
77
|
-
|
78
|
-
it "doesn't activate when output isn't wide enough" do
|
79
|
-
pager.expects(:page).never
|
80
|
-
View.expects(:render_output).returns(false)
|
81
|
-
irb_eval("a")
|
82
|
-
end
|
83
|
-
|
84
|
-
it "activates with an explicit width" do
|
85
|
-
View.config[:width] = 10
|
86
|
-
output = create_pageable_string true, :width=>10
|
87
|
-
pager.expects(:page).with(output.inspect, true)
|
88
|
-
View.expects(:render_output).returns(false)
|
89
|
-
irb_eval output
|
90
|
-
end
|
91
|
-
|
92
|
-
it "activates default_pager when pager command is invalid" do
|
93
|
-
Pager.expects(:pager_command).returns(nil)
|
94
|
-
output = create_pageable_string(true)
|
95
|
-
Pager.expects(:default_pager).with(output.inspect, anything)
|
96
|
-
View.expects(:render_output).returns(false)
|
97
|
-
capture_stdout { irb_eval output }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# this mode is called within View.render_output
|
102
|
-
describe "in normal mode" do
|
103
|
-
it "activates when output is long enough" do
|
104
|
-
output = create_pageable_string
|
105
|
-
View.formatter.expects(:format_output).returns(output)
|
106
|
-
pager.expects(:page).with(output, false)
|
107
|
-
irb_eval(output)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "doesn't activate when output isn't long enough" do
|
111
|
-
output = "a\n"
|
112
|
-
View.formatter.expects(:format_output).returns(output)
|
113
|
-
pager.expects(:page).never
|
114
|
-
capture_stdout { irb_eval(output) }
|
115
|
-
end
|
116
|
-
|
117
|
-
it "activates with an explicit height" do
|
118
|
-
View.config[:height] = 100
|
119
|
-
output = create_pageable_string false, :height=>100
|
120
|
-
View.formatter.expects(:format_output).returns(output)
|
121
|
-
pager.expects(:page).with(output, false)
|
122
|
-
irb_eval(output)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "activates default_pager when pager_command is invalid" do
|
126
|
-
Pager.expects(:pager_command).returns(nil)
|
127
|
-
output = create_pageable_string
|
128
|
-
Pager.expects(:default_pager).with(output, anything)
|
129
|
-
View.formatter.expects(:format_output).returns(output)
|
130
|
-
capture_stdout { irb_eval output }
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "activates pager_command with valid pager_command option" do
|
135
|
-
View.config[:pager_command] = "less"
|
136
|
-
View.expects(:render_output).returns(false)
|
137
|
-
Util.expects(:command_exists?).returns(true)
|
138
|
-
Pager.expects(:command_pager)
|
139
|
-
irb_eval create_pageable_string(true)
|
140
|
-
View.config[:pager_command] = nil
|
141
|
-
end
|
142
|
-
|
143
|
-
it "activates pager_command with pager_command option that has command options" do
|
144
|
-
View.config[:pager_command] = "less -r"
|
145
|
-
View.expects(:render_output).returns(false)
|
146
|
-
Util.expects(:command_exists?).with('less').returns(true)
|
147
|
-
Pager.expects(:command_pager)
|
148
|
-
irb_eval create_pageable_string(true)
|
149
|
-
View.config[:pager_command] = nil
|
150
|
-
end
|
151
|
-
|
152
|
-
it "doesn't activate pager_command with invalid pager_command option" do
|
153
|
-
View.config[:pager_command] = "moreless"
|
154
|
-
View.expects(:render_output).returns(false)
|
155
|
-
Util.expects(:command_exists?).returns(false)
|
156
|
-
Pager.expects(:default_pager)
|
157
|
-
irb_eval create_pageable_string(true)
|
158
|
-
View.config[:pager_command] = nil
|
159
|
-
end
|
160
|
-
end
|
161
|
-
after_all { Hirb.disable }
|
162
|
-
end
|