Skip to content

Instantly share code, notes, and snippets.

@takai
Created April 18, 2012 20:56
Show Gist options
  • Save takai/2416492 to your computer and use it in GitHub Desktop.
Save takai/2416492 to your computer and use it in GitHub Desktop.
describe SymbolStack do
context 'when stack is empty' do
its (:size) { should eq 0 }
describe 'SymbolStack#push' do
context 'with symbol' do
it 'increments stack size' do
expect { subject.push(:data) }.
to change { subject.size }.from(0).to(1)
end
end
context 'with non-symbol' do
it { expect { subject.push('data') }.to raise_error }
end
end
describe 'SymbolStack#pop' do
it { expect { subject.pop }.to raise_error }
end
end
context 'when stack is full' do
before do
10.times {|i| subject.push(:"data#{i}") }
end
its (:size) { should eq 10 }
describe 'SymbolStack#push' do
context 'with symbol' do
it { expect { subject.push(:data) }.to raise_error }
end
context 'with non-symbol' do
it { expect { subject.push('data') }.to raise_error }
end
end
describe 'SymbolStack#pop' do
it 'returns top' do
subject.pop.should eq :data9
end
end
end
context 'when stack is not empty or full' do
before do
subject.push(:data)
end
describe 'SymbolStack#push' do
context 'with symbol' do
it 'increments stack size' do
expect { subject.push(:data) }.
to change { subject.size }.from(1).to(2)
end
end
context 'with non-symbol' do
it { expect { subject.push('data') }.to raise_error }
end
end
describe 'SymbolStack#pop' do
it 'returns top' do
subject.pop.should eq :data
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment