hirb 0.3.1 → 0.3.2
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 +8 -2
- data/Rakefile +23 -41
- data/gemspec +20 -0
- data/lib/bond/completions/hirb.rb +14 -0
- data/lib/hirb.rb +0 -3
- data/lib/hirb/helpers/table.rb +1 -1
- data/lib/hirb/version.rb +1 -1
- data/test/auto_table_test.rb +25 -27
- data/test/bacon_extensions.rb +26 -0
- data/test/console_test.rb +7 -9
- data/test/dynamic_view_test.rb +71 -77
- data/test/formatter_test.rb +39 -37
- data/test/hirb_test.rb +8 -8
- data/test/import_test.rb +4 -4
- data/test/menu_test.rb +42 -42
- data/test/object_table_test.rb +65 -67
- data/test/pager_test.rb +133 -135
- data/test/resizer_test.rb +48 -47
- data/test/table_test.rb +69 -70
- data/test/test_helper.rb +11 -7
- data/test/tree_test.rb +34 -46
- data/test/util_test.rb +57 -59
- data/test/view_test.rb +138 -140
- data/test/views_test.rb +8 -10
- metadata +66 -36
data/test/hirb_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
before
|
3
|
+
describe "Hirb" do
|
4
|
+
before_all { Hirb.config_files = nil }
|
5
|
+
before { Hirb.config = nil }
|
6
6
|
|
7
|
-
|
7
|
+
it "config converts yaml when config file exists" do
|
8
8
|
yaml_data = {:blah=>'blah'}
|
9
9
|
File.stubs('exists?').returns(true)
|
10
10
|
Hirb.config_files = ['ok']
|
@@ -12,25 +12,25 @@ class HirbTest < Test::Unit::TestCase
|
|
12
12
|
Hirb.config.should == yaml_data
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "config defaults to hash when no config file" do
|
16
16
|
File.stubs('exists?').returns(false)
|
17
17
|
Hirb.config.should == {}
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it "config reloads if given explicit reload" do
|
21
21
|
Hirb.config
|
22
22
|
Hirb.expects(:read_config_file).returns({})
|
23
23
|
Hirb.config(true)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it "config reads multiple config files and merges them" do
|
27
27
|
Hirb.config_files = %w{one two}
|
28
28
|
Hirb.expects(:read_config_file).times(2).returns({:output=>{"String"=>:auto_table}}, {:output=>{"Array"=>:auto_table}})
|
29
29
|
Hirb.config.should == {:output=>{"Array"=>:auto_table, "String"=>:auto_table}}
|
30
30
|
Hirb.config_files = nil
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
it "config_file sets correctly when no ENV['HOME']" do
|
34
34
|
Hirb.config_files = nil
|
35
35
|
home = ENV.delete('HOME')
|
36
36
|
Hirb.config_files[0].class.should == String
|
data/test/import_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should
|
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
6
|
require 'hirb/import_object'
|
7
|
-
Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should
|
7
|
+
Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should == true
|
8
8
|
end
|
9
9
|
end
|
data/test/menu_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "Menu" do
|
4
|
+
before_all { View.instance_variable_set("@config", :width=>Hirb::View::DEFAULT_WIDTH) }
|
5
5
|
|
6
6
|
def menu(*args, &block)
|
7
|
-
# testing via menu's main use case (through console) instead of
|
7
|
+
# testing via menu's main use case (through console) instead of Menu.render
|
8
8
|
@console ||= Object.new.extend(Hirb::Console)
|
9
9
|
@console.menu(*args, &block)
|
10
10
|
end
|
@@ -18,8 +18,8 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
18
18
|
$stdin.expects(:gets).returns(input)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
describe "menu" do
|
22
|
+
it "by default renders table menu" do
|
23
23
|
expected_menu = <<-MENU.unindent
|
24
24
|
+--------+-------+
|
25
25
|
| number | value |
|
@@ -33,7 +33,7 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
33
33
|
basic_menu([1,2,3]).include?(expected_menu).should == true
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
it "with block renders" do
|
37
37
|
menu_input "1,2"
|
38
38
|
expected_result = [1,2]
|
39
39
|
capture_stdout {
|
@@ -41,7 +41,7 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
it "with block and no chosen doesn't call block" do
|
45
45
|
menu_input ""
|
46
46
|
block = lambda {|e| @called = true }
|
47
47
|
capture_stdout {
|
@@ -50,12 +50,12 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
50
50
|
assert !@called
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
it "with valid helper_class option renders" do
|
54
|
+
Helpers::Table.expects(:render)
|
55
55
|
basic_menu [1,2,3], :helper_class=>"Hirb::Helpers::Table"
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
it "with invalid helper_class option renders default menu" do
|
59
59
|
expected_menu = <<-MENU.unindent
|
60
60
|
1: 1
|
61
61
|
2: 2
|
@@ -64,7 +64,7 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
64
64
|
basic_menu([1,2,3], :helper_class=>"SomeHelper").include?(expected_menu).should == true
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
it "with false helper_class option renders default menu" do
|
68
68
|
expected_menu = <<-MENU.unindent
|
69
69
|
1: 1
|
70
70
|
2: 2
|
@@ -73,30 +73,30 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
73
73
|
basic_menu([1,2,3], :helper_class=>false).include?(expected_menu).should == true
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
it "prints prompt option" do
|
77
77
|
prompt = "Input or else ..."
|
78
78
|
basic_menu([1,2,3], :prompt=>prompt).include?(prompt).should == true
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
it "converts non-array inputs to array" do
|
82
|
+
Helpers::AutoTable.expects(:render).with([1], anything)
|
83
83
|
basic_menu 1
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
it "with false ask option returns one choice without asking" do
|
87
87
|
$stdin.expects(:gets).never
|
88
88
|
menu([1], :ask=>false).should == [1]
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
it "with no items to choose from always return without asking" do
|
92
92
|
$stdin.expects(:gets).never
|
93
93
|
menu([], :ask=>false).should == []
|
94
94
|
menu([], :ask=>true).should == []
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
it "with directions option turns off directions" do
|
98
98
|
menu_input('blah')
|
99
|
-
capture_stdout { menu([1], :directions=>false) }.
|
99
|
+
capture_stdout { menu([1], :directions=>false) }.should.not =~ /range.*all/
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -104,7 +104,7 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
104
104
|
if options[:invokes] || options[:invoke]
|
105
105
|
cmd = options[:command] || 'p'
|
106
106
|
(options[:invokes] || [options[:invoke]]).each {|e|
|
107
|
-
|
107
|
+
Menu.any_instance.expects(:invoke).with(cmd, e)
|
108
108
|
}
|
109
109
|
end
|
110
110
|
|
@@ -114,107 +114,107 @@ class Hirb::MenuTest < Test::Unit::TestCase
|
|
114
114
|
}
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
describe "2d menu" do
|
118
|
+
it "with default field from last_table renders" do
|
119
119
|
menu_input "1"
|
120
120
|
two_d_menu.should == [1]
|
121
121
|
end
|
122
122
|
|
123
|
-
|
123
|
+
it "with default field from fields option renders" do
|
124
124
|
menu_input "1"
|
125
125
|
two_d_menu(:fields=>[:bro, :a]).should == [2]
|
126
126
|
end
|
127
127
|
|
128
|
-
|
128
|
+
it "with default field option renders" do
|
129
129
|
menu_input "1"
|
130
130
|
two_d_menu(:default_field=>:bro).should == [2]
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
it "with non-table helper class renders" do
|
134
134
|
menu_input "1"
|
135
135
|
two_d_menu(:helper_class=>false, :fields=>[:a,:bro]).should == [1]
|
136
136
|
end
|
137
137
|
|
138
|
-
|
138
|
+
it "with no default field prints error" do
|
139
139
|
menu_input "1"
|
140
140
|
capture_stderr { two_d_menu(:fields=>[]) }.should =~ /No default.*found/
|
141
141
|
end
|
142
142
|
|
143
|
-
|
143
|
+
it "with invalid field prints error" do
|
144
144
|
menu_input "1:z"
|
145
145
|
capture_stderr { two_d_menu }.should =~ /Invalid.*'z'/
|
146
146
|
end
|
147
147
|
|
148
|
-
|
148
|
+
it "with choice from abbreviated field" do
|
149
149
|
menu_input "2:b"
|
150
150
|
two_d_menu.should == [4]
|
151
151
|
end
|
152
152
|
|
153
|
-
|
153
|
+
it "with choices from multiple fields renders" do
|
154
154
|
menu_input "1 2:bro"
|
155
155
|
two_d_menu.should == [1,4]
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
describe "action menu" do
|
160
|
+
it "invokes" do
|
161
161
|
menu_input "p 1 2:bro"
|
162
162
|
two_d_menu(:action=>true, :invoke=>[[1,4]])
|
163
163
|
end
|
164
164
|
|
165
|
-
|
165
|
+
it "with 1d invokes" do
|
166
166
|
menu_input "p 1"
|
167
167
|
two_d_menu(:action=>true, :two_d=>nil, :invoke=>[[{:a=>1, :bro=>2}]])
|
168
168
|
end
|
169
169
|
|
170
|
-
|
170
|
+
it "with non-choice arguments invokes" do
|
171
171
|
menu_input "p arg1 1"
|
172
172
|
two_d_menu :action=>true, :invoke=>['arg1', [1]]
|
173
173
|
end
|
174
174
|
|
175
|
-
|
175
|
+
it "with multiple choice arguments flattens them into arg" do
|
176
176
|
menu_input "p arg1 1 2:bro arg2"
|
177
177
|
two_d_menu :action=>true, :invoke=>['arg1', [1,4], 'arg2']
|
178
178
|
end
|
179
179
|
|
180
|
-
|
180
|
+
it "with nothing chosen prints error" do
|
181
181
|
menu_input "cmd"
|
182
182
|
capture_stderr { two_d_menu(:action=>true) }.should =~ /No rows chosen/
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
it "with no command given prints error" do
|
186
186
|
menu_input "1"
|
187
187
|
capture_stderr { two_d_menu(:action=>true) }.should =~ /No command given/
|
188
188
|
end
|
189
189
|
|
190
|
-
|
190
|
+
it "with multi_action option invokes" do
|
191
191
|
menu_input "p 1 2:bro"
|
192
192
|
two_d_menu(:action=>true, :multi_action=>true, :invokes=>[[1], [4]])
|
193
193
|
end
|
194
194
|
|
195
|
-
|
195
|
+
it "with command option invokes" do
|
196
196
|
menu_input "1"
|
197
197
|
two_d_menu(:action=>true, :command=>'p', :invoke=>[[1]])
|
198
198
|
end
|
199
199
|
|
200
|
-
|
201
|
-
|
200
|
+
it "with command option and empty input doesn't invoke action and exists silently" do
|
201
|
+
Menu.any_instance.expects(:invoke).never
|
202
202
|
menu_input ""
|
203
203
|
two_d_menu(:action=>true, :command=>'p').should == nil
|
204
204
|
end
|
205
205
|
|
206
|
-
|
206
|
+
it "with action_object option invokes" do
|
207
207
|
obj = mock(:blah=>true)
|
208
208
|
menu_input "blah 1"
|
209
209
|
two_d_menu(:action=>true, :action_object=>obj)
|
210
210
|
end
|
211
211
|
|
212
|
-
|
212
|
+
it "with ask false and defaults invokes" do
|
213
213
|
two_d_menu(:output=>[{:a=>1, :bro=>2}], :action=>true, :ask=>false, :default_field=>:a,
|
214
214
|
:command=>'p', :invoke=>[[1]])
|
215
215
|
end
|
216
216
|
|
217
|
-
|
217
|
+
it "with ask false and no defaults prints error" do
|
218
218
|
capture_stderr {
|
219
219
|
two_d_menu(:output=>[{:a=>1, :bro=>2}], :action=>true, :ask=>false, :command=>'p')
|
220
220
|
}.should =~ /Default.*required/
|
data/test/object_table_test.rb
CHANGED
@@ -1,75 +1,73 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
describe "object table" do
|
4
|
+
def table(*args)
|
5
|
+
Helpers::ObjectTable.render(*args)
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
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
|
74
72
|
end
|
75
73
|
end
|
data/test/pager_test.rb
CHANGED
@@ -1,164 +1,162 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
seed * (size[:height] + 1)
|
14
|
-
end
|
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)
|
15
13
|
end
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
37
|
end
|
22
38
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Pager.
|
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
|
27
56
|
end
|
57
|
+
after_all { Hirb.disable }
|
58
|
+
end
|
28
59
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
68
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
output
|
38
|
-
|
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
|
39
76
|
end
|
40
77
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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")
|
45
82
|
end
|
46
83
|
|
47
|
-
|
48
|
-
|
49
|
-
output =
|
50
|
-
|
51
|
-
|
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
|
52
90
|
end
|
53
91
|
|
54
|
-
|
55
|
-
|
56
|
-
output =
|
57
|
-
|
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 }
|
58
98
|
end
|
59
99
|
end
|
60
100
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
::IRB::Irb.new(context_stub).output_value
|
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)
|
69
108
|
end
|
70
109
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
View.expects(:render_output).returns(false)
|
77
|
-
irb_eval output
|
78
|
-
end
|
79
|
-
|
80
|
-
test "doesn't activate when output isn't wide enough" do
|
81
|
-
pager.expects(:page).never
|
82
|
-
View.expects(:render_output).returns(false)
|
83
|
-
irb_eval("a")
|
84
|
-
end
|
85
|
-
|
86
|
-
test "activates with an explicit width" do
|
87
|
-
View.config[:width] = 10
|
88
|
-
output = create_pageable_string true, :width=>10
|
89
|
-
pager.expects(:page).with(output.inspect, true)
|
90
|
-
View.expects(:render_output).returns(false)
|
91
|
-
irb_eval output
|
92
|
-
end
|
93
|
-
|
94
|
-
test "activates default_pager when pager command is invalid" do
|
95
|
-
Pager.expects(:pager_command).returns(nil)
|
96
|
-
output = create_pageable_string(true)
|
97
|
-
Pager.expects(:default_pager).with(output.inspect, anything)
|
98
|
-
View.expects(:render_output).returns(false)
|
99
|
-
capture_stdout { irb_eval output }
|
100
|
-
end
|
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) }
|
101
115
|
end
|
102
116
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
irb_eval(output)
|
110
|
-
end
|
111
|
-
|
112
|
-
test "doesn't activate when output isn't long enough" do
|
113
|
-
output = "a\n"
|
114
|
-
View.formatter.expects(:format_output).returns(output)
|
115
|
-
pager.expects(:page).never
|
116
|
-
capture_stdout { irb_eval(output) }
|
117
|
-
end
|
118
|
-
|
119
|
-
test "activates with an explicit height" do
|
120
|
-
View.config[:height] = 100
|
121
|
-
output = create_pageable_string false, :height=>100
|
122
|
-
View.formatter.expects(:format_output).returns(output)
|
123
|
-
pager.expects(:page).with(output, false)
|
124
|
-
irb_eval(output)
|
125
|
-
end
|
126
|
-
|
127
|
-
test "activates default_pager when pager_command is invalid" do
|
128
|
-
Pager.expects(:pager_command).returns(nil)
|
129
|
-
output = create_pageable_string
|
130
|
-
Pager.expects(:default_pager).with(output, anything)
|
131
|
-
View.formatter.expects(:format_output).returns(output)
|
132
|
-
capture_stdout { irb_eval output }
|
133
|
-
end
|
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)
|
134
123
|
end
|
135
124
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
irb_eval
|
142
|
-
View.config[:pager_command] = nil
|
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 }
|
143
131
|
end
|
132
|
+
end
|
144
133
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
153
142
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
162
159
|
end
|
163
160
|
end
|
164
|
-
|
161
|
+
after_all { Hirb.disable }
|
162
|
+
end
|