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.
@@ -1,10 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class HirbTest < Test::Unit::TestCase
4
- before(:all) { Hirb.config_files = nil }
5
- before(:each) { Hirb.config = nil }
3
+ describe "Hirb" do
4
+ before_all { Hirb.config_files = nil }
5
+ before { Hirb.config = nil }
6
6
 
7
- test "config converts yaml when config file exists" do
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
- test "config defaults to hash when no config file" do
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
- test "config reloads if given explicit reload" do
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
- test "config reads multiple config files and merges them" do
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
- test "config_file sets correctly when no ENV['HOME']" do
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
@@ -1,9 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class Hirb::ImportTest < Test::Unit::TestCase
4
- test "require import_object extends Object" do
5
- Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should be(false)
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 be(true)
7
+ Object.ancestors.map {|e| e.to_s}.include?("Hirb::ObjectMethods").should == true
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class Hirb::MenuTest < Test::Unit::TestCase
4
- before(:all) { Hirb::View.instance_variable_set("@config", :width=>Hirb::View::DEFAULT_WIDTH) }
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 Hirb::Menu.render
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
- context "menu" do
22
- test "by default renders table menu" do
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
- test "with block renders" do
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
- test "with block and no chosen doesn't call block" do
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
- test "with valid helper_class option renders" do
54
- Hirb::Helpers::Table.expects(:render)
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
- test "with invalid helper_class option renders default menu" do
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
- test "with false helper_class option renders default menu" do
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
- test "prints prompt option" do
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
- test "converts non-array inputs to array" do
82
- Hirb::Helpers::AutoTable.expects(:render).with([1], anything)
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
- test "with false ask option returns one choice without asking" do
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
- test "with no items to choose from always return without asking" do
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
- test "with directions option turns off directions" do
97
+ it "with directions option turns off directions" do
98
98
  menu_input('blah')
99
- capture_stdout { menu([1], :directions=>false) }.should_not =~ /range.*all/
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
- Hirb::Menu.any_instance.expects(:invoke).with(cmd, e)
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
- context "2d menu" do
118
- test "with default field from last_table renders" do
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
- test "with default field from fields option renders" do
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
- test "with default field option renders" do
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
- test "with non-table helper class renders" do
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
- test "with no default field prints error" do
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
- test "with invalid field prints error" do
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
- test "with choice from abbreviated field" do
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
- test "with choices from multiple fields renders" do
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
- context "action menu" do
160
- test "invokes" do
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
- test "with 1d invokes" do
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
- test "with non-choice arguments invokes" do
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
- test "with multiple choice arguments flattens them into arg" do
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
- test "with nothing chosen prints error" do
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
- test "with no command given prints error" do
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
- test "with multi_action option invokes" do
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
- test "with command option invokes" do
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
- test "with command option and empty input doesn't invoke action and exists silently" do
201
- Hirb::Menu.any_instance.expects(:invoke).never
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
- test "with action_object option invokes" do
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
- test "with ask false and defaults invokes" do
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
- test "with ask false and no defaults prints error" do
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/
@@ -1,75 +1,73 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class Hirb::Helpers::ObjectTableTest < Test::Unit::TestCase
4
- context "object table" do
5
- def table(*args)
6
- Hirb::Helpers::ObjectTable.render(*args)
7
- end
3
+ describe "object table" do
4
+ def table(*args)
5
+ Helpers::ObjectTable.render(*args)
6
+ end
8
7
 
