Challenge 2: before(:each) for Shared Setup — Solution # stack.rb class Stack def initialize @items = [] end def push(item) @items.push(item) end def pop @items.pop end def empty? @items.empty? end end # spec/stack_spec.rb require_relative "../stack" describe Stack do before(:each) do @stack = Stack.new end it "starts empty" do expect(@stack.empty?).to be true end it "is no longer empty after a push" do @stack.push("item") expect(@stack.empty?).to be false end it "returns the most recently pushed item on pop" do @stack.push("first") @stack.push("second") expect(@stack.pop).to eq("second") end end =begin Expected RSpec output: Stack starts empty is no longer empty after a push returns the most recently pushed item on pop 3 examples, 0 failures Notes: - before(:each) runs before every single it block, assigning a brand new Stack.new to @stack each time — none of the three examples share state with each other, so a push in one example can never accidentally affect the "starts empty" example. - Without before(:each), each it block would need to repeat @stack = Stack.new itself, or worse, accidentally share one @stack across all three examples if it were set up outside any hook. - The three examples each test one distinct behavior (initial state, state after push, pop ordering), keeping each it block focused on a single assertion. =end