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/test_helper.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'context' #gem install jeremymcanally-context -s http://gems.github.com
|
4
|
-
require 'matchy' #gem install jeremymcanally-matchy -s http://gems.github.com
|
1
|
+
require 'bacon'
|
2
|
+
require File.dirname(__FILE__)+'/bacon_extensions'
|
5
3
|
require 'mocha'
|
6
|
-
|
4
|
+
require 'mocha-on-bacon'
|
7
5
|
require 'hirb'
|
6
|
+
include Hirb
|
8
7
|
|
9
|
-
|
8
|
+
module TestHelpers
|
10
9
|
# set these to avoid invoking stty multiple times which doubles test suite running time
|
11
10
|
ENV["LINES"] = ENV["COLUMNS"] = "20"
|
12
11
|
def reset_terminal_size
|
@@ -36,10 +35,15 @@ class Test::Unit::TestCase
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def reset_config
|
39
|
-
|
38
|
+
View.instance_eval "@config = nil"
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
42
|
+
class Bacon::Context
|
43
|
+
include TestHelpers
|
44
|
+
include BaconExtensions
|
45
|
+
end
|
46
|
+
|
43
47
|
class String
|
44
48
|
def unindent(num=nil)
|
45
49
|
regex = num ? /^\s{#{num}}/ : /^\s*/
|
data/test/tree_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
3
|
+
describe "Tree helpers:" do
|
4
4
|
def tree(*args)
|
5
|
-
|
5
|
+
Helpers::Tree.render(*args)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
describe "basic tree" do
|
9
|
+
it "with hash nodes renders" do
|
10
10
|
expected_tree = <<-TREE.unindent(6)
|
11
11
|
0.0
|
12
12
|
1.1
|
@@ -18,7 +18,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
18
18
|
{:level=>1, :value=>'4.1'}]).should == expected_tree
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
it "with array nodes renders" do
|
22
22
|
expected_tree = <<-TREE.unindent(6)
|
23
23
|
0.0
|
24
24
|
1.1
|
@@ -29,7 +29,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
29
29
|
tree([[0, "0.0"], [1, "1.1"], [2, "2.2"], [2, "3.2"], [1, "4.1"]]).should == expected_tree
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "with non-string values renders" do
|
33
33
|
expected_tree = <<-TREE.unindent(6)
|
34
34
|
0.0
|
35
35
|
1.1
|
@@ -40,7 +40,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
40
40
|
tree([[0,0.0],[1,1.1],[2,2.2],[2,3.2],[1,4.1]]).should == expected_tree
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
it "with indent option renders" do
|
44
44
|
expected_tree = <<-TREE.unindent(6)
|
45
45
|
0.0
|
46
46
|
1.1
|
@@ -51,7 +51,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
51
51
|
tree([[0, "0.0"], [1, "1.1"], [2, "2.2"], [2, "3.2"], [1, "4.1"]], :indent=>2).should == expected_tree
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
it "with limit option renders" do
|
55
55
|
expected_tree = <<-TREE.unindent(6)
|
56
56
|
0.0
|
57
57
|
1.1
|
@@ -60,7 +60,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
60
60
|
tree([[0, "0.0"], [1, "1.1"], [2, "2.2"], [2, "3.2"], [1, "4.1"]], :limit=>1).should == expected_tree
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
it "with description option renders" do
|
64
64
|
expected_tree = <<-TREE.unindent(6)
|
65
65
|
0.0
|
66
66
|
1.1
|
@@ -73,7 +73,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
73
73
|
tree([[0, "0.0"], [1, "1.1"], [2, "2.2"], [2, "3.2"], [1, "4.1"]], :description=>true).should == expected_tree
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
it "with type directory renders" do
|
77
77
|
expected_tree = <<-TREE.unindent
|
78
78
|
0.0
|
79
79
|
|-- 1.1
|
@@ -84,7 +84,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
84
84
|
tree([[0, "0.0"], [1, "1.1"], [2, "2.2"], [2, "3.2"], [1, "4.1"]], :type=>:directory).should == expected_tree
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
it "with type directory and multiple children per level renders" do
|
88
88
|
expected_tree = <<-TREE.unindent
|
89
89
|
0.0
|
90
90
|
|-- 1.1
|
@@ -97,19 +97,19 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
97
97
|
tree([[0,'0.0'], [1,'1.1'], [2,'2.2'],[3,'3.3'],[2,'4.2'],[3,'5.3'],[1,'6.1']], :type=>:directory).should == expected_tree
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
it "with type number renders" do
|
101
101
|
expected_tree = <<-TREE.unindent(6)
|
102
102
|
1. 0
|
103
103
|
1. 1
|
104
104
|
1. 2
|
105
105
|
2. 3
|
106
|
-
2. 4
|
106
|
+
2. 4
|
107
107
|
TREE
|
108
|
-
tree([[0,'0'],[1,'1'],[2,'2'],[2,'3'],[1,'4']], :type=>:number)
|
108
|
+
tree([[0,'0'],[1,'1'],[2,'2'],[2,'3'],[1,'4']], :type=>:number).should == expected_tree
|
109
109
|
end
|
110
110
|
|
111
|
-
|
112
|
-
expected_tree = <<-TREE.unindent
|
111
|
+
it "with multi-line nodes option renders" do
|
112
|
+
expected_tree = <<-TREE.unindent(6)
|
113
113
|
parent
|
114
114
|
+-------+
|
115
115
|
| value |
|
@@ -122,7 +122,7 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
122
122
|
stuff
|
123
123
|
TREE
|
124
124
|
node1 = "+-------+\n| value |\n+-------+\n| 1 |\n| 2 |\n| 3 |\n+-------+"
|
125
|
-
tree([ [0, 'parent'],[1, node1],[2, "indented\nstuff"]], :multi_line_nodes=>true)
|
125
|
+
tree([ [0, 'parent'],[1, node1],[2, "indented\nstuff"]], :multi_line_nodes=>true).should == expected_tree
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -132,8 +132,8 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
132
132
|
mock(value_method=>value, :children=>children.map {|e| mock_node(e, value_method)})
|
133
133
|
end
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
describe "parent_child_tree" do
|
136
|
+
it "with name value renders" do
|
137
137
|
expected_tree = <<-TREE.unindent
|
138
138
|
0.0
|
139
139
|
|-- 1.1
|
@@ -141,23 +141,11 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
141
141
|
| `-- 3.2
|
142
142
|
`-- 4.1
|
143
143
|
TREE
|
144
|
-
root = mock_node(['0.0', ['1.1', ['2.1', '3.2'], '4.1']], :name)
|
145
|
-
|
144
|
+
root = mock_node(['0.0', ['1.1', ['2.1', ['3.2']], '4.1']], :name)
|
145
|
+
Helpers::ParentChildTree.render(root, :type=>:directory).should == expected_tree
|
146
146
|
end
|
147
147
|
|
148
|
-
|
149
|
-
expected_tree = <<-TREE.unindent
|
150
|
-
0.0
|
151
|
-
|-- 1.1
|
152
|
-
|-- 2.1
|
153
|
-
| `-- 3.2
|
154
|
-
`-- 4.1
|
155
|
-
TREE
|
156
|
-
root = mock_node(['0.0', ['1.1', ['2.1', '3.2'], '4.1']], :object_id)
|
157
|
-
Hirb::Helpers::ParentChildTree.render(root, :type=>:directory).should == expected_tree
|
158
|
-
end
|
159
|
-
|
160
|
-
test "with value_method option renders" do
|
148
|
+
it "with value_method option renders" do
|
161
149
|
expected_tree = <<-TREE.unindent
|
162
150
|
0.0
|
163
151
|
|-- 1.1
|
@@ -165,11 +153,11 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
165
153
|
| `-- 3.2
|
166
154
|
`-- 4.1
|
167
155
|
TREE
|
168
|
-
root = mock_node(['0.0', ['1.1', ['2.1', '3.2'], '4.1']], :blah)
|
169
|
-
|
156
|
+
root = mock_node(['0.0', ['1.1', ['2.1', ['3.2']], '4.1']], :blah)
|
157
|
+
Helpers::ParentChildTree.render(root, :type=>:directory, :value_method=>:blah).should == expected_tree
|
170
158
|
end
|
171
159
|
|
172
|
-
|
160
|
+
it "with children_method proc option renders" do
|
173
161
|
expected_tree = <<-TREE.unindent
|
174
162
|
1
|
175
163
|
|-- 2
|
@@ -177,20 +165,20 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
177
165
|
|-- 4
|
178
166
|
`-- 5
|
179
167
|
TREE
|
180
|
-
|
181
|
-
:children_method=>lambda {|e| e == 1 ? (2..5).to_a : []}, :value_method=>:to_s)
|
168
|
+
Helpers::ParentChildTree.render(1, :type=>:directory,
|
169
|
+
:children_method=>lambda {|e| e == 1 ? (2..5).to_a : []}, :value_method=>:to_s).should == expected_tree
|
182
170
|
end
|
183
171
|
end
|
184
172
|
|
185
|
-
|
186
|
-
|
173
|
+
it "tree with parentless nodes renders ParentlessNodeError" do
|
174
|
+
lambda { tree([[0, "0.0"], [2, '1.2']], :validate=>true) }.should.raise(Helpers::Tree::ParentlessNodeError)
|
187
175
|
end
|
188
176
|
|
189
|
-
|
190
|
-
|
177
|
+
it "tree with hash nodes missing level raises MissingLevelError" do
|
178
|
+
lambda { tree([{:value=>'ok'}]) }.should.raise(Helpers::Tree::Node::MissingLevelError)
|
191
179
|
end
|
192
180
|
|
193
|
-
|
194
|
-
|
181
|
+
it "tree with hash nodes missing level raises MissingValueError" do
|
182
|
+
lambda { tree([{:level=>0}]) }.should.raise(Helpers::Tree::Node::MissingValueError)
|
195
183
|
end
|
196
|
-
end
|
184
|
+
end
|
data/test/util_test.rb
CHANGED
@@ -1,61 +1,59 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
3
|
+
describe "Util" do
|
4
|
+
it "camelize converts underscore lowercase to camelcase" do
|
5
|
+
Util.camelize('hirb/util').should == "Hirb::Util"
|
6
|
+
Util.camelize('hirb_hash').should == "HirbHash"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "any_const_get returns nested class" do
|
10
|
+
Util.any_const_get("YAML::BaseNode").should == ::YAML::BaseNode
|
11
|
+
end
|
12
|
+
|
13
|
+
it "any_const_get returns nil for invalid class" do
|
14
|
+
Util.any_const_get("Basdfr").should == nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "any_const_get returns class when given class" do
|
18
|
+
Util.any_const_get(String).should == String
|
19
|
+
end
|
20
|
+
|
21
|
+
it "recursive_hash_merge merges" do
|
22
|
+
expected_hash = {:output=>{:fields=>["f1", "f2"], :method=>"blah"}, :key1=>"hash1", :key2=>"hash2"}
|
23
|
+
Util.recursive_hash_merge({:output=>{:fields=>%w{f1 f2}}, :key1=>'hash1'},
|
24
|
+
{:output=>{:method=>'blah'}, :key2=>'hash2'}).should == expected_hash
|
25
|
+
end
|
26
|
+
|
27
|
+
it "choose_from_array specifies range with -" do
|
28
|
+
Util.choose_from_array([1,2,3,4], '1-2,4').should == [1,2,4]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "choose_from_array specifies range with .." do
|
32
|
+
Util.choose_from_array([1,2,3,4], '1 .. 2,4').should == [1,2,4]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "choose_from_array chooses all with *" do
|
36
|
+
Util.choose_from_array([1,2,3,4], '*').should == [1,2,3,4]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "choose_from_array ignores non-numerical input" do
|
40
|
+
Util.choose_from_array([1,2,3,4], 'a,2').should == [2]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "choose_from_array ignores 0" do
|
44
|
+
Util.choose_from_array([1,2,3,4], '0,2').should == [2]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "choose_from_array returns empty when empty input" do
|
48
|
+
Util.choose_from_array([1,2,3,4], "\n").should == []
|
49
|
+
end
|
50
|
+
|
51
|
+
it "choose_from_array returns empty with an invalid range" do
|
52
|
+
Util.choose_from_array([1,2,3,4], "5").should == []
|
53
|
+
end
|
54
|
+
|
55
|
+
it "capture_stdout" do
|
56
|
+
string = "sweetness man"
|
57
|
+
Util.capture_stdout { puts string }.should == string + "\n"
|
58
|
+
end
|
59
|
+
end
|
data/test/view_test.rb
CHANGED
@@ -1,168 +1,166 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
describe "View" do
|
4
|
+
def formatter_config
|
5
|
+
View.formatter.config
|
6
|
+
end
|
7
|
+
|
8
|
+
it "page_output pages when view is enabled" do
|
9
|
+
Hirb.enable
|
10
|
+
View.pager.stubs(:activated_by?).returns(true)
|
11
|
+
View.pager.expects(:page)
|
12
|
+
View.page_output('blah').should == true
|
13
|
+
Hirb.disable
|
14
|
+
end
|
15
|
+
|
16
|
+
it "page_output doesn't page when view is disabled" do
|
17
|
+
Hirb.enable
|
18
|
+
Hirb.disable
|
19
|
+
View.pager.stubs(:activated_by?).returns(true)
|
20
|
+
View.pager.expects(:page).never
|
21
|
+
View.page_output('blah').should == false
|
22
|
+
end
|
16
23
|
|
17
|
-
|
24
|
+
it "view_output catches unexpected errors and prints them" do
|
25
|
+
reset_config
|
26
|
+
Hirb.enable
|
27
|
+
View.expects(:render_output).raises('blah')
|
28
|
+
capture_stderr { View.view_output([1,2,3]) }.should =~ /Hirb Error: blah/
|
29
|
+
Hirb.disable
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "enable" do
|
33
|
+
before { reset_config }
|
34
|
+
after { Hirb.disable }
|
35
|
+
it "redefines irb output_value" do
|
36
|
+
View.expects(:render_output).once
|
18
37
|
Hirb.enable
|
19
|
-
|
20
|
-
|
21
|
-
View.pager.expects(:page).never
|
22
|
-
View.page_output('blah').should be(false)
|
38
|
+
context_stub = stub(:last_value=>'')
|
39
|
+
::IRB::Irb.new(context_stub).output_value
|
23
40
|
end
|
24
41
|
|
25
|
-
|
26
|
-
reset_config
|
42
|
+
it "is enabled?" do
|
27
43
|
Hirb.enable
|
28
|
-
View.
|
29
|
-
capture_stderr { View.view_output([1,2,3]) }.should =~ /Hirb Error: blah/
|
30
|
-
Hirb.disable
|
44
|
+
View.enabled?.should == true
|
31
45
|
end
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
after(:each) { Hirb.disable }
|
36
|
-
test "redefines irb output_value" do
|
37
|
-
View.expects(:render_output).once
|
38
|
-
Hirb.enable
|
39
|
-
context_stub = stub(:last_value=>'')
|
40
|
-
::IRB::Irb.new(context_stub).output_value
|
41
|
-
end
|
42
|
-
|
43
|
-
test "is enabled?" do
|
44
|
-
Hirb.enable
|
45
|
-
assert View.enabled?
|
46
|
-
end
|
47
|
-
|
48
|
-
def output_class_config(klass)
|
49
|
-
{ :output=>{klass=>{:class=>:auto_table}} }
|
50
|
-
end
|
51
|
-
|
52
|
-
test "sets formatter config" do
|
53
|
-
class_hash = {"Something::Base"=>{:class=>"BlahBlah"}}
|
54
|
-
Hirb.enable :output=>class_hash
|
55
|
-
View.formatter_config['Something::Base'].should == class_hash['Something::Base']
|
56
|
-
end
|
57
|
-
|
58
|
-
test "when called multiple times merges configs" do
|
59
|
-
Hirb.config = nil
|
60
|
-
# default config + config_file
|
61
|
-
Hirb.expects(:read_config_file).returns(output_class_config('Regexp'))
|
62
|
-
Hirb.enable output_class_config('String')
|
63
|
-
|
64
|
-
# add config file and explicit config
|
65
|
-
[{:config_file=>'ok'}, output_class_config('Struct')].each do |config|
|
66
|
-
Hirb.expects(:read_config_file).times(2).returns(
|
67
|
-
output_class_config('ActiveRecord::Base'), output_class_config('Array'))
|
68
|
-
Hirb.enable config
|
69
|
-
end
|
70
|
-
|
71
|
-
Hirb.config_files.include?('ok').should == true
|
72
|
-
output_keys = %w{ActiveRecord::Base Array Regexp String Struct}
|
73
|
-
Hirb::View.config[:output].keys.sort.should == output_keys
|
74
|
-
end
|
75
|
-
|
76
|
-
test "when called multiple times without config doesn't affect config" do
|
77
|
-
Hirb.enable
|
78
|
-
old_config = Hirb::View.config
|
79
|
-
Hirb.expects(:read_config_file).never
|
80
|
-
Hirb::View.expects(:load_config).never
|
81
|
-
Hirb.enable
|
82
|
-
Hirb::View.config.should == old_config
|
83
|
-
end
|
84
|
-
|
85
|
-
test "works without irb" do
|
86
|
-
Object.stubs(:const_defined?).with(:IRB).returns(false)
|
87
|
-
Hirb.enable
|
88
|
-
assert formatter_config.size > 0
|
89
|
-
end
|
90
|
-
|
91
|
-
test "with config_file option adds to config_file" do
|
92
|
-
Hirb.enable :config_file=> 'test_file'
|
93
|
-
Hirb.config_files.include?('test_file').should == true
|
94
|
-
end
|
95
|
-
|
96
|
-
test "with output_method option realiases output_method" do
|
97
|
-
eval %[module ::Mini; extend self; def output(str); puts(str.inspect); end; end]
|
98
|
-
Hirb.enable :output_method=>"Mini.output", :output=>{"Symbol"=>{:output_method=>lambda {|e| e.to_s }}}
|
99
|
-
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
100
|
-
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
101
|
-
end
|
47
|
+
def output_class_config(klass)
|
48
|
+
{ :output=>{klass=>{:class=>:auto_table}} }
|
102
49
|
end
|
103
50
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
Util.expects(:command_exists?).with('stty').returns(true)
|
110
|
-
ENV['COLUMNS'] = ENV['LINES'] = nil # bypasses env usage
|
111
|
-
View.resize
|
112
|
-
pager.width.should_not == 10
|
113
|
-
pager.height.should_not == 10
|
114
|
-
reset_terminal_size
|
115
|
-
end
|
51
|
+
it "sets formatter config" do
|
52
|
+
class_hash = {"Something::Base"=>{:class=>"BlahBlah"}}
|
53
|
+
Hirb.enable :output=>class_hash
|
54
|
+
View.formatter_config['Something::Base'].should == class_hash['Something::Base']
|
55
|
+
end
|
116
56
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
57
|
+
it "when called multiple times merges configs" do
|
58
|
+
Hirb.config = nil
|
59
|
+
# default config + config_file
|
60
|
+
Hirb.expects(:read_config_file).returns(output_class_config('Regexp'))
|
61
|
+
Hirb.enable output_class_config('String')
|
62
|
+
|
63
|
+
# add config file and explicit config
|
64
|
+
[{:config_file=>'ok'}, output_class_config('Struct')].each do |config|
|
65
|
+
Hirb.expects(:read_config_file).times(2).returns(
|
66
|
+
output_class_config('ActiveRecord::Base'), output_class_config('Array'))
|
67
|
+
Hirb.enable config
|
122
68
|
end
|
123
69
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
ENV['COLUMNS'] = ENV['LINES'] = nil
|
128
|
-
View.resize
|
129
|
-
pager.width.is_a?(Integer).should be(true)
|
130
|
-
pager.height.is_a?(Integer).should be(true)
|
131
|
-
reset_terminal_size
|
132
|
-
end
|
70
|
+
Hirb.config_files.include?('ok').should == true
|
71
|
+
output_keys = %w{ActiveRecord::Base Array Regexp String Struct}
|
72
|
+
View.config[:output].keys.sort.should == output_keys
|
133
73
|
end
|
134
74
|
|
135
|
-
|
136
|
-
View.expects(:render_output).never
|
75
|
+
it "when called multiple times without config doesn't affect config" do
|
137
76
|
Hirb.enable
|
138
|
-
|
139
|
-
|
140
|
-
|
77
|
+
old_config = View.config
|
78
|
+
Hirb.expects(:read_config_file).never
|
79
|
+
View.expects(:load_config).never
|
80
|
+
Hirb.enable
|
81
|
+
View.config.should == old_config
|
141
82
|
end
|
142
83
|
|
143
|
-
|
84
|
+
it "works without irb" do
|
144
85
|
Object.stubs(:const_defined?).with(:IRB).returns(false)
|
145
86
|
Hirb.enable
|
146
|
-
|
147
|
-
|
87
|
+
formatter_config.size.should.be > 0
|
88
|
+
end
|
89
|
+
|
90
|
+
it "with config_file option adds to config_file" do
|
91
|
+
Hirb.enable :config_file=> 'test_file'
|
92
|
+
Hirb.config_files.include?('test_file').should == true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "with output_method option realiases output_method" do
|
96
|
+
eval %[module ::Mini; extend self; def output(str); puts(str.inspect); end; end]
|
97
|
+
Hirb.enable :output_method=>"Mini.output", :output=>{"Symbol"=>{:output_method=>lambda {|e| e.to_s }}}
|
98
|
+
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
99
|
+
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
148
100
|
end
|
101
|
+
end
|
149
102
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
103
|
+
describe "resize" do
|
104
|
+
def pager; View.pager; end
|
105
|
+
before { View.pager = nil; reset_config; Hirb.enable }
|
106
|
+
after { Hirb.disable}
|
107
|
+
it "changes width and height with stty" do
|
108
|
+
Util.expects(:command_exists?).with('stty').returns(true)
|
109
|
+
ENV['COLUMNS'] = ENV['LINES'] = nil # bypasses env usage
|
110
|
+
View.resize
|
111
|
+
pager.width.should.not == 10
|
112
|
+
pager.height.should.not == 10
|
113
|
+
reset_terminal_size
|
154
114
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
View.
|
159
|
-
|
115
|
+
|
116
|
+
it "changes width and height with ENV" do
|
117
|
+
ENV['COLUMNS'] = ENV['LINES'] = '10' # simulates resizing
|
118
|
+
View.resize
|
119
|
+
pager.width.should == 10
|
120
|
+
pager.height.should == 10
|
160
121
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
122
|
+
|
123
|
+
it "with no environment or stty still has valid width and height" do
|
124
|
+
View.config[:width] = View.config[:height] = nil
|
125
|
+
Util.expects(:command_exists?).with('stty').returns(false)
|
126
|
+
ENV['COLUMNS'] = ENV['LINES'] = nil
|
127
|
+
View.resize
|
128
|
+
pager.width.is_a?(Integer).should == true
|
129
|
+
pager.height.is_a?(Integer).should == true
|
130
|
+
reset_terminal_size
|
166
131
|
end
|
167
132
|
end
|
133
|
+
|
134
|
+
it "disable points output_value back to original output_value" do
|
135
|
+
View.expects(:render_output).never
|
136
|
+
Hirb.enable
|
137
|
+
Hirb.disable
|
138
|
+
context_stub = stub(:last_value=>'')
|
139
|
+
::IRB::Irb.new(context_stub).output_value
|
140
|
+
end
|
141
|
+
|
142
|
+
it "disable works without irb defined" do
|
143
|
+
Object.stubs(:const_defined?).with(:IRB).returns(false)
|
144
|
+
Hirb.enable
|
145
|
+
Hirb.disable
|
146
|
+
View.enabled?.should == false
|
147
|
+
end
|
148
|
+
|
149
|
+
it "capture_and_render" do
|
150
|
+
string = 'no waaaay'
|
151
|
+
View.render_method.expects(:call).with(string)
|
152
|
+
View.capture_and_render { print string }
|
153
|
+
end
|
154
|
+
|
155
|
+
it "state is toggled by toggle_pager" do
|
156
|
+
previous_state = View.config[:pager]
|
157
|
+
View.toggle_pager
|
158
|
+
View.config[:pager].should == !previous_state
|
159
|
+
end
|
160
|
+
|
161
|
+
it "state is toggled by toggle_formatter" do
|
162
|
+
previous_state = View.config[:formatter]
|
163
|
+
View.toggle_formatter
|
164
|
+
View.config[:formatter].should == !previous_state
|
165
|
+
end
|
168
166
|
end
|