9
- before(:all) {
10
- @pets = [stub(:name=>'rufus', :age=>7, :to_s=>'rufus'), stub(:name=>'alf', :age=>101, :to_s=>'alf')]
11
- }
12
- test "renders" do
13
- expected_table = <<-TABLE.unindent
14
- +-------+-----+
15
- | name | age |
16
- +-------+-----+
17
- | rufus | 7 |
18
- | alf | 101 |
19
- +-------+-----+
20
- 2 rows in set
21
- TABLE
22
- table(@pets, :fields=>[:name, :age]).should == expected_table
23
- end
24
-
25
- test "with no options defaults to to_s field" do
26
- expected_table = <<-TABLE.unindent
27
- +-------+
28
- | value |
29
- +-------+
30
- | rufus |
31
- | alf |
32
- +-------+
33
- 2 rows in set
34
- TABLE
35
- table(@pets).should == expected_table
36
- end
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
- test "renders simple arrays" do
39
- expected_table = <<-TABLE.unindent
40
- +-------+
41
- | value |
42
- +-------+
43
- | 1 |
44
- | 2 |
45
- | 3 |
46
- | 4 |
47
- +-------+
48
- 4 rows in set
49
- TABLE
50
- table([1,2,3,4]).should == expected_table
51
- end
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
- test "renders simple arrays with custom header" do
54
- expected_table = <<-TABLE.unindent
55
- +-----+
56
- | num |
57
- +-----+
58
- | 1 |
59
- | 2 |
60
- | 3 |
61
- | 4 |
62
- +-----+
63
- 4 rows in set
64
- TABLE
65
- table([1,2,3,4], :headers=>{:to_s=>'num'}).should == expected_table
66
- end
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
- test "with empty fields" do
69
- expected_table = <<-TABLE.unindent
70
- 0 rows in set
71
- TABLE
72
- table(@pets, :fields => []).should == expected_table
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
@@ -1,164 +1,162 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Hirb
4
- class PagerTest < Test::Unit::TestCase
5
- def pager; View.pager; end
6
-
7
- def create_pageable_string(inspect_mode=false, size={})
8
- size = {:width=>pager.width, :height=>pager.height}.merge(size)
9
- seed = inspect_mode ? "a" : "a\n"
10
- if inspect_mode
11
- seed * (size[:width] * size[:height] + 1)
12
- else
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
- test "command_pager sets pager_command when command exists" do
18
- Util.expects(:command_exists?).returns(true)
19
- Pager.expects(:basic_pager)
20
- Pager.command_pager 'blah', :pager_command=>'less'
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
- test "command_pager doesn't set pager_command when command doesn't exist" do
24
- Util.expects(:command_exists?).returns(false)
25
- Pager.expects(:basic_pager).never
26
- Pager.command_pager 'blah', :pager_command=>'moreless'
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
- context "default_pager" do
30
- before(:all) { reset_config; Hirb.enable :pager=>true }
31
- before(:each) { View.pager = nil; Pager.stubs(:pager_command).returns(nil) }
32
- after(:all) { Hirb.disable }
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
- test "pages once in normal mode" do
35
- $stdin.expects(:gets).returns("\n")
36
- output = capture_stdout { pager.page(create_pageable_string, false) }
37
- output.include?('quit').should be(true)
38
- output.include?('finished').should be(true)
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
- test "doesn't page in normal mode" do
42
- $stdin.expects(:gets).never
43
- output = capture_stdout { pager.page("a\n", false) }
44
- output.include?("a\n=== Pager finished. ===\n").should be(true)
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
- test "pages once in inspect mode" do
48
- $stdin.expects(:gets).returns("\n")
49
- output = capture_stdout { pager.page(create_pageable_string(true), true) }
50
- output.include?('quit').should be(true)
51
- output.include?('finished').should be(true)
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
- test "doesn't page in inspect mode" do
55
- $stdin.expects(:gets).never
56
- output = capture_stdout { pager.page("a", true) }
57
- output.include?("a\n=== Pager finished. ===\n").should be(true)
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
- context "pager" do
62
- before(:all) { reset_config; Hirb.enable }
63
- before(:each) { View.pager = nil; View.formatter = nil }
64
- after(:all) { Hirb.disable }
65
-
66
- def irb_eval(string)
67
- context_stub = stub(:last_value=>string)
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
- # this mode is called within @irb.output_value
72
- context "in inspect_mode" do
73
- test "activates when output is wide enough" do
74
- output = create_pageable_string(true)
75
- pager.expects(:page).with(output.inspect, true)
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
- # this mode is called within Hirb::View.render_output
104
- context "in normal mode" do
105
- test "activates when output is long enough" do
106
- output = create_pageable_string
107
- View.formatter.expects(:format_output).returns(output)
108
- pager.expects(:page).with(output, false)
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
- test "activates pager_command with valid pager_command option" do
137
- View.config[:pager_command] = "less"
138
- View.expects(:render_output).returns(false)
139
- Util.expects(:command_exists?).returns(true)
140
- Pager.expects(:command_pager)
141
- irb_eval create_pageable_string(true)
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
- test "activates pager_command with pager_command option that has command options" do
146
- View.config[:pager_command] = "less -r"
147
- View.expects(:render_output).returns(false)
148
- Util.expects(:command_exists?).with('less').returns(true)
149
- Pager.expects(:command_pager)
150
- irb_eval create_pageable_string(true)
151
- View.config[:pager_command] = nil
152
- end
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
- test "doesn't activate pager_command with invalid pager_command option" do
155
- View.config[:pager_command] = "moreless"
156
- View.expects(:render_output).returns(false)
157
- Util.expects(:command_exists?).returns(false)
158
- Pager.expects(:default_pager)
159
- irb_eval create_pageable_string(true)
160
- View.config[:pager_command] = nil
161
- end
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
- end
161
+ after_all { Hirb.disable }
162
+ end