Skip to content

Commit

Permalink
Add #context_stack_size
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Apr 24, 2024
1 parent 15e481b commit 069bbf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/diver_down/trace/call_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def empty_context_stack?
@context_stack.empty?
end

# @return [Array<Integer>]
def context_stack_size
@context_stack.keys
end

# @return [Array<Object>]
def context_stack
@context_stack.values
Expand Down
8 changes: 7 additions & 1 deletion spec/diver_down/trace/call_stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end
end

describe '#context_stack/push/pop' do
describe '#context_stack/#context_stack_size/push/pop' do
it 'pushes and pops' do
stack = described_class.new

Expand All @@ -24,19 +24,25 @@
stack.push('C')

expect(stack.context_stack).to eq(['A', 'B', 'C'])
expect(stack.context_stack_size).to eq([2, 4, 6])
stack.pop

expect(stack.context_stack).to eq(['A', 'B'])
expect(stack.context_stack_size).to eq([2, 4])
stack.pop
expect(stack.context_stack).to eq(['A', 'B'])
expect(stack.context_stack_size).to eq([2, 4])
stack.pop

expect(stack.context_stack).to eq(['A'])
expect(stack.context_stack_size).to eq([2])
stack.pop
expect(stack.context_stack).to eq(['A'])
expect(stack.context_stack_size).to eq([2])
stack.pop

expect(stack.context_stack).to eq([])
expect(stack.context_stack_size).to eq([])
end

context 'with _ignored: true' do
Expand Down

0 comments on commit 069bbf1

Please sign in to comment.