Skip to content

Commit 70e27f8

Browse files
committed
Passing history manager tests
1 parent 873d350 commit 70e27f8

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/rex/ui/text/shell/history_manager.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def initialize
2828
# @param [Proc] block
2929
# @return [nil]
3030
def with_context(history_file: nil, name: nil, input_library: nil, &block)
31-
input_library ||= :readline # Default to Readline for backwards compatibility.
32-
push_context(history_file: history_file, name: name, input_library: input_library)
31+
# Default to Readline for backwards compatibility.
32+
push_context(history_file: history_file, name: name, input_library: input_library || :readline)
3333

3434
begin
3535
block.call
@@ -69,7 +69,7 @@ def debug?
6969

7070
def push_context(history_file: nil, name: nil, input_library: nil)
7171
$stderr.puts("Push context before\n#{JSON.pretty_generate(_contexts)}") if debug?
72-
new_context = { history_file: history_file, name: name, input_library: input_library }
72+
new_context = { history_file: history_file, name: name, input_library: input_library || :readline }
7373

7474
switch_context(new_context, @contexts.last)
7575
@contexts.push(new_context)

spec/lib/rex/ui/text/shell/history_manager_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(expect do |block|
2626
subject.with_context(name: 'a') do
2727
expected_contexts = [
28-
{ history_file: nil, name: 'a' },
28+
{ history_file: nil, input_library: :readline, name: 'a' },
2929
]
3030
expect(subject._contexts).to eq(expected_contexts)
3131
block.to_proc.call
@@ -36,15 +36,15 @@
3636

3737
context 'when there is an existing stack' do
3838
before(:each) do
39-
subject.send(:push_context, history_file: nil, name: 'a')
39+
subject.send(:push_context, history_file: nil, input_library: :readline, name: 'a')
4040
end
4141

4242
it 'continues to have the previous existing stack' do
4343
subject.with_context {
4444
# noop
4545
}
4646
expected_contexts = [
47-
{ history_file: nil, name: 'a' },
47+
{ history_file: nil, input_library: :readline, name: 'a' },
4848
]
4949
expect(subject._contexts).to eq(expected_contexts)
5050
end
@@ -53,8 +53,8 @@
5353
(expect do |block|
5454
subject.with_context(name: 'b') do
5555
expected_contexts = [
56-
{ history_file: nil, name: 'a' },
57-
{ history_file: nil, name: 'b' },
56+
{ history_file: nil, input_library: :readline, name: 'a' },
57+
{ history_file: nil, input_library: :readline, name: 'b' },
5858
]
5959
expect(subject._contexts).to eq(expected_contexts)
6060
block.to_proc.call
@@ -69,7 +69,7 @@
6969
}
7070
end.to raise_exception ArgumentError, 'Mock error'
7171
expected_contexts = [
72-
{ history_file: nil, name: 'a' },
72+
{ history_file: nil, input_library: :readline, name: 'a' },
7373
]
7474
expect(subject._contexts).to eq(expected_contexts)
7575
end
@@ -79,9 +79,9 @@
7979
describe '#push_context' do
8080
context 'when the stack is empty' do
8181
it 'stores the history contexts' do
82-
subject.send(:push_context, history_file: nil, name: 'a')
82+
subject.send(:push_context, history_file: nil, input_library: :readline, name: 'a')
8383
expected_contexts = [
84-
{ history_file: nil, name: 'a' }
84+
{ history_file: nil, input_library: :readline, name: 'a' }
8585
]
8686
expect(subject._contexts).to eq(expected_contexts)
8787
end
@@ -90,12 +90,12 @@
9090
context 'when multiple values are pushed' do
9191
it 'stores the history contexts' do
9292
subject.send(:push_context, history_file: nil, name: 'a')
93-
subject.send(:push_context, history_file: nil, name: 'b')
94-
subject.send(:push_context, history_file: nil, name: 'c')
93+
subject.send(:push_context, history_file: nil, input_library: :readline, name: 'b')
94+
subject.send(:push_context, history_file: nil, input_library: :reline, name: 'c')
9595
expected_contexts = [
96-
{ history_file: nil, name: 'a' },
97-
{ history_file: nil, name: 'b' },
98-
{ history_file: nil, name: 'c' },
96+
{ history_file: nil, input_library: :readline, name: 'a' },
97+
{ history_file: nil, input_library: :readline, name: 'b' },
98+
{ history_file: nil, input_library: :reline, name: 'c' },
9999
]
100100
expect(subject._contexts).to eq(expected_contexts)
101101
end
@@ -113,12 +113,12 @@
113113
end
114114

115115
context 'when the stack is not empty' do
116-
it 'continues to have an empty stack' do
116+
it 'continues to have a non-empty stack' do
117117
subject.send(:push_context, history_file: nil, name: 'a')
118118
subject.send(:push_context, history_file: nil, name: 'b')
119119
subject.send(:pop_context)
120120
expected_contexts = [
121-
{ history_file: nil, name: 'a' },
121+
{ history_file: nil, input_library: :readline, name: 'a' },
122122
]
123123
expect(subject._contexts).to eq(expected_contexts)
124124
end

0 commit comments

Comments
 (0)