require 'pork-rspec/test' RSpec.shared_examples "collections" do |collection_class| it "is empty when first created" do expect(collection_class.new).to be_empty end end RSpec.describe Array do include_examples "collections", Array end RSpec.describe Hash do include_examples "collections", Hash end RSpec.describe C do example do expect(described_class).to equal(C) end end RSpec.describe "Using an array as a stack" do def build_stack [] end before(:example) do @stack = build_stack end it 'is initially empty' do expect(@stack).to be_empty end context "after an item has been pushed" do before(:example) do @stack.push :item end it 'allows the pushed item to be popped' do expect(@stack.pop).to eq(:item) end end end